![]() |
| | #1 |
| Madly in anger with you Join Date: Nov 2005
Posts: 211
| dialog box problem keeps haunting me I am just experimenting as I seem to be having very bad luck with creating dialog boxes with the API. well, I FINALLY got some code to work that actually displays the dialog box (usually the code will compile fine, but when I execute it there is no sign of the dialog box). ![]() here it is: Code: #include <windows.h>
#include "resource.h"
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
case WM_INITDIALOG:
SetDlgItemText(hwndDlg, IDC_EDIT, "hello there");
return TRUE;
case WM_CLOSE:
EndDialog(hwndDlg, 0);
return TRUE;
}
return FALSE;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
return DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG), NULL, (DLGPROC)DialogProc);
}
now here goes my question. on the dialog, there is also an OK (IDOK) button and a Cancel (IDCANCEL) button (by default). now, watch how I handle these button messages: Code: BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
case WM_INITDIALOG:
SetDlgItemText(hwndDlg, IDC_EDIT, "hello there");
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDOK:
EndDialog(hwndDlg, 0);
return TRUE;
case IDCANCEL:
EndDialog(hwndDlg, 0);
return TRUE;
}
case WM_CLOSE:
EndDialog(hwndDlg, 0);
return TRUE;
}
return FALSE;
}
could anyone here please tell me what looks wrong with the way I am handling those button messages? I would really like to know what I am doing wrong to keep getting these non appearing dialog boxes (like what can cause behaviour like this? I am sure I'm not the only one here that has had this problem). the program appears to be completing execution, so maybe I am adding a return statement somewhere where I shouldn't be? any help would be greatly appreciated, this same problem has been bugging me for a while now. thanks in advance!
__________________ Intel Core 2 Quad Q6600 @ 2.40 GHz 3072 MB PC2-5300 DDR2 2 x 320 GB SATA (640 GB) NVIDIA GeForce 8400GS 256 MB PCI-E |
| Bleech is offline | |
| | #2 |
| Registered User Join Date: May 2003
Posts: 1,199
| What would happen in your code if a WM_COMMAND message came that was neither IDOK nor IDCANCEL? There's no default condition in your switch(LOWORD(wParam)) statement, nor is there a return or break after that switch, so any WM_COMMAND apart from IDOK or IDCANCEL will reach the end of that inner switch statement and then keep executing the contents of case WM_CLOSE.
__________________ You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards. |
| Cat is offline | |
| | #3 |
| Madly in anger with you Join Date: Nov 2005
Posts: 211
| aha. my problem is not writing a break after WM_COMMAND (execution was falling through to WM_CLOSE). I was not expecting any messages to come other than the ones made by my controls. thanks for pointing that out Cat, here is my dialog callback now: Code: BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
case WM_INITDIALOG:
SetDlgItemText(hwndDlg, IDC_EDIT, "hello there");
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDOK:
EndDialog(hwndDlg, 0);
return TRUE;
case IDCANCEL:
EndDialog(hwndDlg, 0);
return TRUE;
default:
return DefWindowProc(hwndDlg, uMsg, wParam, lParam);
}
break;
case WM_CLOSE:
EndDialog(hwndDlg, 0);
return TRUE;
}
return FALSE;
}
__________________ Intel Core 2 Quad Q6600 @ 2.40 GHz 3072 MB PC2-5300 DDR2 2 x 320 GB SATA (640 GB) NVIDIA GeForce 8400GS 256 MB PCI-E |
| Bleech is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [MSVC] Is it valid to link against an import .lib generated from an executable? | pheres | C++ Programming | 9 | 02-13-2008 02:59 PM |
| Dialog Box error | JJFMJR | Windows Programming | 4 | 09-04-2007 07:51 AM |
| Parent of a BrowseForFolder dialog box | @nthony | Windows Programming | 4 | 01-08-2007 02:54 PM |
| Dialog Box Problems | Morgul | Windows Programming | 21 | 05-31-2005 05:48 PM |
| How to program a "back" button with MFC | 99atlantic | Windows Programming | 3 | 04-26-2005 08:34 PM |