creating accelerators on the fly

This is a discussion on creating accelerators on the fly within the Windows Programming forums, part of the Platform Specific Boards category; first of all, dont tell me to use a resource editor, i like run time stuff okay? second, here's the ...

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

    creating accelerators on the fly

    first of all, dont tell me to use a resource editor, i like run time stuff okay?
    second, here's the problem: i cant get accelerators to work when i add them at run time.

    what i do is allocate memory for however many ACCEL structures i require. ie,

    Code:
    LocalAlloc(LPTR,num_accels*sizeof(ACCEL));
    then i use LocalLock to obtain a pointer, put some data in:

    Code:
    AccelPointer[0].cmd=ID_ACCEL_QUIT;
    AccelPointer[0].fVirt=FALT|FCONTROL;
    AccelPointer[0].key=122;
    and then create the table.

    Code:
    accTable=CreateAcceleratorTable(AccelPointer,
                                                          num_accels);
    All throughout, i have been checking each function for error return values, but everything seems to be running perfectly.

    then i add this to the message loop:

    Code:
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
        {
    		if(!TranslateAccelerator(Msg.hwnd, accTable, &Msg))
    		{
    			TranslateMessage(&Msg);
    			DispatchMessage(&Msg);
    		}
    	}
    and put some capturing code in WM_COMMAND. by the way, there are no child windows in this program, so i dont need to subclass or anything to get the accelerator message.

    something is not right, because spy++ shows that no message is being sent for the accelerator, just the usual bunch of keydown and keyup messages. how do i fix it?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    i narrowed down the problem a bit more. if you specify the flags FSHIFT or FCONTROL, the accelerator will ONLY work if you press the designated key by itself. however the FALT flag works fine. when flags are combined, eg, FALT|FCONTROL, the accelerator works only when ALT and the key are held down. if CTRL is held down, it doesn't work. the same goes for SHIFT.
    it seems to me that the status of the CTRL and SHIFT keys is reversed as far as my program is concerned. anyone ever had this happen to them?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    When you do this:
    Code:
    if(!TranslateAccelerator(Msg.hwnd, accTable, &Msg))
    The msg is sent to whatever window procedure is defined for 'Msg.hwnd'. If you want all your accelerator keys to be picked up by your parent window then use its handle exclusively instead.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error in creating socket in a client (UDP)
    By ferenczi in forum Networking/Device Communication
    Replies: 2
    Last Post: 11-27-2008, 10:11 AM
  2. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  3. creating variables on the fly
    By Aalmaron in forum C++ Programming
    Replies: 13
    Last Post: 04-11-2006, 12:06 PM
  4. creating variables on the fly?
    By Brigs76 in forum C Programming
    Replies: 2
    Last Post: 06-19-2005, 01:59 PM
  5. Creating an Code-template in Visual C++
    By yerrel in forum C++ Programming
    Replies: 1
    Last Post: 06-10-2002, 11:25 AM

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