Hiding an Always on top Window

  • Thread starter Thread starter No One
  • Start date Start date
N

No One

I have one application in C# that stays on top. Now I have another one
that needs to make the former hide for a certain amount of time and then
come back up to on top. I had thought of adding a method to the former
to handle being sent a message to change, but I'd rather not change the
first application if I can. Is there a way to accomplish this without
changing the first?
 
Try this

[DllImport("user32.dll")]
private static extern int FindWindow(string className, string windowName);

[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(int hWnd, int nCmdShow);

private const int SW_HIDE = 0;
private const int SW_SHOWNORMAL = 1;
private const int SW_SHOWMINIMIZED = 2;
private const int SW_SHOWMAXIMIZED = 3;
private const int SW_RESTORE = 9;

//get the window handle which is displayed on top
int hWnd = FindWindow(null,"Top most window title");

//hide the window using the handle
bool test = ShowWindowAsync(hWnd, SW_HIDE);

//to restore the window back
bool test = ShowWindowAsync(hWnd, SW_RESTORE );
 
This kinda works. One form hides well, but the modal dialog box it has open
does not. The dialog box thinks a hide or minimize means to close and so it
does. I've no idea why it thinks it is getting a close message. Any ideas?

Shakir said:
Try this

[DllImport("user32.dll")]
private static extern int FindWindow(string className, string windowName);

[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(int hWnd, int nCmdShow);

private const int SW_HIDE = 0;
private const int SW_SHOWNORMAL = 1;
private const int SW_SHOWMINIMIZED = 2;
private const int SW_SHOWMAXIMIZED = 3;
private const int SW_RESTORE = 9;

//get the window handle which is displayed on top
int hWnd = FindWindow(null,"Top most window title");

//hide the window using the handle
bool test = ShowWindowAsync(hWnd, SW_HIDE);

//to restore the window back
bool test = ShowWindowAsync(hWnd, SW_RESTORE );

--
Shak
(Houston)

No One said:
I have one application in C# that stays on top. Now I have another one
that needs to make the former hide for a certain amount of time and then
come back up to on top. I had thought of adding a method to the former
to handle being sent a message to change, but I'd rather not change the
first application if I can. Is there a way to accomplish this without
changing the first?
 
Back
Top