Code reuse by handling CEdit ON_WM_SETFOCUS handler
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Code reuse by handling CEdit ON_WM_SETFOCUS handler

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Posts
    508

    Code reuse by handling CEdit ON_WM_SETFOCUS handler

    In my application I need to to bring up a keyboard dialog when a user clicks any of the edit boxes in the application. Therefore I have OnSetFocus() implemented in all over the application (dialogs) which brings up the keybaord in each of them (which is just another dialog).

    I would rather subclass the CEdit control and implement SetFocus() in it and use this class to lend this behavior automatically to all the edit boxes I am using in the application. The problem is that the keyboard dialog is really part of the end dialog, more accurately part of the base class of the end dialog which has the following class hierarchy.
    Code:
    CDialog
    CDialogEx - it implements ShowKeyboard()
    CMyDialog - it calls the base ShowKeyboard() to bring up the dialog in OnSetFocus()
    The problem is how can I access the ShowKeyboard() function from the underlying dialog while overriding CEdit::OnSetFocus()? Thanks.

  2. #2
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,011

    Re: Code reuse by handling CEdit ON_WM_SETFOCUS handler

    Quote Originally Posted by zspirit View Post
    The problem is how can I access the ShowKeyboard() function from the underlying dialog while overriding CEdit::OnSetFocus()? Thanks.
    Maybe you can send a notification message to the parent from your CEdit-derived class. Then in CDialogEx you can handle the notification message.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  3. #3
    Join Date
    May 1999
    Location
    DELAWARE, USA
    Posts
    9,915

    Re: Code reuse by handling CEdit ON_WM_SETFOCUS handler

    First of all: do not subclass your control using CEdit class. Derive your own from CEdit and then subclass the control.
    Secondly, CDialogEx does not implement ShowKeyboard function unless you are using older VS version.
    MFC starting with VS 2008 already have CDialogEx, so I assume you are working with VS 2005 or earlier.

    Another thing: since this requirement is edit control specific, why don’t you implement ShowKeyboard in your from CEdit derived class and use this class in all projects you need this functionality. Your dialog class does not event have to know about a need for showing a keyboard.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center