6

Those darned users and their minimized windows.

In C#, if I have a window's HWND, is there a way to tell if it is visible on the desktop?

directedition
  • 11,145
  • 18
  • 58
  • 79

3 Answers3

5

The GetWindowPlacement function returns a WINDOWPLACEMENT structure which has a field showCmd:

Specifies the current show state of the window.

The details of this read as though you would be setting the window state, but I suspect that this is because they've been copied from somewhere else and not updated.

ChrisF
  • 134,786
  • 31
  • 255
  • 325
  • Phew thanks, spent at least 10 minutes of boring googling to find out how the heck one is supposed to check window visibility via WinAPI... The name is a little obscure and of course the documentation for how to hide a window doesn't link to it... – Roman Starkov Aug 01 '10 at 00:30
3

There's the Visible property, but that checks the visible flag, it doesn't tell you whether the window is being covered by another window, or off the screen, etc.. That's a lot more tricky. Raymond Chen has some tips, though:

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Tim Sylvester
  • 22,897
  • 2
  • 80
  • 94
1
bool isHwndVisible = Control.FromHandle(handle).Visible
Lee
  • 142,018
  • 20
  • 234
  • 287
  • 1
    That only works for (Managed) Controls in the current Application. I think the OP is referring to another application. – H H Nov 15 '09 at 21:43