Thread: help with keyboard accelerators

  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, 02: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, 03:34 PM
  5. Using Keyboard accelerators.......
    By Clyde in forum Windows Programming
    Replies: 4
    Last Post: 05-26-2002, 06:33 PM