Link to home
Start Free TrialLog in
Avatar of oviv
oviv

asked on

Win32 Dialog

I have a Dialog that I created in Win32 (No MFC).  It has one edit control and 2 button controls.  I would like to be able to tab from control to control as well as use nemonics.  I set the WS_TABSTOP when I created the windows using CreateWindow but still it does not work.  Here is my code:

    g_hInstance = hInstance;
    WNDCLASS wc;
    ZeroMemory( &wc, sizeof(wc) );
    wc.lpfnWndProc =  ShellHookTestWndProc;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon( 0, IDI_WINLOGO );
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
    wc.lpszClassName = g_pszWndClass;
      
    if (RegisterClass(&wc))
    {
        HWND hwnd = CreateWindow( g_pszWndClass, "Security Failure", WS_OVERLAPPED|WS_CAPTION|WS_TABSTOP, CW_USEDEFAULT, CW_USEDEFAULT, 400, 75, NULL, NULL, g_hInstance, NULL );
        if (hwnd)
        {
     
                  
                  HWND ws;
                  HWND wt;
                  HWND wb;
                  HWND wb2;
                  ws=CreateWindow( TEXT("Static"), TEXT("Failed to start Main Application.  Enter Fail Safe: "), WS_CHILD|WS_VISIBLE, 0, 0, 400, 25, hwnd, (HMENU)ID_STATIC, g_hInstance, NULL );
                  wt=CreateWindow( TEXT("Edit"), TEXT(""), WS_CHILD|WS_VISIBLE|WS_BORDER|ES_PASSWORD|WS_TABSTOP, 0, 15, 100, 25, hwnd, (HMENU)ID_EDIT, g_hInstance, NULL );                        wb=CreateWindow( TEXT("Button"), TEXT("&OK"), WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_PUSHBUTTON|BS_DEFPUSHBUTTON, 105, 15, 50, 25, hwnd, (HMENU)ID_BNOK, g_hInstance, NULL );      
                  wb2=CreateWindow( TEXT("Button"), TEXT("&Cancel"), WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_PUSHBUTTON, 160, 15, 50, 25, hwnd, (HMENU)ID_BNCANCEL, g_hInstance, NULL );      
Avatar of Brain2000
Brain2000
Flag of United States of America image

Create the ws "Static" style Window last.  If that doesn't work, then add WS_GROUP to all 3 that also have WS_TABSTOP.
Avatar of oviv
oviv

ASKER

Sorry That did not work.
Avatar of oviv

ASKER

Sorry That did not work.
Interesting.  I had read that if you have a "Static" control in the mix, to make sure it is after all the WS_TABSTOP items.  I also read you can specifically group sets together by using WS_GROUP.  Let me see if I have a few minutes today to compile the code you have above and see if I can't get it working on my end, then I'll post the working code.
ASKER CERTIFIED SOLUTION
Avatar of Laminamia063099
Laminamia063099

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I've never had problem doing dialogs as a resource, but now I'm curious as how to get the tabs to work when creating a dialog manually...
Avatar of oviv

ASKER

Brain2000,

Since my dialog isn't really a dialog (not a modal form), I had to add IsDialogMessage to my message loop before sending message on to TranslateMessage.  This took care of it.  See below:

          while (GetMessage(&msg, 0, 0, 0))
            {      
                        if (!IsDialogMessage(myhwnd,&msg))
                        {
                              TranslateMessage(&msg);
                              DispatchMessage(&msg);
                        }
              }

Thanks to all for your help.
Note:

If you are creating a window that you want to be a dialog without using a resource, you have to subclass the child windows in the dialog (The edit controls and buttons that you want to be able to tab through).  I don't have code with me on it (I do at home however) but it essentially lets you create a Callback function that is called when those child controls get messages.  In this function you need to capture WM_KEY messages (or something like that) and look for when the key is VK_TAB.  When you get that, you set the focus to the next control (you would have to keep an array of the child controls in the order that you wished to tab through them).

This is how I have solved the problem you mentioned, Brain2000.

Laminamia :)
Sounds to me like there's more than one way to skin a cat here.

IsDialogMessage, eh?  I'm going to have to check that out.  That's a new one to me.