Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7536177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:30:19+00:00 2026-05-30T06:30:19+00:00

I have a Winforms application, which hosts two PDF Viewers (Unmanaged C++) in its

  • 0

I have a Winforms application, which hosts two PDF Viewers (Unmanaged C++) in its panels.

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.

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)

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.

Are there other solutions for application-wide hotkeys, that would work even if the focus is on the hosted application?

SOLUTION:

In the main Form, I handle Activated and Deactivate events like this :

public void PDFPicker_Activated(object sender, EventArgs e)
    {
        var foregroundHwnd = GUI.winapiwrap.GetForegroundWindow();
        if (foregroundHwnd==this.Handle ||   this.OwnedForms.Any(form => 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 => form.Handle == foregroundHwnd))
        {

        }
        else
        {
          unregisterHotkeys();
          this.Text = "Hotkeys off";
        }
    }

Then in the dialog, which is in the OwnedForms array, i call just this:

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);
    }

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.

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:30:21+00:00Added an answer on May 30, 2026 at 6:30 am

    So then check on Form Activate/Deactivate events whether the form is a foreground window or not (::GetForegroundWindow()) and then disable/enable hotkeys appropriately.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WinForms application which has two panels which individually contain a usercontrol
I have a WinForms application in which I want to be able to provide
I have a C# .net winforms application with two forms which connects to sql
I have a winforms (C#) application in which will have some settings I want
We have a WinForms application which runs on a touch-screen on a bit of
I have a winforms application in which I am using 2 Forms to display
Ok, I have developed this WinForms client, which interacts with a server (ASPX Application)
I have a WinForms application in which I have hosted a web page inside
I have a WinForms gui application which has a number of areas to it
I am new to Microsoft Dynamic CRM. I have a .NET Winforms application which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.