Solved

Win32 Dialog

Posted on 2000-04-11
9
1,391 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

810 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