<p>#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinSunProc(HWND , UINT , WPARAM, LPARAM );
</p><p>
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPreInst, LPSTR lpszCmdLine, int nCmdShow)
{ //定义的参数可以随意更改,要和系统宏定义和系统结构参数区分开来</p><p> //下面的也可以被改变的,如HINSTANCE hh,HINSTANCE xx,LPSTR cc,int dd</p><p> //当然改了以后在这个函数里面相对应的参数也许要改掉
HWND hwnd;
MSG msg;
WNDCLASS wcex;
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hbrBackground = (HBRUSH)(GetStockObject(WHITE_BRUSH));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hInstance = hInstance; //对应你上面定义的 HINSTANCE hInstance
wcex.lpfnWndProc = WinSunProc;//对应你声明的回调窗口函数,在上面: LRESULT CALLBACK WinSunProc()
wcex.lpszClassName = "winapp";
wcex.lpszMenuName = NULL;
if (!RegisterClass(&wcex))
{
MessageBeep(0);
return false;
}
hwnd = CreateWindow("winapp", "by 天天", WS_OVERLAPPEDWINDOW, 0, 0, 600, 400, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, SW_SHOWNORMAL);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;//这里的wParam,不能替换,因为它是MSG结构的成员,并不是下面那一行里面的,它接收的是MSG结构传递的参数
} //看到这个wParam还以为是下面的呢,不是的,不要试图把它改成和下面的一样,下面的可以改变但是它不能被改变</p><p>
LRESULT CALLBACK WinSunProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
{ //这里的hwnd、umsg、wParam、lParam可以随意替换为你想要更改改的值
//比如HWND hh,UINT uu,WPARAM ww,LPARAM pp </p><p> //当然改了以后在这个函数里面相对应的参数也许要改掉
switch (umsg)
{
case WM_LBUTTONDOWN:
MessageBox(hwnd, "mouse clicked", "message", 0);
HDC hdc;
hdc = GetDC(hwnd); //不能在响应WM_PAINT消息时调用
TextOut(hdc, 0, 50, "程序员之家", strlen("程序员之家"));
//ReleaseDC(hwnd,hdc);
break;
case WM_CHAR:
char szChar[20];
sprintf(szChar, "char code is %d", wParam);
MessageBox(hwnd, szChar, "char", 0);
break;
case WM_PAINT:
PAINTSTRUCT ps;
HDC hDC;
hDC = BeginPaint(hwnd, &ps);
TextOut(hDC,10,10, "有没有人曾告诉你!", strlen("有没有人曾告诉你"));
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);
break;
}
return 0;
}</p>