Dialog Box error
-
Hey again to all... I have a code that creates a dialog box... But this dialog box is useless cause it doesn't handle none of its messages... And when I call DefDlgProc there is an error when it tries to handle message #48 (I think) about a 1000 times. here is my code:
#include <windows.h>
#include "resource.h"bool g_run = true;
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
ShowWindow(hDlg,SW_SHOW);
return TRUE;case WM\_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { g\_run = false; EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break;
/* default:
return DefDlgProc(hDlg,message,wParam,lParam);
break;
*/ }
return FALSE;
}int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
HWND hwnd = CreateDialog(hInstance, (LPCTSTR)IDD_DIALOG1, NULL ,(DLGPROC)About);
if (hwnd == NULL)
{
DWORD err = GetLastError();
}while (g\_run); return 0;
};
-
Hey again to all... I have a code that creates a dialog box... But this dialog box is useless cause it doesn't handle none of its messages... And when I call DefDlgProc there is an error when it tries to handle message #48 (I think) about a 1000 times. here is my code:
#include <windows.h>
#include "resource.h"bool g_run = true;
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
ShowWindow(hDlg,SW_SHOW);
return TRUE;case WM\_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { g\_run = false; EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break;
/* default:
return DefDlgProc(hDlg,message,wParam,lParam);
break;
*/ }
return FALSE;
}int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
HWND hwnd = CreateDialog(hInstance, (LPCTSTR)IDD_DIALOG1, NULL ,(DLGPROC)About);
if (hwnd == NULL)
{
DWORD err = GetLastError();
}while (g\_run); return 0;
};
Hey... dude... You need to change your
while (g_run);
line to this lines:BOOL bRet; MSG msg; while ((g\_run) && ( (bRet = GetMessage(&msg, NULL, 0, 0)) != 0 )) { if (bRet == -1 ) { // handle the error and possibly exit } else if (!IsWindow(hwnd) || !IsDialogMessage(hwnd, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } }
**I wonder why it works ???? Really.. I don't know why it works... but it does**
-
Hey... dude... You need to change your
while (g_run);
line to this lines:BOOL bRet; MSG msg; while ((g\_run) && ( (bRet = GetMessage(&msg, NULL, 0, 0)) != 0 )) { if (bRet == -1 ) { // handle the error and possibly exit } else if (!IsWindow(hwnd) || !IsDialogMessage(hwnd, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } }
**I wonder why it works ???? Really.. I don't know why it works... but it does**
I tell why it works... :-O it didn't work because your dialog window didn't recieve the messages. :-O Now it works because your dialog now recieves the messages... that is why we need to use
TranslateMessage
andDispatchMessage
. :-O