Modeless dialog as main program window & Combo Boxes

Modeless dialog as main program window & Combo Boxes

Post by Jonathan Zimmerm » Sun, 19 Mar 2000 04:00:00



Hi,
        I'm fairly green when it comes to straight Win32 programming, so maybe
the answer to my problem is fairly simple.

My WinMain calls CreateDialog to create a modeless dialog. I then ShowWindow
and UpdateWindow to display the dialog. Finally, I start the message loop:
        while (GetMessage(hWnd, &msg, 0, 0) > 0) {
                .
                .
                .
        }

Inside the DlgProc if the message is a WM_COMMAND I check the LOWORD(wParam) to
see if the exit button (or close-window button on the dialog frame) has been
clicked. I then call PostQuitMessage(0) and return FALSE from the DlgProc.

This works well.

I've added several controls to the dialog box: static controls, edit controls,
buttons, and list controls. When I add a combo box control to the dialog box,
things stop working properly. If you click the combo box the dialog "hangs."
The list portion of the combo doesn't show, and the only way to regain control
of the dialog is to bring another application to the foreground and then bring
the dialog back up... and even then, I may have to click the Exit button a few
times to fix the problem.

Anybody know what my trouble is? If you want, I can send the code from my
DlgProc.

Thanks!

Jonathan Zimmerman

 
 
 

Modeless dialog as main program window & Combo Boxes

Post by Chris Beck » Mon, 20 Mar 2000 04:00:00



> Hi,
> I'm fairly green when it comes to straight Win32 programming, so maybe
> the answer to my problem is fairly simple.

> My WinMain calls CreateDialog to create a modeless dialog. I then
ShowWindow
> and UpdateWindow to display the dialog. Finally, I start the message loop:
> while (GetMessage(hWnd, &msg, 0, 0) > 0) {
> .
> .
> .
> }

> Inside the DlgProc if the message is a WM_COMMAND I check the
LOWORD(wParam) to
> see if the exit button (or close-window button on the dialog frame) has
been
> clicked. I then call PostQuitMessage(0) and return FALSE from the DlgProc.

> This works well.

Just calling "DialogBox" would work too, in addition it would be far
simpler.

- Show quoted text -

Quote:> I've added several controls to the dialog box: static controls, edit
controls,
> buttons, and list controls. When I add a combo box control to the dialog
box,
> things stop working properly. If you click the combo box the dialog
"hangs."
> The list portion of the combo doesn't show, and the only way to regain
control
> of the dialog is to bring another application to the foreground and then
bring
> the dialog back up... and even then, I may have to click the Exit button a
few
> times to fix the problem.

> Anybody know what my trouble is? If you want, I can send the code from my
> DlgProc.

I have no clue as to why the combo box will misbehave like that. Other
things are going to misbehave (tabbing) unless you include a call to
IsDialogMessage() in your GetMessage loop.

For fixing the misbehaving combobox, I'd check you arn't accidently
returning TRUE from the DlgProc for messages you arn't actually handling /
and or ensure that none of the case clauses is falling through to the next
case due to a missing break.

Chris
--
VisualC++ & Win32 FAQ: http://www.mvps.org/vcfaq
My Win32 Page: http://www.mvps.org/user32

 
 
 

Modeless dialog as main program window & Combo Boxes

Post by Strohm Armstron » Tue, 21 Mar 2000 04:00:00


You need to pass NULL for the window handle in GetMessage. GetMessage is
only retrieving messages for the dialog and no other windows.

Your example has the HWND and LPMSG reversed. I assume this is just a typo.

You won't get any default dialog behavior unless you call IsDialogMessage.

As Chris said, DialogBox would be better if it works for you.


Quote:> Hi,
> I'm fairly green when it comes to straight Win32 programming, so maybe
> the answer to my problem is fairly simple.

> My WinMain calls CreateDialog to create a modeless dialog. I then
ShowWindow
> and UpdateWindow to display the dialog. Finally, I start the message loop:
> while (GetMessage(hWnd, &msg, 0, 0) > 0) {
> .
> .
> .
> }

> Inside the DlgProc if the message is a WM_COMMAND I check the
LOWORD(wParam) to
> see if the exit button (or close-window button on the dialog frame) has
been
> clicked. I then call PostQuitMessage(0) and return FALSE from the DlgProc.

> This works well.

> I've added several controls to the dialog box: static controls, edit
controls,
> buttons, and list controls. When I add a combo box control to the dialog
box,
> things stop working properly. If you click the combo box the dialog
"hangs."
> The list portion of the combo doesn't show, and the only way to regain
control
> of the dialog is to bring another application to the foreground and then
bring
> the dialog back up... and even then, I may have to click the Exit button a
few
> times to fix the problem.

> Anybody know what my trouble is? If you want, I can send the code from my
> DlgProc.

> Thanks!

> Jonathan Zimmerman

 
 
 

Modeless dialog as main program window & Combo Boxes

Post by Jonathan Zimmerm » Tue, 21 Mar 2000 04:00:00


I found the problem with the combo box.. Passing NULL for the window handle in
GetMessage solved the problem. For simplicity, I suppose it doesn't matter
whether you use DialogBox or CreateDialog. I guess I like pain. :)

Thanks for the help.

Jonathan Zimmerman


>You need to pass NULL for the window handle in GetMessage. GetMessage is
>only retrieving messages for the dialog and no other windows.

>Your example has the HWND and LPMSG reversed. I assume this is just a typo.

>You won't get any default dialog behavior unless you call IsDialogMessage.

>As Chris said, DialogBox would be better if it works for you.



>> Hi,
>> I'm fairly green when it comes to straight Win32 programming, so maybe
>> the answer to my problem is fairly simple.

>> My WinMain calls CreateDialog to create a modeless dialog. I then
>ShowWindow
>> and UpdateWindow to display the dialog. Finally, I start the message loop:
>> while (GetMessage(hWnd, &msg, 0, 0) > 0) {
>> .
>> .
>> .
>> }

>> Inside the DlgProc if the message is a WM_COMMAND I check the
>LOWORD(wParam) to
>> see if the exit button (or close-window button on the dialog frame) has
>been
>> clicked. I then call PostQuitMessage(0) and return FALSE from the DlgProc.

>> This works well.

>> I've added several controls to the dialog box: static controls, edit
>controls,
>> buttons, and list controls. When I add a combo box control to the dialog
>box,
>> things stop working properly. If you click the combo box the dialog
>"hangs."
>> The list portion of the combo doesn't show, and the only way to regain
>control
>> of the dialog is to bring another application to the foreground and then
>bring
>> the dialog back up... and even then, I may have to click the Exit button a
>few
>> times to fix the problem.

>> Anybody know what my trouble is? If you want, I can send the code from my
>> DlgProc.

>> Thanks!

>> Jonathan Zimmerman

 
 
 

1. Using accelerators when a modeless dialog box is the main window

I'm writing a control panel that uses a modeless dialog box as its main
window.  Somehow I can't seem to trap the accelerator keys.  Here's the
beginning part:

case CPL_DBLCLK:
        CreateDialog(hinst, MAKEINTRESOURCE(IDD_MAIN), hwndCPl,
(DLGPROC)DialogProc);
        hAccelTable = LoadAccelerators(hinst, MAKEINTRESOURCE(IDR_ACCELERATOR));
        while (GetMessage(&msg, NULL, 0, 0))
        {
                if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
                {
                        TranslateMessage(&msg);
                        DispatchMessage(&msg);
                }
        }
        break;

Then in the DialogProc, I try to get the message:

switch(uMsg)
{
        .
        .
        case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                        .
                        .
                        case IDM_MYMENUITEM:
                                MessageBox(GetFocus(), "Hello", "Test", MB_OK);
                                break;
                }
                break;

It doesn't work, though.  What am I missing?

Thanks,
Dave Herman

http://www.microcosm.com/~dave

To e-mail me, delete the underscore
at the end of my e-mail address.

2. Flobynoid

3. Help with modeless dialog box as the main window

4. Zoom 2819

5. OWL: How to put data in combo box on Main Window Dialog?

6. Position Repost due to mail failure/Jr. Quantitative Analyst/Modeling/SAS-CT

7. Calling a modeless dialog box from a modal dialog box

8. WTB: External SCSI enclosure

9. Keeping Main Window Active (with modeless Dialogs)

10. Modeless Dialogs as Main Windows

11. using ctl3d with modeless dialog as main window?

12. Dialog box as main window, how to in Windows 3.1?

13. decorated frame & modeless dialog box