How Can I obtain the handle of a dialog diplayed by an External DLL ?
Thanks
Joseph
Window handle of an External DLL dialog
Re: Window handle of an External DLL dialog
does external Dialog Title (Caption) appear in Taskmanager ?unixkd wrote:How Can I obtain the handle of a dialog diplayed by an External DLL ?
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
Code: Select all
nHwnd := VAL( LEFT( aTasklist[ i ], 8 ) )
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
Jimmy
Re: Window handle of an External DLL dialog
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.
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.
Re: Window handle of an External DLL dialog
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
Jimmy