Note that there are some explanatory texts on larger screens.

plurals
  1. POWinforms: Keyboard shortcuts for Winforms app hosting other applications in its panels
    primarykey
    data
    text
    <p>I have a Winforms application, which hosts two PDF Viewers (Unmanaged C++) in its panels.</p> <p>I want to have application wide hotkeys for project handling (Open,Save,Close,...) which would work even when users focus is on the hosted PDF Viewer.</p> <p>I managed to achieve that via Winapi and RegisterHotKey, but client doesnt like that those are system wide (e.g. they disable the same MS Word hotkeys)</p> <p>I did try to disable and enable global hotkeys on Form's Activate/Deactivate events, however those events appear even when i dont leave my own app, for example on top-menu entry or on a dialog-box.</p> <p>Are there other solutions for application-wide hotkeys, that would work even if the focus is on the hosted application?</p> <p><strong>SOLUTION:</strong></p> <p>In the main Form, I handle Activated and Deactivate events like this :</p> <pre><code>public void PDFPicker_Activated(object sender, EventArgs e) { var foregroundHwnd = GUI.winapiwrap.GetForegroundWindow(); if (foregroundHwnd==this.Handle || this.OwnedForms.Any(form =&gt; form.Handle==foregroundHwnd)) { if (!this.hotkeys.Any()) { registerHotkeys(); this.Text = "Hotkeys just registered"; } } } public void PDFPicker_Deactivate(object sender, EventArgs e) { var foregroundHwnd = GUI.winapiwrap.GetForegroundWindow(); if (foregroundHwnd == this.Handle || this.OwnedForms.Any(form =&gt; form.Handle == foregroundHwnd)) { } else { unregisterHotkeys(); this.Text = "Hotkeys off"; } } </code></pre> <p>Then in the dialog, which is in the OwnedForms array, i call just this:</p> <pre><code>private void QuestionPostingPanel_Activated(object sender, EventArgs e) { parent.PDFPicker_Activated(sender, e); } private void QuestionPostingPanel_Deactivate(object sender, EventArgs e) { parent.PDFPicker_Deactivate(sender, e); } </code></pre> <p>In case of more such dialogs, I would inherit AbstractDialog : Form, add those 2 event functions and a reference to parent, and then inherit all of them from this AbstractDialog.</p> <p>While registering/unregistering GlobalHotkeys, it was a problem for me when I tried doing that in parallel - global hot keys were bound to a thread.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload