发表于:2006-07-09 17:01:00
楼主
在vc的对话框中想使用WM_KEYDOWN消息函数来移动屏幕上所画的直线,代码如下:
void CMouseDrDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
switch(nChar)
{
case 'VK_LEFT':nPoint[1].x--;
SendMessage(WM_PAINT);
break;
case VK_RIGHT:nPoint[1].x++;
SendMessage(WM_PAINT);
break;
}
CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}
按左箭头和右箭头键怎么均没反应,后又增加了PreTranslateMessage()函数:
BOOL CMouseDrDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message == WM_KEYDOWN)
{
PostMessage(WM_KEYDOWN);
}
return CDialog::PreTranslateMessage(pMsg);
}
还是没反应,该怎么办?