CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #8
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: RichEdit and SetSel when tabbing

    Indeed, for rich-edit control, VS6 Class Wizard shows both EN_SETFOCUS and NM_SETFOCUS in the list, although Rich-edit 1.0 which can be taken from VS6 toolbox, sends only EN_SETFOCUS (at least according to the documentation).
    Moreover, it maps both notifications using ON_NOTIFY macro, which is not correct.
    Let's take it as a little bug. If you still are using old VS6.0, then map manually the rich-edit control notifications. That's it.

    Beware of the message handlers prototype! VS6 performs C-style cast when uses function pointers involved in message mapping. If you manually provide a wrong prototype, let's say void OnSetfocusSomeCtrl(NMHDR* pNMHDR, LRESULT* pResult) the program compiles but may crash at run-time (it crashes for sure in release build). Newer versions of Visual Studio resolved this issue by making static_cast.

    Putting all together, including the advices of my colleagues, the following sample must compile, run and work with no problems:

    Code:
    class CMyDialog : public CDialog
    {
       // ...
       CRichEditCtrl m_richeditTest;
       // ...
       // ...
       afx_msg void OnSetfocusRichEditTest();
       DECLARE_MESSAGE_MAP()
    };
    Code:
    void CMyDialog::DoDataExchange(CDataExchange* pDX)
    {
       // ...
       // ...
       DDX_Control(pDX, IDC_RICHEDIT_TEST, m_richeditTest);
       //}}AFX_DATA_MAP
    }
       // ...
       // ...
       ON_EN_SETFOCUS(IDC_RICHEDIT_TEST, OnSetfocusRichEditTest)
    END_MESSAGE_MAP()
    
    void CMyDialog::OnSetfocusRichEditTest()
    {
       m_richeditTest.SetSel(0, 0);
    }
    Of course, must not forget to call AfxInitRichEdit in InitInstance of aplication (derived from CWinApp) class.
    Last edited by ovidiucucu; June 3rd, 2012 at 01:04 AM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured