Original published in [http://community.9cbs.net/expert/topicview2.asp?id=3072485]
ActiveX control problem with a sub-window, how to get the Enter key?
problem:
Create a new MFC ActiveX project, add a dialogue resource, there are some standard controls, such as buttons, editing boxes, etc., and generate a class CCTRLPANEL. In the cxxxctrl class: int CXXXXCTRL :: OnCreate (lpcreatestruct lpcreatestruct) {if (ColeControl :: oncreate (lpcreateStruct) == -1) Return -1;
m_ctrlPanel.create (IDD_CTRLPANEL, this); // m_ctrlpanel is stated in .h file is: cctrlPanel m_ctrlPanel; onactivateInplace (true, null); return 0;}
In this way, it is true that the interface-based ActiveX control is used, which is used in the web page, the child window of the control is the cctrlPanel class less than the TAB key, the Enter key and the arrow keys, so that the control is very unprofessional ( For example, the user entered the content in an edit box, and the carriageway wants to indicate that the default button, but can not be implemented), and then I found that these buttons were intercepted by the cxxxctrl class! So I just added the following code: BOOL CSluiceCtrl :: PretranslateMessage (MSG * PMSG) {if (pmsg-> message == wm_keydown) {if (PMSG-> wparam == vk_tab || PMSG-> wparam == vk_return | | pMsg-> wParam == VK_LEFT || pMsg-> wParam == VK_RIGHT) {m_CtrlPanel.SendMessage (pMsg-> message, pMsg-> wParam, pMsg-> lParam); return TRUE;}} return COleControl :: PreTranslateMessage ( PMSG);} But the result proves that I think too much, but I don't understand why I don't understand why? Please advise! Also want to ask the master, how should this problem solve? I also tried it even the most extreme method, as follows: BOOL CSluiceCtrl :: PretranslateMessage (MSG * PMSG) {m_ctrlPanel.sendMessage (PMSG-> Message, PMSG-> WPARAM, PMSG-> lparam); Return True;} A:
PretranslateMessage depends on the MFC message loop. If the message loop of the container is not MFC, then PretranslateMessage will not be called. Int cwinapp :: run () {?? for (;;) {while (! :: peekmessage (& m_msgcur, ...) {if (! Onidle (...)) // do some iDle work break; } // i Have a message, or else no IDle work to do: // pump it if (! PumpMessage ()) Break;} return exitInstance ();} Bool cwinapp :: pumpMPMESSAGE () {?? Ration (! :: GetMessage (& m_msgCur, ...)) {return FALSE;} if (PreTranslateMessage (& m_msgCur!)) {:: TranslateMessage (& m_msgCur); :: DispatchMessage (& m_msgCur);} return TRUE;} BOOL CWinApp :: PreTranslateMessage ( MSG * PMSG) {for (PWND = / * window That Sent MSG * /; PWND; PWND = PWND-> getParent ()) ife (PWND-> PretranslateMessage (PMSG)) Return True; if (PMainWnd = / * Main Frame And it's not one of the parents * /) ife (PMainWnd-> PretranslateMessage (PMSG)) Return True;
Return false; // not handled}
The corresponding keyboard processing of the MFC dialog relies on the MFC message loop.
Bool CDialog :: PretranslateMessage (MSG * PMSG) {IF (PMSG-> Message> = WM_KEYFIRST && // for Performance Pmsg-> Message <= WM_KEYLAST)
// Maybe Translate Dialog Key Return :: IsdialogMessage (M_HWND, PMSG);
Return false;}
If the message loop of the container does not call IsDialogMessage, the corresponding keyboard processing will not be called.
The solution is to use hook to get the required keyboard input, and then forward to the dialog. See PRB: MODELESS DIALOG BOX IN A DLL DoES Not Process Tab Key (233263) Reference Document PRB: Modeless Dialog Box in A DLL Does Not Process Tab Key (233263) http://support.microsoft.com/default.aspx?kbid = 233263
FAQ: WebBrowser Keystroke ProblemShttp://www.microsoft.com/mind/0499/faq/faq0499.asp
Meandering Through the Maze of MFC Message and Command Routing http://www.microsoft.com/msj/0795/dilascia/dilascia.aspxC Q & A: Enabling Menus in MFC Apps, Changing the Behavior of Enter with DLGKEYS Sample App - MSDN Magazine , July 2000Http: //msdn.microsoft.com/msdnmag/issues/0700/c/default.aspx