Code: Select all
Procedure EnumWindowsProc(hWnd,lParam)
GetWindowThreadProcessId_(hWnd,@lpProc)
If lpProc=PeekL(lParam) ; process passed to EnumWindows is process found at this hwnd
PokeL(lParam,hWnd) ; set ptr to hwnd
ProcedureReturn 0
EndIf
ProcedureReturn 1
EndProcedure
Procedure GetProcHwnd(lpProc)
ptr=lpProc
Repeat : Until EnumWindows_(@EnumWindowsProc(),@ptr)
If ptr=lpProc ; if no handle is returned no matching process was found
ProcedureReturn 0
EndIf
; some form of GetWindow_() here for top-level window..
ProcedureReturn ptr
EndProcedure
program=RunProgram("Notepad.exe","","",#PB_Program_Open)
id=ProgramID(program)
hproc=OpenProcess_(#PROCESS_ALL_ACCESS,0,id)
Debug hproc
If Not GetProcHwnd(hproc)
Debug "GetProcHwnd failed."
Else
Debug "Success!"
EndIf