Solved

Win32 Dialog

Posted on 2000-04-11
9
1,394 Views
Last Modified: 2008-02-01
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 );      
0
Comment
Question by:oviv
  • 4
  • 3
  • 2
9 Comments
 
LVL 8

Expert Comment

by:Brain2000
ID: 2705414
Create the ws "Static" style Window last.  If that doesn't work, then add WS_GROUP to all 3 that also have WS_TABSTOP.
0
 

Author Comment

by:oviv
ID: 2705498
Sorry That did not work.
0
 

Author Comment

by:oviv
ID: 2705580
Sorry That did not work.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 8

Expert Comment

by:Brain2000
ID: 2707973
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.
0
 
LVL 3

Accepted Solution

by:
Laminamia063099 earned 100 total points
ID: 2708903
Both tab and mnemonics are built in if you create this dialog window as a dialog resource.

An example resource script that would create your dialog would be:

#define IDD_DIALOG1 2000

IDD_DIALOG1 DIALOG DISCARDABLE  0, 0, 185, 46
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "MS Sans Serif"
BEGIN
    DEFPUSHBUTTON   "&OK",IDOK,128,7,50,14
    PUSHBUTTON      "&Cancel",IDCANCEL,128,24,50,14
    EDITTEXT        IDC_EDIT1,13,14,96,16,ES_AUTOHSCROLL
END
0
 
LVL 8

Expert Comment

by:Brain2000
ID: 2709839
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...
0
 

Author Comment

by:oviv
ID: 2709906
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.
0
 
LVL 3

Expert Comment

by:Laminamia063099
ID: 2711915
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 :)
0
 
LVL 8

Expert Comment

by:Brain2000
ID: 2712044
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.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question