Help me learn to use accelerators

This is a discussion on Help me learn to use accelerators within the Windows Programming forums, part of the Platform Specific Boards category; hi, i am trying to learn how to use accelerators. Here's what i have done so far in my main ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    114

    Talking Help me learn to use accelerators

    hi, i am trying to learn how to use accelerators.

    Here's what i have done so far


    in my main message loop :
    Code:
    	
    	HACCEL 	haccel = LoadAccelerators( GetModuleHandle(0),   MAKEINTRESOURCE(IDC_AINTERFACE)  );
    
    	while(GetMessage(&Msg, NULL, 0, 0) > 0)
    	{
    		TranslateAccelerator(calc_hwnd,      // handle to receiving dialog right?			haccel,        // handle to active accelerator table 
    			&Msg)   ;   // message data */
    			
    
    			TranslateMessage(&Msg);
    			DispatchMessage(&Msg);
    	}


    For calc_hwnd's callback function, where there's a problem
    Code:
    BOOL CALLBACK calcproc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
        switch(Message)
        {
            case WM_INITDIALOG:
    			{
    			SendDlgItemMessage(hwnd,IDC_HOUR, EM_SETLIMITTEXT, (WPARAM)2,0);
    			SendDlgItemMessage(hwnd,IDC_MIN, EM_SETLIMITTEXT, (WPARAM)2,0);
    			break;
    			}
            return TRUE;
            case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                  /*  case IDOK:
                        EndDialog(hwnd, IDOK);
                    break;
                    case IDCANCEL:
                        EndDialog(hwnd, IDCANCEL);
                    break;*/
    
    			case IDM_TAB:
    				{
    					int a = 5;  // !!PROBLEM PROBLEM !! : here where a doesnt become 5 because no "IDM_TAB" message was received.
    				}
    				break;
    
    			case IDC_EXIT:
    				{
    					EndDialog(calc_hwnd, IDOK);
    					EnableWindow(dia_hwnd, TRUE);
    
    					break;
    				}
    
                }
            break;
            default:
                return FALSE;
        }
        return TRUE;
    }

    The name of my accelerator resource is IDC_AINTERFACE.
    I defined it such that the ID "IDM_TAB" has key "VK_TAB" of type "VIRTKEY"


    I believe there's something very wrong with this. can anyonoe pls correct me?


    using
    - win 98se
    - API Style
    - vc++6.0
    Last edited by hanhao; 05-24-2004 at 01:04 AM.

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    I can't see anything wrong with your code. All I can think of is:

    1. Under 'case IDM_TAB', put a call to MessageBox():
    Code:
    MessageBox(NULL,"tab pressed",NULL,NULL);
    That will tell us for sure whether or not the point is being reached.

    2. Check to make sure the accelerator table was loaded correctly:
    Code:
    HACCEL 	haccel = LoadAccelerators( GetModuleHandle(0),   MAKEINTRESOURCE(IDC_AINTERFACE)  );
    if (!haccel)
        MessageBox(NULL,"Accelerator Table not loaded correctly",NULL,NULL);
    That should narrow the problem down.
    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
    Also make sure that you are properly trapping accelerator keys in your WM_COMMAND (see wParam parameter description) handler by checking that HIWORD(wParam)=1, eg;
    Code:
    if (HIWORD(wParam)==1 && LOWORD(wParam)==IDM_TAB)
      {
      /*accelerator key 'IDM_TAB' pressed
      }
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    114
    yo i got it!!!!!!!!!
    Code:
    BOOL CALLBACK calcproc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
        switch(Message)
        {
            case WM_INITDIALOG:
    			{
    			SendDlgItemMessage(hwnd,IDC_HOUR, EM_SETLIMITTEXT, (WPARAM)2,0);
    			SendDlgItemMessage(hwnd,IDC_MIN, EM_SETLIMITTEXT, (WPARAM)2,0);
    			break;
    			}
            return TRUE;
            case WM_COMMAND:
    			case IDM_TAB:
    				{
    					int a = 5;
    						MessageBox(NULL, "TAB PRESSED", "Error!",MB_ICONEXCLAMATION | MB_OK);
    				}
    				break;
    this should be before "switch(LOWORD(wParam))" not after

    thnx anyway for your help

  5. #5
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Your code may seem to work but it is still incorrect. All that is happening is, any WM_COMMAND message, which could mean any number of things, is simply executing the code under 'case IDM_TAB:', because there is no 'break' or 'return'. Try clicking a button or control, you will get the message "TAB PRESSED" as well.

    Could you please zip up your entire project folder (minus the executable) and post it here? There must be some small detail that is preventing this from working.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    114
    ok, i figured it out already
    the above code is correct
    but for some reason i gotta rewrite my accelerator with a different name

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What do I learn now?
    By Lorgon Jortle in forum C++ Programming
    Replies: 14
    Last Post: 03-14-2009, 06:44 PM
  2. Looking to learn C++
    By Fuzzy91 in forum C++ Programming
    Replies: 40
    Last Post: 04-13-2006, 02:38 AM
  3. You have to learn C in order to learn C++
    By gandalf_bar in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 07-16-2004, 10:33 AM
  4. Trying to learn guitar
    By Ben_Robotics in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 07-10-2003, 03:15 AM
  5. Advice on how to being to learn C++
    By VenomUK in forum C++ Programming
    Replies: 9
    Last Post: 05-18-2002, 01:06 PM

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