Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
#Include "Win32API.inc"
Global hDlg as Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local hInstance,hWin AS Dword
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
hInstance = Shell("calc.exe")
hWin = GetWinHandle(hInstance)
? Str$(hWin)
End If
End Function
Function GetWinHandle(hInstance As Long) As Long
Local hWin As Dword
hWin = FindWindow(%Null, %Null)
Do Until hWin = 0
If GetParent(hWin) = 0 Then
If hInstance = ProcIDFromWnd(hWin) Then
Function = hWin : Exit Do
End If
End IF
hWin = GetWindow(hWin, %GW_hWndNext
Loop
End Function
Function ProcIDFromWnd(ByVal hwnd As Long) As Long
Dim idProc As Long
GetWindowThreadProcessId hwnd, idProc ' Get PID for this HWnd
Functioni = idProc
End Function
'gbs_01371
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm