Solved

Win32 Dialog

Posted on 2000-04-11
9
1,379 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now