Date: 02-16-2022
Return to Index
created by gbSnippets
HWND h = ::GetTopWindow(0 );
While ( h )
{
DWord pid;
DWord dwTheardId = ::GetWindowThreadProcessId( h,&pid);
If ( pid == /*your Process ID*/ )
{
// here h is the Handle to the Window
break;
}
h = ::GetNextWindow( h , GW_HWNDNEXT);
}
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg, hWnd, TargethWnd, tempPID, PID as DWord
Global iResult As Long
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Open", 50,10,100,20
Control Add Button, hDlg, 200,"Move", 50,50,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
'open external app
PID = Shell ("notepad.Exe")
'cycle through open windows, looking for matching PID
hWnd = GetTopWindow(0)
While hWnd
GetWindowThreadProcessId(hWnd, tempPID) 'get PID of each window
If tempPID = PID Then
'match found. the current hWnd is that of the Shell'd app
If IsWindowVisible(hWnd) Then
TargethWnd = hWnd
Exit Loop
End If
End If
hWnd = GetNextWindow(hWnd, %GW_HWNDNEXT)
Wend
End If
If CB.Msg = %WM_Command AND CB.Ctl = 200 AND CB.Ctlmsg = %BN_Clicked Then
iResult = MoveWindow( TargethWnd, 0,0,100,100,ByVal 1)
End If
End Function
'gbs_00617
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm