RegisterHotKey does not work with invisible forms (C #)

I am trying to put an icon in the system tray and then give it a global key combination to execute a function.

I use RegisterHotKey to set a global keyboard shortcut, and works if the main form associated with this icon is visible. But if the form is invisible, then the WndProc method is never called.

Any ideas?

Edit: What I mean by β€œhidden” is that the following is added to the main form:

protected override void OnLoad(EventArgs e)
{
    hotKey = new GlobalHotkey(GlobalHotkey.WIN, Keys.T, this);
    bool registered = hotKey.Register();
    Visible = false;
    ShowInTaskbar = false;
    base.OnLoad(e);
}

"registered" is displayed as "true", and the shortcut key works fine unless I specify "Visible = false"; and "ShowInTaskbar = false;".

+5
source share
2 answers

Winforms winapi. . , , CreateWindowEx().

, CreateWindowEx(). , , . , . , , . , , TreeView. , . , . ShowInTaskbar . RightToLeft, FormBorderStyle, ControlBox ..

, . Handle, . , RegisterHotKey() , , winapi . , Winforms , .

, . OnHandleCreated. , . , , , , ShowInTaskbar.

+4

, ShowInTaskbar false , , hwnd, RegisterHotkey, .

ShowInTaskBar .

+4

All Articles