Can't Implement Tabbing

This is a discussion on Can't Implement Tabbing within the Windows Programming forums, part of the Platform Specific Boards category; I've searched this site, MSDN, and various other sites, but I still can't find any good tutorials on how to ...

  1. #1
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210

    Can't Implement Tabbing

    I've searched this site, MSDN, and various other sites, but I still can't find any good tutorials on how to implement keyboard input. I thought I understood how it worked vaguely, but no matter how I try to implement tabbing in my app, my sytstem just beeps at me. It's not the like the code doesn't compile, I just can't register the tab key. According to MSDN, tabbing is a feature handled by DefWndProc(); but I've found this to be untrue.

    So far I've tried various ways, but this is my best approach. I include this statement in the WndProc Callback:
    Code:
    switch: (message)
    {
          case WM_KEYDOWN:
          {
          int vKey = (int)wParam;
          if(vKey == VK_TAB)
          {
          OnDestroy();  //to test the validity of my statement
          }
          return TRUE;
          }
    }
    I was going to use this appraoch along with the GetNextDlgTabItem(); function and the WS_TABSTOP flag. But it still just beeps, beeps, beeps at me! I'm going mad

    The code is quite long so I'll post it if you want to take a look. Yes, I borrowed the frame from Ken Fitlike. My thanks to him. Yes, But I mostly understand what's going on in the code as you'll see through my implementation of other features. If anyone can explain what I'm missing I'd appreciate it.
    Attached Files Attached Files
    Last edited by Invincible; 02-25-2002 at 02:45 AM.
    "The mind, like a parachute, only functions when open."

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    In general, you do not need to process the TAB key, Windows does it for you.

    >>>
    According to MSDN, tabbing is a feature handled by DefWndProc(); but I've found this to be untrue.
    <<<

    This is true. You can set the tab order for a dialog etc. when you create it, or dynamically by specifying the "Z Order", (the third dimension on your screen!). You can modify the Z order with SetWindowPos() for example. If you have found this to be untrue, then I would guess you are doing something wrong!!! What is not working?

    (Sorry, I'm busy today, I don't have time to look at your code!)
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210
    I'll tell you what is not working. I've created four edit boxes as child windows. On each event, SetFocus() goes back to the first edit box. The edit boxes are written in the order I wish them to be tabbed. However, I changed my code so I could get the focus off the edit box, and I find that my system beeps at me when I press any of the non-ascii keys only when the focus is set to an edit box. In other words, my child window of an edit box is not accepting any non-ascii keypresses I guess.

    Hmm, that leads me to think some of the messages from my controls aren't being handled. How could that be?
    "The mind, like a parachute, only functions when open."

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Have you got IsDialogMessage() with the Window handle for your window in it in your Windows loop?

    >>>
    Although the IsDialogMessage function is intended for modeless dialog boxes, you can use it with any window that contains controls, enabling the windows to provide the same keyboard selection as is used in a dialog box.

    When IsDialogMessage processes a message, it checks for keyboard messages and converts them into selection commands for the corresponding dialog box. For example, the tab key, when pressed, selects the next control or group of controls, and the down arrow key, when pressed, selects the next control in a group.

    Because the IsDialogMessage function performs all necessary translating and dispatching of messages, a message processed by IsDialogMessage must not be passed to the TranslateMessage or DispatchMessage function.
    <<<

    MSDN...
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210
    Thanks Adrian. That worked. I can now tab through my edit boxes. Although, it took me all day to figure out what happened to my handle in the mess of OOP. I feel cheapened for not learning how to override the tab key though

    I set up my buttons to return the focus to my first edit control, but they still have dark lines around them after I push them (not dashed tab selection lines, but darker lines around the outer edge), and one of my buttons even starts in this state. How can I fix this?

    No wait, I was wrong. It doesn't happen when I open the program. It happens the first time I tab. My last button is hi-lighted with a thick black line... grrr.
    Last edited by Invincible; 02-26-2002 at 02:19 AM.
    "The mind, like a parachute, only functions when open."

  6. #6
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Well can you either a) post a screen shot of what you are talking about, or b) post the executable somewhere so I can look at it?. The other thing your going to have to do is post some relevent code to your creation of your 1) Window, 2) each Controll that has a problem, and your WndProc.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  7. #7
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210
    Sorry, here's the new source.
    Attached Files Attached Files
    "The mind, like a parachute, only functions when open."

  8. #8
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Try changing your msg loop to:
    Code:
    while (GetMessage(&Msg,NULL,0,0))
        {
        /*first check if the message is from a resource defined keyboard accelerator key*/
        //if (!TranslateAccelerator(hwnd,hAccelTable,&Msg))
            {
            /*now check for default dlg keyboard keys eg TAB, ESC*/
    	if ((!IsWindow(hwnd))||(!IsDialogMessage(hwnd,&Msg)))
                {
                /*translate and dispatch other messages*/
                TranslateMessage(&Msg);
                DispatchMessage(&Msg);
                }
    	}
        }
    You will need to add additional code your WM_COMMAND handler to check for the ESC key being pressed or the wnd close btn; the handler will receive IDCANCEL (system defined) as the LOWORD(wParam) ie the id.

  9. #9
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    I just downloaded it and it runs fine. Are you talking about the black around the buttons? If so thats just the focus. But its gonna take me a while to find out why the focus highlight stays on your buton when one of the other controls recieves focus. Ill fill you in as soon as I can, im taking a break from studying for my midterms right now so I might not post again till late tonight or tomorow afternoon
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  10. #10
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210
    Thanks Ken, that worked fine. I can now close my window with the escape key But can you tell me why I'm having such a hard time overriding the virtual keys? I thought they were stored in wParam as well... are they LOWORD too?

    And thank you also xds4lx, I would appreciate if you would. No, hurry
    "The mind, like a parachute, only functions when open."

  11. #11
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210
    Well, solved one problem. I changed my exit button to IDCANCEL rather then a user defined ID and the focus no longer defaults to that button when tab is pressed. Now if I could just figure out to make my other buttons release their focus. Actually, they do release the focus every other click. Strange...
    "The mind, like a parachute, only functions when open."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 12-20-2007, 07:55 PM
  2. How to implement ISRs in C ?
    By Ambika in forum C Programming
    Replies: 11
    Last Post: 11-16-2007, 08:47 AM
  3. best STL method to implement a binary tree
    By MatthewDoucette in forum C++ Programming
    Replies: 8
    Last Post: 06-16-2006, 08:08 AM
  4. Implement "Whats This" using Win32
    By hemanth.balaji in forum Windows Programming
    Replies: 1
    Last Post: 05-29-2005, 07:03 AM
  5. How to implement custom window message
    By naruto in forum Windows Programming
    Replies: 1
    Last Post: 08-27-2004, 09:19 PM

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