-
December 17th, 2012, 10:18 AM
#1
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.
-
December 17th, 2012, 11:19 AM
#2
Re: Code reuse by handling CEdit ON_WM_SETFOCUS handler
Originally Posted by zspirit
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
-
January 3rd, 2013, 06:01 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|