HELP: Grabbing CTRL-TAB keystroke in a dialog box
Jeff Thompson -- thompson@in.net Thursday, June 20, 1996 Environment: MSVC 1.5, WINNT 4.0 BETA2 I was wondering if anybody knows how to do this: I need to intercept the CTRL-TAB keystroke in a dialog box... I'm trying to implement a dynamic dialog and switch between sub-dialogs with the CTRL-TAB key. I can't use the MFC Tab Dialogs (since MSVC 1.5 doesn't have them). I've tried adding OnChar, OnCommand, OnSysChar, OnSysCommand handlers but none of them ever get called... What am I doing wrong or what do I need to do? Thanks!
MICHAEL@datatree.com Saturday, June 22, 1996 [Mini-digest: 3 responses] Subclass your dialog controls. Here is how I subclassed a single line edit control using VC++ 4.1. I believe VC++ 1.52 is compatible. MYDIALOG.H --------------------- CMyEdit m_cpyEdt; MYDIALOG.CPP ------------------------- BOOL CMyDialog::OnInitDialog() { m_cpyEdt.SubclassDlgItem(IDC_COPIES, this); // Update from member variables to controls CDialog::OnInitDialog(); return TRUE; } // CCPYEdt Subclass for trapping tab and enter keys CCPYEdt::CCPYEdt() { } BEGIN_MESSAGE_MAP(CCPYEdt, CEdit) //{{AFX_MSG_MAP(CCPYEdt) ON_WM_GETDLGCODE() ON_WM_KEYDOWN() //}}AFX_MSG_MAP END_MESSAGE_MAP() // CCPYEdt message handlers UINT CCPYEdt::OnGetDlgCode() { return DLGC_WANTALLKEYS | DLGC_HASSETSEL; } void CCPYEdt::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { if (nChar == VK_TAB && GetKeyState(VK_SHIFT) & KF_UP) { // Process Shift+Tab keys MessageBeep(0); // Do nothing - sample code } else if (nChar == VK_RETURN) { // Process Enter key MessageBeep(0); // Do nothing - sample code } else if (nChar == VK_TAB) { // Process Tab key MessageBeep(0); // Do nothing - sample code } CEdit::OnKeyDown(nChar, nRepCnt, nFlags); } Michael L. Thal Data Tree Corporation voice: (619) 231-3300 fax: (619) 231-3301 -----From: jimt1@voicenet.com (Jim Tannenbaum) A quick and dirty solution is to use a VBX control (Borland's Visual Solution Pack or WinWidgets from Lifeboat) that provide Tab Dialog Box controls. I've used WinWidgets with mixed results. I was able to design with their control, but I had work arround selecting a tab that was not the left-most tab when I first initialized the dialog box. Borland supplies third party VBX controls that work with either Borland 4.5 or MS VC 1.52. Good Luck, Jet JJM Systems, Inc Phone: (215) 672-3660 1 Ivybrook Blvd, Suite 190 Fax: (215) 672-5702 Ivyland, PA 19874 Net: jimt1@voicenet.com -----From: funduc@sprynet.com If you were to use 4.0, you could just override PreTranslateMessage(). The problem is, in 1.5 we don't have access to the Dialog's proc. That's why PreTranslateMessage is not called and neither are the handlers you mention! The best way, would be to write it with MFC 4.1 but that's not an option is it? I guess in 1.5, you could subclass your controls, resopond to OnGetDlgCode with the base class return or-ed with DLGC_WANTTABS. Yuk! You can then send a custom WM_COMMAND with WM_USER+something to your parent(the dialog) when you see that key and handle it there. You may then have to make sure you don't break standard dialog box TAB key handling (if the control key is not pressed). In other words, set the focus from one control to the next yourself (don't forget Shift+TAB)! Perhaps another good idea would be to pick another key combination! I've done something similar to catch the VK_RETURN key once (I had to return DLGC_DEFPUSHBUTTON for edit fields) and believe me I'm not proud of it. This really makes your code hard to maintain since you have to subclass every control in the dialog (use the class Wizard and then modify the class names in the header) but it will do the job. If you find a better way, let me know. Hope this helps. Mike Funduc Funduc Software Inc. funduc@sprynet.com 102372.2530@compuserve.com http://home.sprynet.com/sprynet/funduc http://ourworld.compuserve.com/homepages/funduc
| Вернуться в корень Архива |