Question Process MainWindowHandle

ahmdod5

Member
Joined
Jan 20, 2011
Messages
14
Programming Experience
5-10
i have a simple GUI form to hide / show / minimize / terminate / force terminate Processes
i can do all well but for show and hide i need the MainWindowHandle to show or hide it
so here is hide process code
VB.NET:
Dim Proc As New Process = Process.GetProcessesById(List.SelectedRows(0).Cells(1))
Dim hwnd = Proc.MainWindowHandle
ShowWindow(hwnd,0)

if i try the same with show code

VB.NET:
Dim Proc As New Process = Process.GetProcessesById(List.SelectedRows(0).Cells(1))
Dim hwnd = Proc.MainWindowHandle
ShowWindow(hwnd,9)

the MainWindowHandle become 0 cuz its hidden is there is any other way to get the MainWindowHandle of Process ?
 
Use same handle for both operations.
 
yes but if my process list refreshed
process handle will equal 0
and also

if some1 hided window
then close the program
the opened it the process handle will be also 0
 
Your code have to remember the handle first used, and use the same one later.
 
Back
Top