switch(uMsg)出问题
发布网友
发布时间:2022-04-30 04:51
我来回答
共1个回答
热心网友
时间:2023-10-14 04:05
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hprevIstance,
LPSTR lpCmdLine,
int nCmdshow)
{
WNDCLASS wndcls ;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.style=CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hInstance=hInstance;
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.lpszMenuName=NULL;
wndcls.lpszClassName="WG";
wndcls.lpfnWndProc=(WNDPROC)WindowProc;
RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("WG","欢迎你来参观",WS_OVERLAPPEDWINDOW,0,0 ,400,600,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_RESTORE);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
return 0;
}
return msg.wParam ;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
HDC hdc;
switch(message)
{
case WM_CHAR:
char achar[20];
sprintf(achar,"wu wie ni hao %d",wParam);
MessageBox(hwnd,achar,"wuwei",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"ni ta made ","wuwei",0);
hdc=GetDC(hwnd);
TextOut(hdc,0,60,"LDH",strlen("LDH"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT :
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,0,60,"WG",strlen("WG"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"你是否结束?","wuwei",MB_YESNO))
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message, wParam,lParam );
}
return 0;
}
热心网友
时间:2023-10-14 04:05
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hprevIstance,
LPSTR lpCmdLine,
int nCmdshow)
{
WNDCLASS wndcls ;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.style=CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hInstance=hInstance;
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.lpszMenuName=NULL;
wndcls.lpszClassName="WG";
wndcls.lpfnWndProc=(WNDPROC)WindowProc;
RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("WG","欢迎你来参观",WS_OVERLAPPEDWINDOW,0,0 ,400,600,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_RESTORE);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
return 0;
}
return msg.wParam ;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
HDC hdc;
switch(message)
{
case WM_CHAR:
char achar[20];
sprintf(achar,"wu wie ni hao %d",wParam);
MessageBox(hwnd,achar,"wuwei",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"ni ta made ","wuwei",0);
hdc=GetDC(hwnd);
TextOut(hdc,0,60,"LDH",strlen("LDH"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT :
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,0,60,"WG",strlen("WG"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"你是否结束?","wuwei",MB_YESNO))
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message, wParam,lParam );
}
return 0;
}