Delete the system automatically generated code, copy the code below to engineering,
# include "stdafx. H"
# include "testdlg. H"
# define MAX_LOADSTRING 100
//global variables:
HINSTANCE hInst,//the current instance
TCHAR szTitle [MAX_LOADSTRING];//title bar text
TCHAR szWindowClass [MAX_LOADSTRING];//the main window class name
BOOL InitInstance (HINSTANCE, int);
INT_PTR CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About (HWND, UINT, WPARAM, LPARAM);
Int APIENTRY _tWinMain (HINSTANCE HINSTANCE,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
Int nCmdShow)
{
UNREFERENCED_PARAMETER (hPrevInstance);
UNREFERENCED_PARAMETER (lpCmdLine);
MSG MSG.
if (! InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
//the main message loop:
While (GetMessage (& amp; MSG, NULL, 0, 0))
{
if (! IsDialogMessage (HWND. MSG., & amp; MSG))
{
TranslateMessage (& amp; MSG);
DispatchMessage (& amp; MSG);
}
}
Return (int) MSG. WParam;
}
BOOL InitInstance (HINSTANCE HINSTANCE, int nCmdShow)
{
The HWND HWND;
HInst=hInstance;//handle to the instance is stored in the global variable
HWnd=CreateDialog (hInstance, MAKEINTRESOURCE (IDD_DIALOG1), NULL, WndProc);
if (! HWnd)
{
return FALSE;
}
ShowWindow (hWnd, nCmdShow);
UpdateWindow (hWnd);
return TRUE;
}
INT_PTR CALLBACK WndProc (HWND HWND, UINT message, WPARAM WPARAM, LPARAM LPARAM)
{
Int wmId wmEvent;
PAINTSTRUCT ps;
HDC HDC.
The switch (the message)
{
Case WM_COMMAND:
WmId=LOWORD (wParam);
WmEvent=HIWORD (wParam);
//analysis menu choice:
The switch (wmId)
{
Case IDOK:
MessageBox (hWnd, _T (" cannot close!" ), _T (" blue "), MB_OK);
break;
Case IDCANCEL:
The DestroyWindow (hWnd);
break;
Default:
Return DefWindowProc (hWnd, message, wParam, lParam);
}
break;
In case the WM_PAINT:
HDC=BeginPaint (hWnd, & amp; Ps);
//TODO: add any in this drawing code...
EndPaint (hWnd, & amp; Ps);
break;
Case WM_DESTROY:
The PostQuitMessage (0);
break;
Default:
Return DefWindowProc (hWnd, message, wParam, lParam);
}
return 0;
}
CodePudding user response:
CreateDialog with independent WndProcReference App wizard generated Hello word About
CodePudding user response:
default:
//return DefWindowProc (hWnd, message, wParam, lParam);
break;