Getting Key state in Dialog based app

This is a discussion on Getting Key state in Dialog based app within the Windows Programming forums, part of the Platform Specific Boards category; Hey guys. I want to have my dialog based app react when ALT+SPACE is pressed, but I'm having some trouble ...

  1. #1
    Unregistered
    Guest

    Getting Key state in Dialog based app

    Hey guys. I want to have my dialog based app react when ALT+SPACE is pressed, but I'm having some trouble with it. Searching the net I see to try and use WM_CHAR or WM_KEYDOWN but when I try to break on those with my debugger it never happens. I'm assuming that those never get sent with dialog based apps?? Can anyone help me out with some code or maybe a link with some info?? Thanks always!!!

    -Aaron

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    317
    Are you using MFC or API ?

  3. #3
    Unregistered
    Guest
    Sorry. Here's the specifics. I'm using Borland c++ commandline tools with just API. No classes or MFC.

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    317
    So, you tried to trap those in your dialog procedure?

  5. #5
    Unregistered
    Guest
    I tried case WM_KEYDOWN: and case WM_CHAR: then going from there, but nothing happens. Like I said, I set breaks on those with the debugger and it doesn't break.

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Try trapping the WM_GETDLGCODE message.

    Something like this.

    Code:
    case WM_GETDLGCODE:
      return( DLGC_WANTALLKEYS );

  7. #7
    Registered User
    Join Date
    May 2002
    Posts
    317
    Is it a Modal or Modeless dialog box. For a modeless dialog box you get all the messages through your message queue, and if it is a dialog based app that sound slike the way you would want to go.

  8. #8
    Registered User
    Join Date
    May 2002
    Posts
    317
    So:
    Code:
    hDlgModeless=CreateDialog(hInstance,MAKEINTRESOURCE (IDD_DIALOG),hwnd,ColorScrDlg);
    
    while(GetMessage(&msg,NULL,0,0)){
            if(hDlgModeless==0||!IsDialogMessage(hDlgModeless,&msg))
            {
    	TranslateMessage(&msg);
    	DispatchMessage(&msg);
            }
    }
    This is how you would create a modeless dialog, with the CreateDialog function. Then you would setup your message queue like this to intercept any messages from the dialog and send them to you dlg proc.

  9. #9
    Unregistered
    Guest
    Well, so far all the samples I've found on the web show the dialog being called from a window. I'm just using only a dialog. Will this make a difference in trying to tell what keys are down?

  10. #10
    Registered User VBprogrammer's Avatar
    Join Date
    Mar 2002
    Posts
    175
    What about GetAsyncKeyState()?
    VC++ 6

  11. #11
    Unregistered
    Guest
    Let me also explain exactly what EXACTLY I'm wanting to do, in case it makes a differance. I want to use a key combo, ie ALT + SPACE to hide my Dialog based app. I could just set a button with ShowWindow(hwnd, SW_HIDE); but I'm not sure how to get the dialog back. Thus, I'm trying to see if a key combo was pressed or even just one key such as F11 or something. I hope this is clear. I'm still very new to this.

    -Aaron

  12. #12
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Try creating and accelerator table,

    or if capturing the WM_KEYDOWN.

    Try checking the 24th byte of the LPARAM. If it is true (==1) then either the ALT or CRL keys were held down as the key was pressed. You are looking for VK_SPACE (==20) as well.

    (you are using TranslateMessage() ? or the keycodes will not be translated and sent as messages)
    "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

  13. #13
    Unregistered
    Guest
    Hey Novacain, thanks for that info. I'm finding some bits and pieces on it now. Can you post maybe some sample code on using the accelerator table? Yes, I am using TranslateMessage but still nothing is working with it. Thanks for the help.

    -Aaron

  14. #14
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    I use MSVC 6 so may be some differences.

    Simplest method is to insert an accelerator table using the resource builder. Add your ALT+SPACE combo. Call the whole table say, IDA_ACCEL

    In your winmain()

    Code:
    hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_ACCEL));
    //error check hAccel
    //for both MDI (remove the MDI translate if only a single document app)
    while (GetMessage(&msg, (HWND) NULL, 0, 0)) 
    {
         if( (!TranslateMDISysAccel( msg.hwnd, &msg)) && (!TranslateAccelerator( msg.hwnd, hAccel, &msg)))
         { 
              TranslateMessage(&msg); 
              DispatchMessage(&msg); 
         } 
    }
    "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

  15. #15
    Unregistered
    Guest
    Ok novacain, once I set that under WinMain, I should then beable to go case WM_COMMAND: switch(LOWORD(WParam)) and then case CM_ACCEL1: and have my code there? Cause that's what I have and it's not working. Everything else works, but when I SHIFT+SPACE a space shos up in my edit control. Thanks for all your input on this.

    -Aaron

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. input/switch statement issues
    By peanut in forum C Programming
    Replies: 5
    Last Post: 10-27-2006, 02:58 PM
  2. Creating a Dialog Based Application without MFC
    By MitchellH in forum C++ Programming
    Replies: 8
    Last Post: 05-21-2005, 10:02 AM
  3. make Child Dialog not Popup?
    By Zeusbwr in forum Windows Programming
    Replies: 5
    Last Post: 04-08-2005, 02:42 PM
  4. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM
  5. onKeyDown(), question in dlg based app
    By codewarrior in forum Windows Programming
    Replies: 0
    Last Post: 10-24-2001, 05:26 AM

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