VC6.0でのメッセージの特殊な処理--PreTranslateMessageの説明



まずMSDNのPreTranslateMessageの説明を見てみましょう
 
 
Override this function to filter window messages before they are dispatched to the Windows functions TranslateMessage and DispatchMessage The default implementation performs accelerator-key translation, so you must call the CWinApp::PreTranslateMessage member function in your overridden version.
 
virtual BOOL PreTranslateMessage(
MSG* pMsg
);

Parameters


pMsg
A pointer to a MSG structure that contains the message to process.

Return Value


Nonzero if the message was fully processed in PreTranslateMessage and should not be processed further. Zero if the message should be processed 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()==GetDlgIt( IDC_EDT_TET_TET_TETE_TETE_TEE_FILEのEditBoxにフォーカスが移行し、リタキーを押すと次のコントロールif(GetFocus()==GetDlST_DATA_FILE)){                                GetFocus()->GetNextWindow()->SetFocus();                return TRUE;            }
//このページにフォーカスがある場合はIDCと言います.EDT_WAITTIMEのEditBoxで、リターンキーを押すと親ウィンドウのIDC_にフォーカスが移りますBEXECUTEボタン上のelse if(GetFocus()==GetDlgItem(IDC_EDT_WAITTIME){(CArithmeticExpressionDlg*)this->GetParent()->GetDlgItem(IDC_BEXECUTE)->SetFocus();return TRUE;            }        }
       //[Shift] + [TAB]        else if(GetKeyState(VK_SHIFT) & 0x8000 && pMsg->wParam == VK_TAB){//このページのIDC_EDT_WAITTIMEというEditBoxに焦点が当てられている場合、Shift+TABは、IDC_RBTN_STEP 4というウィンドウ名のRadio Button上if(pMsg->hwnd=(GetDlgItem(IDC_EDT_TEST_DATA_FILE)-> m_hWnd){((CArithmeticExpressionDlg*)->this GetParent()->GetDlgItem(IDC_RBTN_STEP 4))->SetFocus();                return TRUE;            }        }        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();return TRUE;}//Escape key 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);            return TRUE;        }       //other events
       /*********************some other code***************************/          }   //others    return CDialog::PreTranslateMessage(pMsg);}
 
本例の機能は、親子ウィンドウの前にフォーカスの移行を実現することである.
例えば、フォーカスがサブウィンドウの最後のコントロールにある場合、TABキーを操作すると、親ウィンドウにフォーカスが移行し、サブウィンドウに続くコントロールとなる.
 
 
香りを嗅ぐのは立ち止まって収集します:http://blog.csdn.net/roofwei/archive/2009/02/18/3906112.aspx淘宝店摆件饰品*木彫りシリーズ*:海南黄花梨、ベトナム黄花梨、草花梨、小葉紫檀、黒檀、緑檀木、黄楊木、桃木髪かんざし木櫛樟木壁掛仏珠車飾摆件
http://shop36570193.taobao.com
友达、暇があったら见に来て、好きな友达はコレクションしてください