Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 3
    There is no "Main window" concept, the author of that object just assumed that the first would be it. Further more, MSDN says "Brings the thread that created the specified window into the foreground"
    – Deanna
    Commented Feb 1, 2012 at 19:10
  • Good info. Apparently I fell into the trap. Anyway, FindWindow, given that you know the title of the window you want, gives the right answer.
    – KeithS
    Commented Feb 1, 2012 at 22:35
  • +1 @KeithS what find window method are you using here. I take it that you are talking about an Interop method?
    – MoonKnight
    Commented Nov 29, 2012 at 17:34
  • Yes, a P/Invoke call to FindWindow in the same WinAPI dll as ShowWindow.
    – KeithS
    Commented Nov 29, 2012 at 17:52
  • 1
    +1 - FindWindow was the answer in my case too. MainWindowHandle worked fine, until I would hide the window on minimize & made a TrayIcon visible instead. In this case, MainWindowHandle returned the handle of the TrayIcon... Gotta love that beautiful win32 API, huh? :D
    – nevelis
    Commented Jan 25, 2014 at 19:04