I create a global hot key to show a window by PInvoking RegisterHotKey(). But to do this I need that window’s HWND, which doesn’t exist until the window is loaded, that means shown for the first time. But I don’t want to show the window before I can set the hot key. Is there a way to create a HWND for that window that is invisible to the user?
I create a global hot key to show a window by PInvoking RegisterHotKey() .
Share
If you are targeting .NET 4.0 you can make use of the new
EnsureHandlemethod available on theWindowInteropHelper:(thanks to Thomas Levesque for pointing this out.)
If you are targeting an older version of the .NET Framework, the easiest way is to show the window to get to the HWND while setting a few properties to make sure that the window is invisible and doesn’t steal focus:
Once you want to show the actual window you can then set the Content, the size and change the style back to a normal window.