24,854
社区成员
发帖
与我相关
我的任务
分享
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK Replace(
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.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_CROSS);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=Replace;
wndclass.lpszClassName="wangchu";
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW||CS_VREDRAW;
RegisterClass(&wndclass);
HWND hwnd;
hwnd=CreateWindow("wangchu","wangchu",WS_OVERLAPPEDWINDOW,100,100,400,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;
}
LRESULT CALLBACK Replace(
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,"输入的字母是%S",wParam);
MessageBox(hwnd,szChar,"YES?",MB_OK);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"wangchu","YES?",MB_OK);
HDC hdc1;
hdc1=GetDC(hwnd);
TextOut(hdc1,0,50,"wangchu",strlen("wangchu"));
ReleaseDC(hwnd,hdc1);
break;
case WM_PAINT:
HDC hdc2;
PAINTSTRUCT ps;
hdc2=BeginPaint(hwnd,&ps);
TextOut(hdc2,0,100,"wangchu",strlen("wangchu"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"YES?","wangchu",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}