Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get the main window handle by PID
#2
C#:
print.it((wnd)Process.GetProcessById(10876).MainWindowHandle);

Notes:
- In Windows API there is no property "main window of a process".
- .NET and PowerShell simply gets the first-in-Z-order visible unowned window of that process. A process may have any number of such windows. `MainWindowHandle` can return a random temporary window such as a tooltip.

This QM function works exactly like the .NET `MainWindowHandle`. And probably like that of PowerShell.

Function Process_MainWindowHandle
Code:
Copy      Help
;/
function# processId

int r
EnumWindows &sub.EnumProc 0
ret r


#sub EnumProc v
function# w _

if IsWindowVisible(w)
,GetWindowThreadProcessId(w &_i)
,if _i=processId
,,if GetWindow(w GW_OWNER) = 0
,,,r = w
,,,ret 0
ret 1


Messages In This Thread
Get the main window handle by PID - by Davider - 03-02-2026, 10:35 AM
RE: Get the main window handle by PID - by Gintaras - 03-02-2026, 12:08 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)