9、编写一个Windows应用程序,在窗口用户区中绘制一个矩形,用键盘上的上下左右光标键可以使该矩形分别向4

编写一个Windows应用程序,在窗口用户区中绘制一个矩形,用键盘上的上下左右光标键可以使该矩形分别向4个方向移动,当按下键盘上的Home键时该矩形会从左上角方向增大,当按下键盘上的End键时该矩形会从右下角方向缩小,当单击鼠标左键时该矩形会恢复原始尺寸。

控制台程序 还是 MFC ?

1. 如果是控制台程序,使用 GetAsyncKeyState 函数
我以前写个一个小程序,你可以参考一下

2. 如果是MFC程序,你需要在PreTranslateMessage(MSG* pMsg)中捕获按键的消息,然后设置焦点(SetFocus())。类似下面的样子:

BOOL CXXXDialog(or CXXXView)::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_KEYDOWN)
{
if(pMsg->wParam == VK_LEFT) {
//左键 .....

return CWnd::PreTranslateMessage(pMsg);
}
else if (pMsg->wParam == VK_RIGHT)
{
//右键.....

return CWnd::PreTranslateMessage(pMsg);
}
else if (pMsg->wParam == VK_UP)
{
//上键.....

return CWnd::PreTranslateMessage(pMsg);
}
else if (pMsg->wParam == VK_DOWN)
{
//下键.....

return CWnd::PreTranslateMessage(pMsg);
}
else if (pMsg->wParam == VK_TAB)
{
//Tab 键....

return CWnd::PreTranslateMessage(pMsg);
}
else if (pMsg->wParam == VK_ESCAPE)
{
//ESC 键....

return CWnd::PreTranslateMessage(pMsg);
}
else if(pMsg->wParam == VK_RETURN )
{
//回车键....

return CWnd::PreTranslateMessage(pMsg);
}
}
a
return CWnd::PreTranslateMessage(pMsg);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-05-09
请教导师吧
相似回答