none
MFC Property sheet Dialog RRS feed

  • Question

  • How to add tabbing functionality (means using tab key control should move to next item in the dialog) in mfc Property sheet dialog.

    Please help



    Friday, May 24, 2019 11:26 AM

All replies

  • You can see this thread
    Friday, May 24, 2019 11:37 AM
  • Initially you asked about modeless dialogs.

    Subsequently, you changed the question to ask about property sheets.

    You can obtain an MFC Property Sheet demo at https://github.com/microsoft/VCSamples/tree/master/VC2010Samples/MFC/Visual%20C%2B%2B%202008%20Feature%20Pack/PropSheetDemo

    Friday, May 24, 2019 12:37 PM
  • Hi,

    Thank you for posting here.

    >>How to add tabbing functionality (means using tab key control should move to next item in the dialog) in mfc Property sheet dialog.

    You could try to Overload the virtual function PreTranslateMessage. PreTranslateMessage is a virtual member function that is called in order to give your control a chance to do something before (or instead of) the default behavior of the control. Therefore, in this function, we check to see if the message being sent is a WM_KEYDOWN message (indicating that the user has pressed some key). We determine if the key being pressed is the Tab key (whose id is VK_TAB). And then we could capture the TAB key and specify the focus jump.

    Best Regards,

    Jeanine Zhang
    Monday, May 27, 2019 3:02 AM
    Moderator
  • Thanks for your suggestion, but I'm new to MFC so don't know how to overload PreTranslateMessage function.It will be great if you suggest any tutorial or demo for this  
    Monday, May 27, 2019 6:03 AM
  • Hi,

    >>how to overload PreTranslateMessage function

    You should right click on the project and select "class wizard"-> "Virtual Functions" -> "PreTranslateMessage"

    Here is the code:

    BOOL CMFCPropSheetDemoDlg::PreTranslateMessage(MSG* pMsg)
    {
    	// TODO: Add your specialized code here and/or call the base class
    
    	if ((pMsg->message == WM_KEYDOWN) && (VK_TAB == (int)pMsg->wParam)
    	{
    		CWnd *mwnd = GetFocus();
    			if (NULL != mwnd)
    			{
    				if (mwnd == GetDlgItem(IDC_AAA))
    				{
    					GetDlgItem(IDC_BBB)->SetFocus();
    						return TRUE;
    				}
    			
    				
    			}
    	}
    
    	
    	return CDialogEx::PreTranslateMessage(pMsg);
    }
    

    Best Regards,

    Jeanine Zhang
    Monday, May 27, 2019 7:29 AM
    Moderator
  • Hi,

    Thanks for code snippet. I Added PreTranslateMessage function through class wizard and also paste your code inside that function.but nothing is happening on pressing tab key.Also breakpoint inside that function is not hitting.Can you please tell what went wrong? 

    Here is what I have tried - 

    Header File contains - 
    class CNGUniformMomentPage : public CNGPropertyPage
    {
     protected:
            virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
            //}}AFX_VIRTUAL
    
        // Implementation
        protected:
            // Generated message map functions
            //{{AFX_MSG(CNGUniformMomentPage)
            virtual BOOL OnInitDialog();
            afx_msg void OnClickedDirection();
            afx_msg void OnChangeD1();
            afx_msg void OnChangeD2();
            afx_msg void OnChangeD3();
            afx_msg void OnChangeW1();
            //}}AFX_MSG
            DECLARE_MESSAGE_MAP()
        protected:
            void ReflectChanges();
        private:
            bool m_bUpdate;
        public:
            void Initialize();
    		virtual BOOL PreTranslateMessage(MSG* pMsg);
    };
    
    Source File Contains - 
    
    BOOL CNGUniformMomentPage::PreTranslateMessage(MSG* pMsg)
    {
    	// TODO: Add your specialized code here and/or call the base class
    	if ((pMsg->message == WM_KEYDOWN) && (VK_TAB == (int)pMsg->wParam))
    	{
    		CWnd *mwnd = GetFocus();
    		if (NULL != mwnd)
    		{
    			if (mwnd == GetDlgItem(IDC_W1))
    			{
    				GetDlgItem(IDC_D1)->SetFocus();
    				return TRUE;
    			}
    
    
    		}
    
    	}
    	return CNGPropertyPage::PreTranslateMessage(pMsg);
    }
    I'm working on modeless property sheet so is that causing a problem?



    Monday, May 27, 2019 9:49 AM
  • You can obtain an MFC Property Sheet demo at

    Thanks for demo application but need tabbing functionality in modeless property sheet.
    Monday, May 27, 2019 12:15 PM
  • You can obtain an MFC Property Sheet demo at

    Thanks for demo application but need tabbing functionality in modeless property sheet.

    For example, in the PropSheetDemo sample use Class Wizard to add the following virtual function override to the CMyPropertySheet class -

    void CMyPropertySheet::PostNcDestroy()
    {
    	// TODO: Add your specialized code here and/or call the base class
    
    	CMFCPropertySheet::PostNcDestroy();
    
    	if (IsModeless())
    		delete this;
    }
    

    In the sample's PropSheetDemoDlg.cpp file make the following change -

    void CPropSheetDemoDlg::OnPropSheet1()
    {
    	UpdateData();
    
    	CMyPropertySheet *pPropSheet = new CMyPropertySheet(CMFCPropertySheet::PropSheetLook_Tabs);
    
    	pPropSheet->EnablePageHeader(m_bHeader ? HEADER_HEIGHT : 0);
    	//pPropSheet->DoModal();
    
    	pPropSheet->Create(this);
    
    	//delete pPropSheet;
    }
    
    When you run the demo and display the simple property sheet it will be modeless.  If you place controls on property pages the tab key will navigate between the controls.

    Monday, May 27, 2019 12:45 PM
  • When you run the demo and display the simple property sheet it will be modeless.  If you place controls on property pages the tab key will navigate between the controls.

       Made changes in your demo app and run it and it's working.I was wondering, you only made your property sheet Modeless and still tabbing functionality is working but why it's not working in my case?
    Monday, May 27, 2019 1:49 PM
  • When you run the demo and display the simple property sheet it will be modeless.  If you place controls on property pages the tab key will navigate between the controls.

       Made changes in your demo app and run it and it's working.I was wondering, you only made your property sheet Modeless and still tabbing functionality is working but why it's not working in my case?

    Sorry, but I don't know what "your case" is or is not doing.

    Monday, May 27, 2019 1:57 PM