CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2004
    Location
    Philippines
    Posts
    58

    How can i use shortcut keys?

    good day to all!i try to check some thread regarding shortcut keys but i cant find a good one.

    the scenario here is that i want to impliment actions using keyboard inputs. I may press f1-f8 and also alt combinations and ctrl combinations.

    how can i do this?

  2. #2
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: How can i use shortcut keys?

    You can use accelerators to combine keys with modifier to menues. Or you can use "RegisterHotkey" to register a global hotkey your pogramm can handle.

    Just use MSDN and search for these two phrases.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  3. #3
    Join Date
    Feb 2004
    Location
    Philippines
    Posts
    58

    Re: How can i use shortcut keys?

    can you give me a code snipet so i can have a good pattern... thats all..

  4. #4
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: How can i use shortcut keys?

    For me I cannot explain this all as good as here.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  5. #5
    Join Date
    Feb 2004
    Location
    Philippines
    Posts
    58

    Re: How can i use shortcut keys?

    i forgot to add... im using sdi application and all modules are in modal state....
    so every dialog that pops-up will have different shortcut approaches...
    i need some code samples to be my pattern code

  6. #6
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: How can i use shortcut keys?

    Quote Originally Posted by DjChris14
    i forgot to add... im using sdi application and all modules are in modal state....
    so every dialog that pops-up will have different shortcut approaches...
    i need some code samples to be my pattern code
    If you post your code, I will know what you are doing and how to add this functionality to your code. Otherwise it's hard to help you.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  7. #7
    Join Date
    Feb 2004
    Location
    Philippines
    Posts
    58

    Re: How can i use shortcut keys?

    i cant post the code because i havent started to put short cuts... anyway ill give you the logical flow what i wanted to do...

    in my dialog, i have several controls like radio button(3), check boxes(2), command buttons (command buttons can have its shortcut keys right?).

    if i press let say f1, one of the radio buttons will be true and the last 2 will be false.., if i press f2, check button1 will be active (and be deactivate) same with check button2...

    have you figure it out? can the accelerators handle it? i notice about the accelerators is that they pertains to controls on every commands being issued...

  8. #8
    Join Date
    Feb 2004
    Location
    Philippines
    Posts
    58

    Re: How can i use shortcut keys?

    in additional to it... if i dont register the control shortcuts of command button, is there an effect to it?

  9. #9
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: How can i use shortcut keys?

    Just create an appropiate accelerate resource - You can assign key strokes to ID's, so if this key is pressed within your application a WM_COMMAND message for the specified ID will occur - and change your 'InitInstance' as follows:

    Code:
    // Some code before
    
    // Load your accelerator table here
    HACCEL haccel = LoadAccelerators(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_ACCEL)); 
    
    // Possible check if haccel is NULL ...
    
    while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
    {
          if (bRet == -1)
          {
              // handle the error and possibly exit
          }
          else
          { 
                if (!TranslateAccelerator( 
                        hwndMain,  // handle to receiving window, use the hwnd of your main window here
                        haccel,
                        &msg)) 
                {
                    TranslateMessage(&msg); 
                    DispatchMessage(&msg); 
                } 
          } 
    }
    return FALSE
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured