15,978
社区成员
发帖
与我相关
我的任务
分享
#include"winuser.h"
#include"stdio.h"
#include"windows.h"
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackgrourd=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndclass.style=CS_VREDRAW|CS_HREDRAW;
wndclass.hIcon=LoadIcon(NULL,IDI_ERROR);
wndclass.hCursor=LoadCursor(NULL,IDC_CROSS);
wndclass.hInstance=Instance;
wndclass.wndProc=WinSonProc;
wndclass.lpszClassName="lesson1";
wndclass.lpszMenuName=NULL;
Register(&wndclass);
HWND hwnd;
hwnd=CreateWindow("lesson1","yanglinwei",WS_OVERLAPPEDWINDOW,0,0,500,600,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,hwnd,0,0))
{ TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char is %d",wParam);
MessageBox(hwnd,szChar,"lesson1",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse click","lesson1",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,20,40,"i love you",strlen("i love you"));
Release(hwnd,hdc);
break;
case WM_PAINT:
HDC hdc;
PAINTSTUCT ps;
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,30,40,"i love you",strlen("i love you"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwdn,"是否真的关闭?","yanglinwei",MB_YESNO))
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}