hey, i got difficulty hiding and showing lots of instances of console app made in c++, im able to hide them but once hidden i cant show them here is code
when i try hide the programs i am able to get a process.mainwindowhandle, but once hidden mainwindowhandle becomes 0. there a way to get hwnd from pid maybe ?
im using showwindow api call from user32.dll
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
Process[] lines;
Process a;
lines = Process.GetProcesses();
foreach (Process p in lines)
{
if (p.ProcessName.ToLower() == "prog")
{
ShowWindow(p.MainWindowHandle, 5);
MessageBox.Show(p.MainWindowHandle.ToString());
}
}
Hiding and showing process
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

AlanRank #669 · 3.6K reputationPosted Sep 20, 2007, 7:57 AM EDT
Couldn't you get the window handle before you hide it and then store it in an IntPtr field so that you can reshow the window with it later?
You wouldn't then have to call Process.MainWindowHandle again at that point.
Daniel van Pletzen25 reputationPosted Sep 20, 2007, 8:31 AM EDT