我在程序中加了WM_CHAR消息,为什么收不到WM_CHAR消息?这是为什么?

来源:百度知道 编辑:UC知道 时间:2024/06/06 20:59:08
我在程序中加了WM_CHAR消息,为什么收不到WM_CHAR消息?这是为什么?

不需要发送WM_CHAR消息,操作系统自动的为键盘产生WM_CHAR消息.
你所要做的只是用类向导,建立WM_CHAR的消息响应函数(也就是你所说的,收消息!)
======================
当然你也可以手工收消息.就象下面一样!
=======================

MSG Msg;

while(GetMessage(&Msg,0,0,0))
{TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
long WINAPI WndProc(HWND hWnd,UINT iMessage,UINT wParam,LONG lParam)
{
HDC hDC;
// HBRUSH hBrush;
HPEN hPen;
PAINTSTRUCT PtStr;
switch(iMessage)
{
case WM_PAINT:
hDC=BeginPaint(hWnd,&PtStr);
SetMapMode(hDC,MM_ANISOTROPIC);
hPen=(HPEN)GetStockObject(DKGRAY_BRUSH);
SelectObject(hDC,hPen);
// SelectObject(hDC,hBrush);
Ellipse(hDC,250,150,300,250);
// Ellipse(hDC,400,400,200,200);
EndPaint(hWnd,&PtStr);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd,iMessage,wParam,lParam);
}