tags:

views:

290

answers:

2
+1  A: 

The dialog manager does a lot of this for you, so if you don't have a good reason for creating your own window class, you might consider creating a dialog instead.

If you're still of a mind to roll your own, you'll have to intercept WM_CHAR and look for VK_TAB and VK_SHIFT | VK_TAB. The dialog manager uses something called "z-order" as the tab order (http://msdn.microsoft.com/en-us/library/ms632599%28VS.85%29.aspx#zorder).

FWIW, my advice would be to not underestimate the burden you're taking on when trying to re-create an existing facility in Windows like this. For every behavior that you know about, there are usually at least as many that you don't. For example, how will your application behave on a pen-based device? What about accessibility extensions? Will screen readers be able to handle it properly? All of that stuff is already baked into the dialog manager.

I'm not sure I followed... I thought dialogs are just a floating windows above the "regular" (?) one. Is it possible that the application uses just a dialog, instead of proper CreateWindow()?

Dialogs can be modal or modeless children of the main application window, but they can also be the main application window. That's typically called a dialog-based app.

If you want a dialog-based application (that is, an application with a dialog as it's main window), you'd do something like this:

int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow )
{
    MSG msg;
    HWND hDlg = CreateDialog(hInst, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DialogProc);
    if (hDlg != NULL)
    {
        ShowWindow(hDlg, SW_SHOWNORMAL);

        while (GetMessage(&msg, NULL, 0, 0)) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
    return 0;
}

The full example is probably too long to list here, but if you Google for CreateDialog, you should find some examples of this.

...And is it possible to add other windows inside a dialog? Even with custom window procedures? (In other words, in dialogs, am I not restricted just to the default controls, like edit and static?)

Yes, you can create custom controls within the dialog. Within the DIALOG portion of your .rc file, you can include something like:

CONTROL "",IDC_MYCUSTOM,"MyCtrlClassName",WS_TABSTOP,10,20,30,40

You can also create a new control and add it to the dialog dynamically (I'll let you Google for an example).

Also, if I wanted to roll my own, how do I find out what's the next control? I don't really think there will be more use cases than a basic desktop

Use GetNextDlgTabItem() if you want to cycle through the controls within a dialog in tab-order: http://msdn.microsoft.com/en-us/library/ms645495%28VS.85%29.aspx

If you're rolling your own, then you probably want something like the EnumChildWindows() function: http://msdn.microsoft.com/en-us/library/ms633494%28VS.85%29.aspx

This may also be useful: http://msdn.microsoft.com/en-us/library/bb775501%28VS.85%29.aspx

Scott Smith
I'm not sure I followed... I thought dialogs are just a floating windows above the "regular" (?) one. Is it possible that the application uses just a dialog, instead of proper CreateWindow()? And is it possible to add other windows inside a dialog? Even with custom window procedures? (In other words, in dialogs, am I not restricted just to the default controls, like edit and static?)
Lars Kanto
Also, if I wanted to roll me own, how do I find out what's the next control? I don't really think there will be more use cases than a basic desktop...
Lars Kanto
A: 

This kind of processing can be easily added to an application :- Add a call to IsDialogMessage() in your message loop - all the controls have to have the WS_TABSTOP style.

The parent window might have to be of the dialog class as the dialog window class stores state allowing it to (for example) restore focus to the correct control when activation is lost and restored.

Chris Becke