该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
LPCTSTR lpszAppName=TEXT("MyApp");
LPCTSTR lpszTitle=TEXT("My Application");
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow)
{
MSG msg;
HWND hWnd;
WNDCLASS wc;
//注册主应用程序的窗口类
wc.style=CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc=(WNDPROC)WndProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName=lpszAppName;
wc.lpszClassName=lpszAppName;
if(!RegisterClass(&wc))
return (FALSE);
//创建主应用程序的窗口
hWnd=CreateWindow(lpszAppName,lpszTitle,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,0,CW_USEDEFAULT,0,NULL,NULL,hInstance,NULL);
if(!hWnd)
return (FALSE);
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (msg.wParam);
}
//窗口过程函数
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
RECT rect;
HDC hdc;
PAINTSTRUCT ps;
static int uRed=0,uGreen=0,uBlue=0;
switch(uMsg)
{
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
GetClientRect(hWnd,&rect);
SetTextColor(hdc,RGB(uRed,uGreen,uBlue));
DrawText (hdc,TEXT("Hello,You Are Welcome!"),-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
EndPaint(hWnd,&ps);
break;
case WM_KEYDOWN:
uRed=rand() % 255;
uGreen=rand() % 255;
uBlue=rand() % 255;
InvalidateRect(hWnd,NULL,TRUE);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
return (0L);
}