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

  • SEARCH
  • Home
  • 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 525185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:38:43+00:00 2026-05-13T08:38:43+00:00

I have created a Windows GUI program using C and the Windows API, and

  • 0

I have created a Windows GUI program using C and the Windows API, and I want the program to utilise keyboard accelerators. I have set up some accelerators, which are working correctly, but when focus goes to a child Window of my program’s main window, such as a list view control or a status bar control, it appears that the keyboard accelerators are being translated to WM_COMMAND messages for the child windows rather than the main window. Because of this, my handling of the appropriate WM_COMMAND messages in the main window’s WndProc is ignored when the focus is on a child control.

How should I resolve this problem?

  • 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-13T08:38:43+00:00Added an answer on May 13, 2026 at 8:38 am

    I found the answer. The child windows of the main window must be subclassed so that the WM_COMMAND messages generated by the keyboard accelerators can be intercepted and passed to the parent window.

    This involves changing the window procedure of the control to a different one. The alternate procedure handles the messages that should be intercepted by sending them to the parent window. A pointer to the original window procedure must also be stored somewhere so that the control can function correctly.

    The window procedure can be altered using SetWindowLongPtr with GWLP_WNDPROC.

    Here is a simple example of how to do this by storing a pointer to the original window procedure in the control’s user data value (GWLP_USERDATA):

    The code to change the window procedure and store the original procedure in GWLP_USERDATA:

    SetWindowLongPtr( hWnd, GWLP_USERDATA, ( LONG_PTR )SetWindowLongPtr( hWnd, GWLP_WNDPROC, ( LONG_PTR )WndProc ) );
    

    The intercepting window procedure:

    static LRESULT CALLBACK WndProc( const HWND hWnd, const UINT message, const WPARAM wParam, const LPARAM lParam )
    {
        switch( message )
        {
            case WM_COMMAND:
                SendMessage( GetParent( hWnd ), message, wParam, lParam );
                return 0;
            default:
            //Assume that GWLP_USERDATA has been set to the original window procedure.
                return CallWindowProc( ( WNDPROC )GetWindowLongPtr( hWnd, GWLP_USERDATA ), hWnd, message, wParam, lParam );
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Windows program that has a GUI which also uses a command
I have created a c/c++ program which uses opencv library. I want to convert
I have created a GUI program using python and wxpython. It is now ready
I have created a windows mobile application in Visual Studio. I want to templatize
I have created a Windows CE6 Image through Platform Builder, and I now want
hello i have created one windows application in c# .net and its working fine
I'm looking into creating a GUI program for Windows in C++, I have a
I have recently started a tutorial to learn how to code GUI using Windows
I have a GUI window that I've created using Netbeans. I then ported the
I have created a program in c++ that doesn't have any GUI. When this

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.