我在程序中加了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);
}
return 0;
}
你所要做的只是用类向导,建立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);
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询