Window handle of an External DLL dialog

This forum is for eXpress++ general support.
Post Reply
Message
Author
User avatar
unixkd
Posts: 579
Joined: Thu Feb 11, 2010 1:39 pm

Window handle of an External DLL dialog

#1 Post by unixkd »

How Can I obtain the handle of a dialog diplayed by an External DLL ?

Thanks

Joseph

User avatar
Auge_Ohr
Posts: 1428
Joined: Wed Feb 24, 2010 3:44 pm

Re: Window handle of an External DLL dialog

#2 Post by Auge_Ohr »

unixkd wrote:How Can I obtain the handle of a dialog diplayed by an External DLL ?
does external Dialog Title (Caption) appear in Taskmanager ?
if yes you can "scan" Tasklist to get handle of "that" Window.

Code: Select all

FUNCTION gettasklist( hWnd )
***************************
LOCAL aList       := {}
LOCAL cWindowName
LOCAL nVisible
   DO WHILE hWnd != 0
      cWindowname := SPACE( 100 )
      IF ( getwindowtexta( hWnd, @cWindowName, LEN( cWindowName ) ) <> 0 )
         nVisible := IsWindowVisible( hWnd )
         IF nVisible == 1
            AADD( aList, STR( hWnd, 8 ) + cWindowname )
         ENDIF
      ENDIF
      hWnd = GetWindow( hWnd, GW_HWNDNEXT )
   ENDDO
RETURN aList

******************************************************************************

FUNCTION GetWindow( hWnd, uCmd )
LOCAL nDll := DllLoad( "USER32.DLL" )
LOCAL xRet := DllCall( nDll, DLL_STDCALL, "GetWindow", hWnd, uCmd )
   DllUnLoad( nDll )
RETURN xRet

FUNCTION GetWindowTextA( hWnd, lPstring, nMax )
LOCAL nDll := DllLoad( "USER32.DLL" )
LOCAL xRet := DllCall( nDll, DLL_STDCALL, "GetWindowTextA", hWnd, @lPstring, nMax )
   DllUnLoad( nDll )
RETURN xRet

FUNCTION IsWindowVisible( hWnd )
LOCAL nDll := DllLoad( "USER32.DLL" )
LOCAL xRet := DllCall( nDll, DLL_STDCALL, "IsWindowVisible", hWnd )
   DllUnLoad( nDll )
RETURN xRet
you will get a Array with Number and Names where

Code: Select all

nHwnd := VAL( LEFT( aTasklist[ i ], 8 ) )
is your Handle.

you also can use this Handle for

Code: Select all

DLLFUNCTION ShowWindow( nHwnd, nCmdShow ) USING STDCALL FROM USER32.DLL
DLLFUNCTION BringWindowToTop( nHwnd )     USING STDCALL FROM USER32.DLL
DLLFUNCTION SetForegroundWindow( nHwnd )  USING STDCALL FROM USER32.DLL
greetings by OHR
Jimmy

User avatar
unixkd
Posts: 579
Joined: Thu Feb 11, 2010 1:39 pm

Re: Window handle of an External DLL dialog

#3 Post by unixkd »

In your code:
Function gettasklist( hWnd )

Which Dialog is hWnd that you passed to this function ?

You also tall of aTaskList, I want to guess it is the return value of the above function

J.O.

User avatar
Auge_Ohr
Posts: 1428
Joined: Wed Feb 24, 2010 3:44 pm

Re: Window handle of an External DLL dialog

#4 Post by Auge_Ohr »

unixkd wrote:In your code:
Function gettasklist( hWnd )

Which Dialog is hWnd that you passed to this function ?
You also tall of aTaskList, I want to guess it is the return value of the above function

Code: Select all

FUNCTION ForceApp2Front( cAppName )
LOCAL oDlg
LOCAL aTasklist
LOCAL aSize     := { 0, 0 }
LOCAL aPos      := { 0, 0 }
LOCAL i
LOCAL nHwnd, cWind

IF PCOUNT() > 0

   oDlg := XbpDialog() :new( AppDesktop(),, aPos, aSize,, .F. )
   oDlg:create()
   SETAPPFOCUS( oDlg )

   aTasklist := GetTaskList( oDlg:gethWnd( ) )

   FOR i = 1 TO LEN( aTasklist )
      cWind := TRIM( UPPER( SUBSTR( aTasklist[ i ], 9 ) ) )
      cWind := SUBSTR( cWind, 1, LEN( cWind ) - 1 )

      IF cWind == TRIM( UPPER( cAppName ) )
         nHwnd := VAL( LEFT( aTasklist[ i ], 8 ) )   // this is the Handle

         ShowWindow( nHwnd, SW_RESTORE )
         BringWindowToTop( nHwnd )
         SetForegroundWindow( nHwnd )
         EXIT
      ENDIF
   NEXT
   oDlg:destroy()
ENDIF
RETURN
greetings by OHR
Jimmy

Post Reply