16,548
社区成员




# include<windows.h>
# include<stdio.h>
LRESULT CALLBACK WindowLiProc(WNDPROC lpPrevWndFunc,
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_WINLOGO);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WindowLiProc;
wndcls.lpszClassName="CheersLi01";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("CheersLi01","Cheers Li Api 学习",WS_OVERLAPPEDWINDOW,0,0,800,600,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
WindowLiProc(WNDPROC lpPrevWndFunc,
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch(uMsg)
{
case WM_CHAR :
char szChar[20];
sprintf(szChar,"Char is %d",wParam);
MessageBox(hwnd,szChar,"CheersLi01",0);
break;
case WM_LBUTTONDOWN :
MessageBox(hwnd,"mouse click","CheersLi01",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"我的C++学习",ARRAYSIZE("我的C++学习"));
ReleaseDC(hwnd,hdc);
case WM_PAINT :
HDC hDc;
PAINTSTRUCT ps;
hDc=BeginPaint(hwnd,&ps);
TextOut(hDc,0,50,"C++ Programming",ARRAYSIZE("C++ Programming"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE :
if(IDYES==MessageBox(hwnd,"是否真的结束?","Hints for you",0))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY :
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}