From: JY on
Hi,
I'm using a CRichEditCtrl control in a dialog. I've added a data member and
verified that the control is correctly associated with the member in
DoDataExchange() using DDX_Control().

In the application's InitInstance() I've also called AfxInitRichEdit2() as
needed for RichEditCtrl initialization. The problem is that the control has a
NULL handle at runtime if I do not call the Create method. If I do call the
Create() method (In OnIntDialog), it creates another control placed on top of
the original one at run time. My question is how do I use the control by
placing it in the dialog template without having to explicitly call the
create method ? (Another problem with the create is that I need to specify
the size in a rect member, and this is not very accurate with what I want).

TIA,
JY
From: AliR on
Double check your ID in DDX_Control. The rich edit control works the same
way as any other control when it comes to subclassing.

You can set a break point on the DDX_Control call and step into it to see
why it is not subclassing the control on the dialog template.

A Rebuild all might help if you have id mismatches or something.

AliR.

"JY" <sd(a)nospamgroup.com> wrote in message
news:93CAEB0E-8D3B-487C-A231-F3EE00D7CC81(a)microsoft.com...
> Hi,
> I'm using a CRichEditCtrl control in a dialog. I've added a data member
> and
> verified that the control is correctly associated with the member in
> DoDataExchange() using DDX_Control().
>
> In the application's InitInstance() I've also called AfxInitRichEdit2() as
> needed for RichEditCtrl initialization. The problem is that the control
> has a
> NULL handle at runtime if I do not call the Create method. If I do call
> the
> Create() method (In OnIntDialog), it creates another control placed on top
> of
> the original one at run time. My question is how do I use the control by
> placing it in the dialog template without having to explicitly call the
> create method ? (Another problem with the create is that I need to specify
> the size in a rect member, and this is not very accurate with what I
> want).
>
> TIA,
> JY


From: JY on
"AliR" wrote:

> Double check your ID in DDX_Control. The rich edit control works the same
> way as any other control when it comes to subclassing.
>
> You can set a break point on the DDX_Control call and step into it to see
> why it is not subclassing the control on the dialog template.
>
> A Rebuild all might help if you have id mismatches or something.
>
> AliR.
>
I just found that this is a problem with any control variable I add to the
dialog - it is actually a Property Page. If I add a control to the dialog
template, add a member variable for it, and try to use it in the class later,
it throws an exception with a NULL handle value. I've done a rebuild and
checked the names of the variables. I have to dynamically create all controls
- not sure what could be going wrong.
Appreciate any help.

TIA,
JY
From: Stephen Myers on
JY wrote:
> "AliR" wrote:
>
>> Double check your ID in DDX_Control. The rich edit control works the same
>> way as any other control when it comes to subclassing.
>>
>> You can set a break point on the DDX_Control call and step into it to see
>> why it is not subclassing the control on the dialog template.
>>
>> A Rebuild all might help if you have id mismatches or something.
>>
>> AliR.
>>
> I just found that this is a problem with any control variable I add to the
> dialog - it is actually a Property Page. If I add a control to the dialog
> template, add a member variable for it, and try to use it in the class later,
> it throws an exception with a NULL handle value. I've done a rebuild and
> checked the names of the variables. I have to dynamically create all controls
> - not sure what could be going wrong.
> Appreciate any help.
>
> TIA,
> JY
Are you using the Add Member Variable Wizard? (Right click on the
control on the dialog (propertypage) template in the resource editor and
select Add Variable. This will add the variable to your class and add
DDX_Control in the DoDataExchange.

If not you will need to add the DDX_Control manually to DoDataExchange.


Assuming you've got the above stuff right, check OnInitDialog.

You must call CPropertyPage::OnInitDialog() before your DoDataExchange
is called. Note that your member variables are not associated with the
control until after DoDataExchange is called (by
CPropertyPage::OnInitDialog()).

HTH
Steve
From: Joseph M. Newcomer on
See below...
On Thu, 11 Feb 2010 04:35:01 -0800, JY <sd(a)nospamgroup.com> wrote:

>
>"AliR" wrote:
>
>> Double check your ID in DDX_Control. The rich edit control works the same
>> way as any other control when it comes to subclassing.
>>
>> You can set a break point on the DDX_Control call and step into it to see
>> why it is not subclassing the control on the dialog template.
>>
>> A Rebuild all might help if you have id mismatches or something.
>>
>> AliR.
>>
>I just found that this is a problem with any control variable I add to the
>dialog - it is actually a Property Page. If I add a control to the dialog
>template, add a member variable for it, and try to use it in the class later,
>it throws an exception with a NULL handle value. I've done a rebuild and
>checked the names of the variables. I have to dynamically create all controls
>- not sure what could be going wrong.
>Appreciate any help.
****
THis is always a mistake. You have done something seriously wrong.

For example, in your OnInitDialog handler, do you call the superclass OnInitDialog
handler? Did you put a breakpoint at DoDataExchange to see if it is called? If
DoDataExchange is not being called, you have a coding error. This typically only happens
if you add handlers manually instead of using the automated mechanisms.

Note that there are some annoying glithces, such as if you have a spin control with an
autobuddy with an OnEnChange handler; you will get calls to the handler before the spin
control variable is set. Since you have not given any context of where these happen,
there is no way to diagnose the problem. But you can consider that it is *always* a
mistake to create the controls yourself because you get this error, because what it really
means is you have done something wrong, something that is almost always totally trivial to
repair!
joe
****
>
>TIA,
>JY
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm