- 这是MFC课上的内容,理解窗口程序很重要
#include <windows.h>
#include <iostream>
using namespace std;
#define APPNAME "MFC_Lession"
#define GUINAME "MFC_GUI"
LRESULT CALLBACK MyProc(HWND hwnd ,
UINT uMsg,
WPARAM wParam,
LPARAM lParam);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
/************************************************************************/
/************************************************************************/
WNDCLASS wcls;
wcls.cbClsExtra = 0;
wcls.cbWndExtra = 0;
wcls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wcls.hIcon = LoadIcon(hInstance, IDI_WARNING);
wcls.hCursor = LoadCursor(hInstance, IDC_CROSS);
wcls.hInstance = hInstance;
wcls.lpfnWndProc = MyProc;
wcls.lpszClassName = APPNAME;
wcls.lpszMenuName = NULL;
wcls.style = CS_VREDRAW|CS_HREDRAW;
/************************************************************************/
/************************************************************************/
RegisterClass(&wcls);
/************************************************************************/
/************************************************************************/
HWND hwd;
hwd = CreateWindow(APPNAME, GUINAME, WS_OVERLAPPEDWINDOW, 200, 200, 400, 400, NULL, NULL, hInstance, NULL);
ShowWindow(hwd,SW_SHOWNORMAL);
UpdateWindow(hwd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK MyProc(
HWND hwnd ,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch(uMsg)
{
case WM_PAINT:
HDC dc;
PAINTSTRUCT ps ;
dc = BeginPaint(hwnd,&ps);
TextOut(dc,100,100,"haha",strlen("haha"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if (IDYES == MessageBox(hwnd, "是否真的结束?", "message", MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}