help with keyboard accelerators

This is a discussion on help with keyboard accelerators within the Windows Programming forums, part of the Platform Specific Boards category; I am trying to get keyboard accelerators to work but the messages are not aligned to the menu messages. can ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    3

    help with keyboard accelerators

    I am trying to get keyboard accelerators to work but the messages are not aligned to the menu messages. can anyone
    tell me what I'm doing wrong?? Here is my code:

    main.cpp
    Code:
    #include <windows.h>
    #include <stdlib.h>
    #include "acctest.h"
    
    char szClassName[ ] = "acctest";
    
    LRESULT CALLBACK
    WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
        switch (message)  {
            case WM_DESTROY: PostQuitMessage (0);  
                break;
            case WM_COMMAND:         
                switch (wParam)
                   case COM_FILEEXIT:  system("pause");
                break;
            default: return DefWindowProc (hwnd, message, wParam, lParam);
        }
        return 0;
    }
    
    int WINAPI WinMain (HINSTANCE hThisInstance,HINSTANCE hPrevInstance, LPSTR lpszArgument, int n){
        HWND hwnd;
        HMENU menu;
        HACCEL hAccTable;   
        MSG messages;          
        WNDCLASSEX wincl; 
    
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;   
        wincl.style = CS_DBLCLKS; 
        wincl.cbSize = sizeof (WNDCLASSEX);
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL; 
        wincl.cbClsExtra = 0; 
        wincl.cbWndExtra = 0;  
        wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    
        if (!RegisterClassEx (&wincl))
            return 0;
    
        hwnd = CreateWindowEx (0, szClassName, "acctest", WS_OVERLAPPEDWINDOW, 
               300,300,300,300,HWND_DESKTOP, NULL,hThisInstance, NULL );
        ShowWindow (hwnd, n);
    
    	menu = LoadMenu(hThisInstance, MAKEINTRESOURCE(COM_MENU));
        SetMenu(hwnd, menu);    
    	hAccTable = LoadAccelerators(hThisInstance, MAKEINTRESOURCE(COM_KEY)); 
        
        while (GetMessage (&messages, NULL, 0, 0)){
           if (TranslateAccelerator(hwnd, hAccTable, &messages) == 0) {
               TranslateMessage(&messages); 
               DispatchMessage(&messages);  	} }
        return messages.wParam;
    }
    acctest.h
    Code:
    #define COM_KEY                500
    #define COM_MENU             501
    #define COM_FILEEXIT        502
    RC.rc
    Code:
    #include <windows.h>
    #include "acctest.h"
    
    COM_MENU MENU
    BEGIN
        POPUP "File"
        BEGIN
            MENUITEM "&Exit\tctrl+e", COM_FILEEXIT
        END
    END
    
    COM_KEY ACCELERATORS DISCARDABLE
    BEGIN
        "E",   COM_FILEEXIT,       VIRTKEY, CONTROL
    END

  2. #2
    Registered User
    Join Date
    Jul 2004
    Posts
    3
    i think i needed to use switch(LOWORD(wParam)) {... etc. rather than just (wParam)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting keyboard and mouse in linux
    By sameer.nalwade in forum C Programming
    Replies: 3
    Last Post: 11-22-2008, 04:24 AM
  2. Keyboard port using other that a keyboard
    By antoinelac in forum C++ Programming
    Replies: 4
    Last Post: 06-12-2008, 03:46 PM
  3. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  4. Game Design Topic #2 - Keyboard or Mouse?
    By TechWins in forum Game Programming
    Replies: 4
    Last Post: 10-08-2002, 04:34 PM
  5. Using Keyboard accelerators.......
    By Clyde in forum Windows Programming
    Replies: 4
    Last Post: 05-26-2002, 07:33 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21