1
votes

I am using the ShowWindow function in Windows to show and hide specific windows which are not created by my own application. The use of this function is simple, as you basically only have to pass the window HWND and whether to show or hide it. However, some applications make it show up again.

For example, I can hide a Google Chrome window. However, when opening a website within Windows, Chrome pops up (it is my default internet browser) which means the hidden Chrome window is made shown again. I'd like to prevent this as any hidden windows should stay hidden at all times.

Would it be advisable to continiously pass the hide command (say 10 times a second or so) so that possibly shown windows are immediately made hidden again, or is there a function to lock these windows as being hidden?

Thanks.

1
Why don't you just switch you computer off, I guarantee that no Windows can show with the machine in that state. - David Heffernan
Well, I am creating a application with which you can hide and show certain windows, e.g. for privacy reasons. Shutting off the computer closes the applications (as well as the complete operating system) so that isn't really of any use. - pimvdb
lol jerk comment @DavidHeffernan but i understand it was a joke :P @ pimvdb: awesome finding and describing of quirk and question about solution for it pimvdb. Helped me out but I don't see this reappearing behavior in Win8.1, does this reappearing only occur up till Win7 or something? - Noitidart

1 Answers

3
votes

If there is a specific window you want to control, trying to issue hide commands over and over isn't going to cut it.

The best option would be to locate the target window (FindWindow), inject a hook dll into the process (SetWindowHookEx) to hook the window proc: then in the hooked window proc, watch for and handle the WM_WINDOWPOSCHANGING message to apply your own window position and visibility policies.

As most codepaths that change the visible state of a window happen eventually via a call to SetWindowPos, and SetWindowPos always verifies its parameters via that message.