   Stupid problem with Modeless dialog
  Hi all,Maybe someone can help me before I kill myself here. The following code is copied directly from Petzolds book (Programming Windows 5th edition). It is from the Hexcalc program. And I have stripped the unnessecary code from this example.Now what happens is that the dialog box is created, but no matter what I do, I cannot get it to close, or to respond to commands. Can anyone see why? Even the system menu will not close it. I have a feeling it may be there is a bug in Visual C++ 7 as no matter how many times I set the properties of the dialog to OVERLAPPED, it does not save it in the resources script. But would this cause these symptoms?#define WIN32_LEAN_AND_MEAN#include <windows.h>LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int nCmdShow){static TCHAR szAppName[] = TEXT("MyApp");HWNDhwnd;MSGmsg;WNDCLASSwc;wc.cbClsExtra= 0;wc.cbWndExtra= DLGWINDOWEXTRA; //NOTEwc.hbrBackground= (HBRUSH)(COLOR_BTNFACE + 1);wc.hCursor= LoadCursor(NULL, IDC_ARROW);wc.hIcon= LoadIcon(NULL, IDI_WINLOGO);wc.hInstance= hInstance;wc.lpfnWndProc= WndProc;wc.lpszClassName= szAppName;wc.lpszMenuName= NULL;wc.style= CS_HREDRAW | CS_VREDRAW;if (!RegisterClass(&wc)){MessageBox(hwnd, TEXT("Error: unable to register class!"), TEXT("Error!"), MB_OK | MB_ICONEXCLAMATION);return FALSE;}hwnd = CreateDialog(hInstance, szAppName, 0, NULL);ShowWindow(hwnd, nCmdShow);while (GetMessage(&msg, NULL, 0, 0)){TranslateMessage(&msg);DispatchMessage(&msg);}return msg.wParam;}LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){switch(msg){case WM_DESTROY:PostQuitMessage(0);return 0;}return DefWindowProc(hwnd, msg, wParam, lParam);} 
  hmmm....well I've never seen that TEXT("")ommand in my life but I'll assume that's not the problem since it compiles successfully. But as to why it's not responding....I'm not sure excpet that my Window Proc always looks like this: LRESULT CALLBACK WindowProc(HWND hwnd,UINT msg,    WPARAM wparam,    LPARAM lparam){// this is the main message handler of the systemPAINTSTRUCTps;// used in WM_PAINTHDChdc;// handle to a device contextchar buffer[80];   // used to print strings// what is the message switch(msg){case WM_CREATE:    {// do initialization stuff here   // return successreturn(0);} break;   case WM_PAINT: {// simply validate the window   hdc = BeginPaint(hwnd,&ps);  // end painting   EndPaint(hwnd,&ps);   // return successreturn(0);   } break;case WM_DESTROY: {// kill the application, this sends a WM_QUIT message PostQuitMessage(0);   // return successreturn(0);} break;default:break;    } // end switch// process any messages that we didn't take care of return (DefWindowProc(hwnd, msg, wparam, lparam));} // end WinProc EDIT: ARG it's b/c you forgot to add a break; at the end of WM_DESTROY   [edited by - sathenzar on February 14, 2004 8:38:47 PM];  IT shoudl look like this:    case WM_DESTROY:{  PostQuitMessage(0);  return 0;  break;};  Ah. Thanks It doesn''t actually fix it though - I think I have found at least part of the problem. In Visual C++ 6 you could just create a dialog as the main window as per the above code - by using the dialog editor. Unusually in Visual C++ 7 you actually have to specify the windows class that the dialog is to use in the properties editor. What threw me here is that unlike any other property box, you don''t enclose a string such as "MyApp" in quotations, otherwise in the resource script it will come out like this.. CLASS ""MyApp"".Secondly it doesn''t store this field in the properties dialog so there is no record (unless you look in the resource file) that the change has been made. Grrr!By the way TEXT(" ") is just a macro that is used with string literals to indicate that the string is a UNICODE string. It is superfluous here since I have not actually defined UNICODE anyway. Just a habit. Thanks for all your help. I''ll be back if I can''t figure the rest of this out! ;  When working with dialog boxes, you need to code a DialogProc rather than the standard WndProc.  DialogProc is *similar*, but not quite the same thing as a WndProc.  Check out this link for general information on using dialog boxes (scroll down to the section on modeless dialog boxes), and you can read about DialogProc here.Then when you call CreateDialog, pass DialogProc as the fourth parameter (lpDialogFunc) instead of NULL.It''s been at least a year since I''ve coded a Win32 dialog box, so I don''t know if this code is completely right, but I''ll give it a shot: BOOL CALLBACK DialogProc(HWND hDlgWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){  switch ( uMsg )  {    case WM_COMMAND:    { switch ( LOWORD( wParam ) ) {   case CLOSING_BUTTON_ID:   {EndDialog( hDlgWnd, 0 );return TRUE;   } }    }  }  return FALSE;}One of the big differences between DialogProc and WndProc that I remember is that DialogProc returns TRUE if a message was handled, and FALSE otherwise.  Hopefully this helps you out. 