VC中对消息的特殊处理--PreTranslateMessage说明(转载) pretranslatemessage

(转载自:)http://blog.csdn.net/dengjiang1999/archive/2009/05/12/4170902.aspx

首先看看MSDN对PreTranslateMessage的说明

Override this function to filter window messages before they aredispatched to the Windows functions TranslateMessage andDispatchMessage The default implementation performs accelerator-keytranslation, so you must calltheCWinApp::PreTranslateMessagememberfunction in your overridden version.

virtual BOOL PreTranslateMessage(
MSG* pMsg
);

Parameters

pMsg

A pointer to a MSG structure that contains the message toprocess.

Return Value

Nonzero if the message was fully processedinPreTranslateMessageandshould not be processed further. Zero if the message should beprocessed in the normal way.

Requirements

Header:afxwin.h

------------------------------------------------------

再看看一个具体的例子.

BOOL MyDialog::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_KEYDOWN)
{
//Returnkey
if(pMsg->wParam == VK_RETURN )
{//若焦点在本页面上的一个名叫IDC_EDT_TEST_DATA_FILE的EditBox上,按回车键则焦点转移到下个控件
if(GetFocus() == GetDlgItem(IDC_EDT_TEST_DATA_FILE))
{

GetFocus()->GetNextWindow()->SetFocus();
returnTRUE;
}

//若焦点在本页面一个叫IDC_EDT_WAITTIME的EditBox上,按回车键时焦点转移到父窗口的IDC_BEXECUTE按钮上
elseif(GetFocus() == GetDlgItem(IDC_EDT_WAITTIME))
{
((CArithmeticExpressionDlg*)this->GetParent())->GetDlgItem(IDC_BEXECUTE)->SetFocus();
returnTRUE;
}
}

//[Shift] + [TAB]
elseif(GetKeyState(VK_SHIFT) & 0x8000&& pMsg->wParam ==VK_TAB)
{
//若焦点在本页面一个叫IDC_EDT_WAITTIME的EditBox上,Shift +TAB是,焦点跳到窗口名叫IDC_RBTN_STEP4的Radio Button上
if(pMsg->hwnd ==(GetDlgItem(IDC_EDT_TEST_DATA_FILE))->m_hWnd )
{
(((CArithmeticExpressionDlg*)this->GetParent())->GetDlgItem(IDC_RBTN_STEP4))->SetFocus();
returnTRUE;
}
}
VC中对消息的特殊处理--PreTranslateMessage说明(转载) pretranslatemessage
else if(pMsg->wParam == VK_TAB )
{
//[TAB]

//若焦点在本页面一个叫IDC_EDT_WAITTIME的EditBox上,TAB时焦点转移到父窗口的IDC_BEXECUTE按钮上
if(pMsg->hwnd ==GetDlgItem(IDC_EDT_WAITTIME)->GetSafeHwnd())
{
((CArithmeticExpressionDlg*)this->GetParent())->GetDlgItem(IDC_BEXECUTE)->SetFocus();
returnTRUE;
}
}
//Escapekey
else if(pMsg->wParam == VK_ESCAPE )
{
//按Esc键时,相当于按窗口上有的EXIT按钮.
CButton*pBtnExit =(CButton*)((CArithmeticExpressionDlg*)this->GetParent())->GetDlgItem(IDC_BEXIT);
::SendMessage(pBtnExit->GetSafeHwnd(),WM_LBUTTONDOWN,0,0);
::SendMessage(pBtnExit->GetSafeHwnd(),WM_LBUTTONUP,0,0);
returnTRUE;
}
//other events


}
//others

returnCDialog::PreTranslateMessage(pMsg);
}

本例子的功能就是在父子窗口之前实现焦点的转移.

例如,当焦点位于子窗口的最后一个控件时,此时接着操作TAB键,就要注焦点转移到父窗口中,并且是紧跟着子窗口的那个控件.

闻香止步 收集于:http://blog.csdn.net/roofwei/archive/2009/02/18/3906112.aspx

  

爱华网本文地址 » http://www.413yy.cn/a/25101017/359349.html

更多阅读

Word中对段落的对齐方式怎么设置 word如何段落对齐

Word中对段落的对齐方式怎么设置——简介一篇不错的文章,除了要有丰富和详细的内容之外,还要有漂亮和庄重的外观。这就需要我们对文章进行校对后的排版和修饰了,其次是进行文章段落格式的设置,那么怎么去区分段落呢,在Word中只要敲回车键

VC中获取文件的相对路径与绝对路径 vc 获取绝对路径

Ⅰ、获取相对路径如果当前打开的文件中要寻找同级的目录文件就要用到 .或者 ./ VC编译器都可以识别。例如#define ".XXXXxx.h"如果当前打开的文件中要寻找在上级的目录文件就要用到 .. 或者 ../ VC编译器都可以识别。例如#define "..

声明:《VC中对消息的特殊处理--PreTranslateMessage说明(转载) pretranslatemessage》为网友绿水无忧分享!如侵犯到您的合法权益请联系我们删除