Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Win32 Dialog

Posted on 2000-04-11
9
Medium Priority
?
1,415 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 300 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

636 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