#include <windows.h>
LONG WINAPI WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPreInstance,LPSTR lpszCmdLine,
int nCmdShow)
{
WNDCLASS wc;
HWND hwnd;
MSG msg;
BOOL bReg;
wc.style = 0;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = "FirstWindowClass";
RegisterClass(&wc);
hwnd = CreateWindow(
"FirstWindowClass",
"第一个windows应用程序",
WS_OVERLAPPEDWINDOW,
0,
0,
300,
400,
HWND_DESKTOP,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while ((bReg = GetMessage(&msg,NULL,0,0)) != 0)
{
if (bReg == -1)
{
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
PAINTSTRUCT pp;
HDC hdc;
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_LBUTTONDOWN://想在点击鼠标左键时绘制出 "Welcome",这样怎么做不到啊?
hdc=BeginPaint(hWnd,&pp);
RECT rr;
GetClientRect(hWnd,&rr);
DrawText(hdc,"Welcome",strlen("Welcome"),&rr,DT_CENTER);
EndPaint(hWnd,&pp);
return 0;
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
}