Thread: accelerator keys

  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401

    accelerator keys

    i created an accelerator with an ID of ACCEL_QUIT. In the window procedure, in WM_COMMAND, i try to capture ACCEL_QUIT using LOWORD(wParam). ACCEL_QUIT is defined at the top of the source file. nothing happens though, i cannot seem to capture the message anywhere. how do i do this?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    Jim(U)
    Guest
    Usually you have to have a modified Message Loop.

    Like this:

    !TranslateAccelerator
    --- !GetMessage
    ------ TranslateMessage

    Make sure that TranslateAccelerator gets called before GetMessage.... then you will intercept the Accelerator.

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    i still cant get it to work. here is my setup:

    Code:
    HACCEL table;
    
    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);
    	
    table=LoadAccelerators(hInstance,
               MAKEINTRESOURCE(IDR_ACCELERATOR1));
    
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
        {
    	TranslateAccelerator(hwnd,table,&Msg);
    	TranslateMessage(&Msg);
                    DispatchMessage(&Msg);
        }
    i then do the following:

    Code:
    case WM_COMMAND:
        switch (LOWORD(wParam))
        {
            case ACCEL_QUIT: //this is the ID
                  //do stuff here
    nothing happens. since the whole window is covered by an edit box, which always has focus, i modified it, gave focus to the window, but still nothing. is the order of my operations wrong?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    try

    Code:
    while(GetMessage(&msg, NULL , 0, 0))	
    {
         if(!TranslateAccelerator( msg.hwnd, hAccel, &msg))
        {
              TranslateMessage(&msg) ;
    	  DispatchMessage(&msg) ;
        }
    }
    if still having problems post the actual record from the acc table as well.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    no that still wont work
    i dont see why would want the accelerator table, but here go

    Code:
    IDR_ACCELERATOR1 ACCELERATORS DISCARDABLE 
    BEGIN
        "Z",            ACCEL_QUIT,             VIRTKEY, CONTROL, ALT, NOINVERT
    END
    by the way, that was created by the resource editor in MSVC++ 98.
    perhaps i am not loading the accelerator table properly?

    Code:
    table=LoadAccelerators(hInstance,
               MAKEINTRESOURCE(IDR_ACCELERATOR1));
    that code is just before the message loop.

    this is really annoying, and i cant find anything on the internet about how to do it, except with class based code, which i dont like to use. anyone have any ideas for me?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    So you are pressing 'z' + 'ctrl' + 'alt' ?

    What int have you defined ACCEL_QUIT as?


    ie
    #define ACCEL_QUIT 40001



    What happens in the callback under the case ACCEL_QUIT: any msg's incomming?


    try
    GetLastError() if table = NULL
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    yeah, there was an error loading the table. i specified the parameter for the accelerator table incorrectly. what i was supposed to do was specify 0 as the high order word, and a MAKEINTRESOURCE(tableID) as the low order word. the problem now is, how do i specify that? i know how to refer to the low and high words, like this:

    Code:
    LOWORD()
    HIWORD()
    But i dont know how to assign to these words. could someone help?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  8. #8
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    actually, i found out how to make the word. i found the MAKELONG() function. i assume this is the right function, because it returns a 4 byte value, and the parameter requires a 4 byte pointer to a char. here is the help text:

    LPCTSTR lpTableName:
    Points to a null-terminated string that names the accelerator table to load. Alternatively, this parameter can specify the resource identifier of an accelerator-table resource in the low-order word and zero in the high-order word. The MAKEINTRESOURCE macro can be used to create this value.

    And this is the code:

    Code:
    table=LoadAccelerators(hInstance,
    (LPCTSTR)MAKELONG(MAKEINTRESOURCE
    (IDR_ACCELERATOR1),0) )
    i type casted the second parameter to a pointer because the compiler told me to. is this all correct?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

Popular pages Recent additions subscribe to a feed