4.21 如何使用ENTER键控制对话框中控件的输入焦点
将键盘转回Tab建
BOOL CDemoDlg::PreTranslateMessage(MSG* pMsg)
{
//将按键为ENTER的WM_KEYDOWN消息转换成按键为TAB的消息
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam == VK_RETURN)
{
pMsg->wParam = VK_TAB;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
4.22 如何屏蔽对话框按ESC或ENTER键退出
还是一样,直接返回TRUE,什么事情也不发生
BOOL CDemoDlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE)
{
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
4.23 如何设置应用程序中对话框的默认颜色
http://blog.163.com/wenxianliang08@126/blog/static/8358326320101020173473/
//设置对话框的默认颜色
SetDialogBkColor(RGB(0x99, 0xCC, 0xFF), RGB(0xFF, 0x00, 0x00));
4.24 如何创建消息对话框
即MessageBox,没啥好说的
void CDemoDlg::OnShowDlg1()
{
MessageBox(_T("MessageBox函数创建的消息对话框"),
_T("Demo"), MB_ICONEXCLAMATION);
}
void CDemoDlg::OnShowDlg2()
{
AfxMessageBox(_T("AfxMessageBox函数创建的消息对话框"));
}
4.25 如何实现对话框在桌面工作区的停靠
一种思想,当左右pos少于50的时候就更改pos
void CDemoDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
{
CDialog::OnWindowPosChanging(lpwndpos);
//获得桌面工作区大小
CRect rect;
SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0);
//左停靠
if (abs(lpwndpos->x - rect.left) <= 50)
{
lpwndpos->x = rect.left;
lpwndpos->y = rect.top;
lpwndpos->cy = rect.Height();
}
//右停靠
else if (abs(lpwndpos->x + lpwndpos->cx-rect.right) <= 50)
{
lpwndpos->x = rect.right - lpwndpos->cx;
lpwndpos->y = rect.top;
lpwndpos->cy = rect.Height();
}
else
{
lpwndpos->cy = m_nHeigh;
}
if (lpwndpos->y < rect.top)
{
lpwndpos->y = rect.top;
}
}