Newbie: How to Access Controls on a Dialog

I'm making my first stab at an MFC program.  Basically a dialog box with 
some controls.  I started out with basic edit boxes placed on the main 
dialog using the resource editor in VC++ (6.0).  To set text, I have been 
using the SetDlgItemText(IDC_MYEDITBOX, "Sample Text").  Works fine.

Now I working with Check Boxes.  Okay, placed it using the dialog editor. 
Looked for some sort of equivalent to SetDlgItemText to check and uncheck 
the box using the control ID ("IDC_MYFIRSTCHECKBOX").  Nothing.

Reading through Prosise's "Programming Windows with MFC", I found a 
discussion using the CButton::SetCheck method and examples like:

    m_wndMyCheckBox.SetCheck( BST_CHECKED )

The key difference is that the checkbox is created in code and, therefore, a 
handle is available to it.

So, is there a way to get a handle to controls placed on a dialog using the 
resource editor?  If so how?  Or is the preferred method of working with 
controls to create them in the dialog's initialization code (or as needed), 
and thus have the handles directly.

Any assistance will be greatly appreciated!

Thanks!

Don



0
2/3/2006 2:03:12 PM
vc.mfc 33608 articles. 0 followers. Follow

14 Replies
1069 Views

Similar Articles

[PageSpeed] 50

On Fri, 3 Feb 2006 09:03:12 -0500, Don wrote:

> I'm making my first stab at an MFC program.  Basically a dialog box with 
> some controls.  I started out with basic edit boxes placed on the main 
> dialog using the resource editor in VC++ (6.0).  To set text, I have been 
> using the SetDlgItemText(IDC_MYEDITBOX, "Sample Text").  Works fine.
> 
> Now I working with Check Boxes.  Okay, placed it using the dialog editor. 
> Looked for some sort of equivalent to SetDlgItemText to check and uncheck 
> the box using the control ID ("IDC_MYFIRSTCHECKBOX").  Nothing.
> 
> Reading through Prosise's "Programming Windows with MFC", I found a 
> discussion using the CButton::SetCheck method and examples like:
> 
>     m_wndMyCheckBox.SetCheck( BST_CHECKED )
> 
> The key difference is that the checkbox is created in code and, therefore, a 
> handle is available to it.
> 
> So, is there a way to get a handle to controls placed on a dialog using the 
> resource editor?  If so how?  Or is the preferred method of working with 
> controls to create them in the dialog's initialization code (or as needed), 
> and thus have the handles directly.
> 
> Any assistance will be greatly appreciated!
> 
> Thanks!
> 
> Don

I'm not using VC6 right now, so adjust clicks as necessary:

Basically, right-click the checkbox in the resource editor and add a
control variable.

This will add a dialog member variable and the necessary DDX code to bind
it to the control. 

Check out <http://www.codeproject.com/> for all kinds of tutorials.  It's a
great resource!
0
2/3/2006 2:10:00 PM
Add a control variable for those controls and then use the SetCheck on it 
from
OnInitDialog(...). you can choose between Value OR Control type for a member 
variable you
want to associate with the control. Right click on the control in the 
resource editor and then
choose Add Variable in .net 2004. In vc++6, you will have to right click the 
control in the resource editor
and then click classwizard and then click "Member variables" and then "Add 
Variable".
Make sure to change the type from Value to Control as value is the default 
in vc++6,
but it is by default Control if you were to use vs.net 2003 or vs .net 2005.

In this particular situation you should add a control variable for the 
checkbox like this
CButton  m_CheckBox;

Then add this in your OnInitDialog:-
m_CheckBox.SetCheck(    BST_CHECKED);

-- 
Vipin Aravind

"Don" <someone@somewhere.net> wrote in message 
news:OD%239XqMKGHA.2900@TK2MSFTNGP14.phx.gbl...
> I'm making my first stab at an MFC program.  Basically a dialog box with 
> some controls.  I started out with basic edit boxes placed on the main 
> dialog using the resource editor in VC++ (6.0).  To set text, I have been 
> using the SetDlgItemText(IDC_MYEDITBOX, "Sample Text").  Works fine.
>
> Now I working with Check Boxes.  Okay, placed it using the dialog editor. 
> Looked for some sort of equivalent to SetDlgItemText to check and uncheck 
> the box using the control ID ("IDC_MYFIRSTCHECKBOX").  Nothing.
>
> Reading through Prosise's "Programming Windows with MFC", I found a 
> discussion using the CButton::SetCheck method and examples like:
>
>    m_wndMyCheckBox.SetCheck( BST_CHECKED )
>
> The key difference is that the checkbox is created in code and, therefore, 
> a handle is available to it.
>
> So, is there a way to get a handle to controls placed on a dialog using 
> the resource editor?  If so how?  Or is the preferred method of working 
> with controls to create them in the dialog's initialization code (or as 
> needed), and thus have the handles directly.
>
> Any assistance will be greatly appreciated!
>
> Thanks!
>
> Don
>
>
> 


0
vipin (697)
2/3/2006 2:19:38 PM
Isn't this newsgroup a great resource???

-- 
Vipin Aravind

"BobF" <rNfOrSePeAzMe@charter.net> wrote in message 
news:tl68hcyn532p$.zak3bob0fkuj$.dlg@40tude.net...
> On Fri, 3 Feb 2006 09:03:12 -0500, Don wrote:
>
>> I'm making my first stab at an MFC program.  Basically a dialog box with
>> some controls.  I started out with basic edit boxes placed on the main
>> dialog using the resource editor in VC++ (6.0).  To set text, I have been
>> using the SetDlgItemText(IDC_MYEDITBOX, "Sample Text").  Works fine.
>>
>> Now I working with Check Boxes.  Okay, placed it using the dialog editor.
>> Looked for some sort of equivalent to SetDlgItemText to check and uncheck
>> the box using the control ID ("IDC_MYFIRSTCHECKBOX").  Nothing.
>>
>> Reading through Prosise's "Programming Windows with MFC", I found a
>> discussion using the CButton::SetCheck method and examples like:
>>
>>     m_wndMyCheckBox.SetCheck( BST_CHECKED )
>>
>> The key difference is that the checkbox is created in code and, 
>> therefore, a
>> handle is available to it.
>>
>> So, is there a way to get a handle to controls placed on a dialog using 
>> the
>> resource editor?  If so how?  Or is the preferred method of working with
>> controls to create them in the dialog's initialization code (or as 
>> needed),
>> and thus have the handles directly.
>>
>> Any assistance will be greatly appreciated!
>>
>> Thanks!
>>
>> Don
>
> I'm not using VC6 right now, so adjust clicks as necessary:
>
> Basically, right-click the checkbox in the resource editor and add a
> control variable.
>
> This will add a dialog member variable and the necessary DDX code to bind
> it to the control.
>
> Check out <http://www.codeproject.com/> for all kinds of tutorials.  It's 
> a
> great resource! 


0
vipin (697)
2/3/2006 2:20:53 PM
On Fri, 3 Feb 2006 19:50:53 +0530, Vipin [MVP] wrote:

> Isn't this newsgroup a great resource???

Of course it is!  Just a little Value Add for the OP :-)
0
2/3/2006 2:26:22 PM
Bob,

Thanks for the help and reference to the tutorials!

Don



"BobF" <rNfOrSePeAzMe@charter.net> wrote in message 
news:tl68hcyn532p$.zak3bob0fkuj$.dlg@40tude.net...
> On Fri, 3 Feb 2006 09:03:12 -0500, Don wrote:
>
>> I'm making my first stab at an MFC program.  Basically a dialog box with
>> some controls.  I started out with basic edit boxes placed on the main
>> dialog using the resource editor in VC++ (6.0).  To set text, I have been
>> using the SetDlgItemText(IDC_MYEDITBOX, "Sample Text").  Works fine.
>>
>> Now I working with Check Boxes.  Okay, placed it using the dialog editor.
>> Looked for some sort of equivalent to SetDlgItemText to check and uncheck
>> the box using the control ID ("IDC_MYFIRSTCHECKBOX").  Nothing.
>>
>> Reading through Prosise's "Programming Windows with MFC", I found a
>> discussion using the CButton::SetCheck method and examples like:
>>
>>     m_wndMyCheckBox.SetCheck( BST_CHECKED )
>>
>> The key difference is that the checkbox is created in code and, 
>> therefore, a
>> handle is available to it.
>>
>> So, is there a way to get a handle to controls placed on a dialog using 
>> the
>> resource editor?  If so how?  Or is the preferred method of working with
>> controls to create them in the dialog's initialization code (or as 
>> needed),
>> and thus have the handles directly.
>>
>> Any assistance will be greatly appreciated!
>>
>> Thanks!
>>
>> Don
>
> I'm not using VC6 right now, so adjust clicks as necessary:
>
> Basically, right-click the checkbox in the resource editor and add a
> control variable.
>
> This will add a dialog member variable and the necessary DDX code to bind
> it to the control.
>
> Check out <http://www.codeproject.com/> for all kinds of tutorials.  It's 
> a
> great resource! 


0
2/3/2006 2:59:02 PM
Vipin,

Between you an Bob, I am think I am now pointed in the right direction.

Thanks!

Don


"Vipin [MVP]" <Vipin@nospam.com> wrote in message 
news:ugtWgzMKGHA.3876@TK2MSFTNGP11.phx.gbl...
> Add a control variable for those controls and then use the SetCheck on it 
> from
> OnInitDialog(...). you can choose between Value OR Control type for a 
> member variable you
> want to associate with the control. Right click on the control in the 
> resource editor and then
> choose Add Variable in .net 2004. In vc++6, you will have to right click 
> the control in the resource editor
> and then click classwizard and then click "Member variables" and then "Add 
> Variable".
> Make sure to change the type from Value to Control as value is the default 
> in vc++6,
> but it is by default Control if you were to use vs.net 2003 or vs .net 
> 2005.
>
> In this particular situation you should add a control variable for the 
> checkbox like this
> CButton  m_CheckBox;
>
> Then add this in your OnInitDialog:-
> m_CheckBox.SetCheck(    BST_CHECKED);
>
> -- 
> Vipin Aravind
>
> "Don" <someone@somewhere.net> wrote in message 
> news:OD%239XqMKGHA.2900@TK2MSFTNGP14.phx.gbl...
>> I'm making my first stab at an MFC program.  Basically a dialog box with 
>> some controls.  I started out with basic edit boxes placed on the main 
>> dialog using the resource editor in VC++ (6.0).  To set text, I have been 
>> using the SetDlgItemText(IDC_MYEDITBOX, "Sample Text").  Works fine.
>>
>> Now I working with Check Boxes.  Okay, placed it using the dialog editor. 
>> Looked for some sort of equivalent to SetDlgItemText to check and uncheck 
>> the box using the control ID ("IDC_MYFIRSTCHECKBOX").  Nothing.
>>
>> Reading through Prosise's "Programming Windows with MFC", I found a 
>> discussion using the CButton::SetCheck method and examples like:
>>
>>    m_wndMyCheckBox.SetCheck( BST_CHECKED )
>>
>> The key difference is that the checkbox is created in code and, 
>> therefore, a handle is available to it.
>>
>> So, is there a way to get a handle to controls placed on a dialog using 
>> the resource editor?  If so how?  Or is the preferred method of working 
>> with controls to create them in the dialog's initialization code (or as 
>> needed), and thus have the handles directly.
>>
>> Any assistance will be greatly appreciated!
>>
>> Thanks!
>>
>> Don
>>
>>
>>
>
> 


0
2/3/2006 2:59:44 PM
Generally, ignore SetDlgItemText, it should be thought of as obsolete.

Create a member variable to represent the control, and use the SetWindowText method.

SetDlgItemText sets the text, ignoring all reality of subclassing and therefore bypasses
the entire C++/MFC methodology.  And it certainly would not set the state of a checkbox.
The example from Prosise is the typical way of setting a check mark.

I have no idea why you would need a handle.  If you are creating a checkbox dynamically,
you have done a Create operation, and it returned a CButton *, you would use that
CButton*, e.g.,

mybutton->SetCheck(BST_CHECKED);

Handles do not even enter the discussion.

You can assume that except in very exotic situations, there is never a need to have a
control handle in MFC.  These exotic situations arise from time to time, but generally
about once a year is the typical frequency.

Also, there is always the question of why you are creating controls dynamically.  There
are lots of good reasons to do so, but a huge number of bad reasons.  I find that most
people, especially those new to MFC, tend to have bad reasons.  Can you say why you need
to create them dynamically?
				joe

On Fri, 3 Feb 2006 09:03:12 -0500, "Don" <someone@somewhere.net> wrote:

>I'm making my first stab at an MFC program.  Basically a dialog box with 
>some controls.  I started out with basic edit boxes placed on the main 
>dialog using the resource editor in VC++ (6.0).  To set text, I have been 
>using the SetDlgItemText(IDC_MYEDITBOX, "Sample Text").  Works fine.
>
>Now I working with Check Boxes.  Okay, placed it using the dialog editor. 
>Looked for some sort of equivalent to SetDlgItemText to check and uncheck 
>the box using the control ID ("IDC_MYFIRSTCHECKBOX").  Nothing.
>
>Reading through Prosise's "Programming Windows with MFC", I found a 
>discussion using the CButton::SetCheck method and examples like:
>
>    m_wndMyCheckBox.SetCheck( BST_CHECKED )
>
>The key difference is that the checkbox is created in code and, therefore, a 
>handle is available to it.
>
>So, is there a way to get a handle to controls placed on a dialog using the 
>resource editor?  If so how?  Or is the preferred method of working with 
>controls to create them in the dialog's initialization code (or as needed), 
>and thus have the handles directly.
>
>Any assistance will be greatly appreciated!
>
>Thanks!
>
>Don
>
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15973)
2/3/2006 5:21:41 PM
Joe,

I think I have confused things more with my poor understanding and use of 
terminology.  You are correct, "handles" should have not entered the 
discussion because it is the incorrect term.  The correct term (or hopefully 
a little bit better) would be instance.

My problem was tying what I had done on the resource editor (in terms of 
check boxes, etc) to my code.  The only sample I had initially was the 
SetDlgItemText which used the control ID.  In my wonderings through the 
various references, I did not come across the 'Add Member Variable' approach 
in the MFC class wizard for controls.  That pretty much solved the problem!

I am glad you made the comments you did about dynamically creating controls. 
It seemed like a rather excessive amount of work for something that could be 
done so easily in the resource editor.

Long story short: I now know enough to move forward!

Thanks for your comments!

Don



"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:pv37u1pevl69kjh9vckupeop9duke3qkkg@4ax.com...
> Generally, ignore SetDlgItemText, it should be thought of as obsolete.
>
> Create a member variable to represent the control, and use the 
> SetWindowText method.
>
> SetDlgItemText sets the text, ignoring all reality of subclassing and 
> therefore bypasses
> the entire C++/MFC methodology.  And it certainly would not set the state 
> of a checkbox.
> The example from Prosise is the typical way of setting a check mark.
>
> I have no idea why you would need a handle.  If you are creating a 
> checkbox dynamically,
> you have done a Create operation, and it returned a CButton *, you would 
> use that
> CButton*, e.g.,
>
> mybutton->SetCheck(BST_CHECKED);
>
> Handles do not even enter the discussion.
>
> You can assume that except in very exotic situations, there is never a 
> need to have a
> control handle in MFC.  These exotic situations arise from time to time, 
> but generally
> about once a year is the typical frequency.
>
> Also, there is always the question of why you are creating controls 
> dynamically.  There
> are lots of good reasons to do so, but a huge number of bad reasons.  I 
> find that most
> people, especially those new to MFC, tend to have bad reasons.  Can you 
> say why you need
> to create them dynamically?
> joe
>
> On Fri, 3 Feb 2006 09:03:12 -0500, "Don" <someone@somewhere.net> wrote:
>
>>I'm making my first stab at an MFC program.  Basically a dialog box with
>>some controls.  I started out with basic edit boxes placed on the main
>>dialog using the resource editor in VC++ (6.0).  To set text, I have been
>>using the SetDlgItemText(IDC_MYEDITBOX, "Sample Text").  Works fine.
>>
>>Now I working with Check Boxes.  Okay, placed it using the dialog editor.
>>Looked for some sort of equivalent to SetDlgItemText to check and uncheck
>>the box using the control ID ("IDC_MYFIRSTCHECKBOX").  Nothing.
>>
>>Reading through Prosise's "Programming Windows with MFC", I found a
>>discussion using the CButton::SetCheck method and examples like:
>>
>>    m_wndMyCheckBox.SetCheck( BST_CHECKED )
>>
>>The key difference is that the checkbox is created in code and, therefore, 
>>a
>>handle is available to it.
>>
>>So, is there a way to get a handle to controls placed on a dialog using 
>>the
>>resource editor?  If so how?  Or is the preferred method of working with
>>controls to create them in the dialog's initialization code (or as 
>>needed),
>>and thus have the handles directly.
>>
>>Any assistance will be greatly appreciated!
>>
>>Thanks!
>>
>>Don
>>
>>
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm 


0
2/3/2006 7:39:08 PM
See below...
On Fri, 3 Feb 2006 14:39:08 -0500, "Don" <someone@somewhere.net> wrote:

>Joe,
>
>I think I have confused things more with my poor understanding and use of 
>terminology.  You are correct, "handles" should have not entered the 
>discussion because it is the incorrect term.  The correct term (or hopefully 
>a little bit better) would be instance.
>
>My problem was tying what I had done on the resource editor (in terms of 
>check boxes, etc) to my code.  The only sample I had initially was the 
>SetDlgItemText which used the control ID.  In my wonderings through the 
>various references, I did not come across the 'Add Member Variable' approach 
>in the MFC class wizard for controls.  That pretty much solved the problem!
>
****
See my essay on avoiding GetDlgItem, and in fact you might want to check out my "Dialog
Box Series" on my MVP Tips site.
			joe

****
>I am glad you made the comments you did about dynamically creating controls. 
>It seemed like a rather excessive amount of work for something that could be 
>done so easily in the resource editor.
>
>Long story short: I now know enough to move forward!
>
>Thanks for your comments!
>
>Don
>
>
>
>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
>news:pv37u1pevl69kjh9vckupeop9duke3qkkg@4ax.com...
>> Generally, ignore SetDlgItemText, it should be thought of as obsolete.
>>
>> Create a member variable to represent the control, and use the 
>> SetWindowText method.
>>
>> SetDlgItemText sets the text, ignoring all reality of subclassing and 
>> therefore bypasses
>> the entire C++/MFC methodology.  And it certainly would not set the state 
>> of a checkbox.
>> The example from Prosise is the typical way of setting a check mark.
>>
>> I have no idea why you would need a handle.  If you are creating a 
>> checkbox dynamically,
>> you have done a Create operation, and it returned a CButton *, you would 
>> use that
>> CButton*, e.g.,
>>
>> mybutton->SetCheck(BST_CHECKED);
>>
>> Handles do not even enter the discussion.
>>
>> You can assume that except in very exotic situations, there is never a 
>> need to have a
>> control handle in MFC.  These exotic situations arise from time to time, 
>> but generally
>> about once a year is the typical frequency.
>>
>> Also, there is always the question of why you are creating controls 
>> dynamically.  There
>> are lots of good reasons to do so, but a huge number of bad reasons.  I 
>> find that most
>> people, especially those new to MFC, tend to have bad reasons.  Can you 
>> say why you need
>> to create them dynamically?
>> joe
>>
>> On Fri, 3 Feb 2006 09:03:12 -0500, "Don" <someone@somewhere.net> wrote:
>>
>>>I'm making my first stab at an MFC program.  Basically a dialog box with
>>>some controls.  I started out with basic edit boxes placed on the main
>>>dialog using the resource editor in VC++ (6.0).  To set text, I have been
>>>using the SetDlgItemText(IDC_MYEDITBOX, "Sample Text").  Works fine.
>>>
>>>Now I working with Check Boxes.  Okay, placed it using the dialog editor.
>>>Looked for some sort of equivalent to SetDlgItemText to check and uncheck
>>>the box using the control ID ("IDC_MYFIRSTCHECKBOX").  Nothing.
>>>
>>>Reading through Prosise's "Programming Windows with MFC", I found a
>>>discussion using the CButton::SetCheck method and examples like:
>>>
>>>    m_wndMyCheckBox.SetCheck( BST_CHECKED )
>>>
>>>The key difference is that the checkbox is created in code and, therefore, 
>>>a
>>>handle is available to it.
>>>
>>>So, is there a way to get a handle to controls placed on a dialog using 
>>>the
>>>resource editor?  If so how?  Or is the preferred method of working with
>>>controls to create them in the dialog's initialization code (or as 
>>>needed),
>>>and thus have the handles directly.
>>>
>>>Any assistance will be greatly appreciated!
>>>
>>>Thanks!
>>>
>>>Don
>>>
>>>
>> Joseph M. Newcomer [MVP]
>> email: newcomer@flounder.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm 
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15973)
2/3/2006 9:25:06 PM
Joe,

Just skimmed through some of your articles.

Excellent resource!

Thanks!

Don




"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:8fi7u157f2j152gcpaha6leu3s4kthdm1e@4ax.com...
> See below...
> On Fri, 3 Feb 2006 14:39:08 -0500, "Don" <someone@somewhere.net> wrote:
>
>>Joe,
>>
>>I think I have confused things more with my poor understanding and use of
>>terminology.  You are correct, "handles" should have not entered the
>>discussion because it is the incorrect term.  The correct term (or 
>>hopefully
>>a little bit better) would be instance.
>>
>>My problem was tying what I had done on the resource editor (in terms of
>>check boxes, etc) to my code.  The only sample I had initially was the
>>SetDlgItemText which used the control ID.  In my wonderings through the
>>various references, I did not come across the 'Add Member Variable' 
>>approach
>>in the MFC class wizard for controls.  That pretty much solved the 
>>problem!
>>
> ****
> See my essay on avoiding GetDlgItem, and in fact you might want to check 
> out my "Dialog
> Box Series" on my MVP Tips site.
> joe
>
> ****
>>I am glad you made the comments you did about dynamically creating 
>>controls.
>>It seemed like a rather excessive amount of work for something that could 
>>be
>>done so easily in the resource editor.
>>
>>Long story short: I now know enough to move forward!
>>
>>Thanks for your comments!
>>
>>Don
>>
>>
>>
>>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
>>news:pv37u1pevl69kjh9vckupeop9duke3qkkg@4ax.com...
>>> Generally, ignore SetDlgItemText, it should be thought of as obsolete.
>>>
>>> Create a member variable to represent the control, and use the
>>> SetWindowText method.
>>>
>>> SetDlgItemText sets the text, ignoring all reality of subclassing and
>>> therefore bypasses
>>> the entire C++/MFC methodology.  And it certainly would not set the 
>>> state
>>> of a checkbox.
>>> The example from Prosise is the typical way of setting a check mark.
>>>
>>> I have no idea why you would need a handle.  If you are creating a
>>> checkbox dynamically,
>>> you have done a Create operation, and it returned a CButton *, you would
>>> use that
>>> CButton*, e.g.,
>>>
>>> mybutton->SetCheck(BST_CHECKED);
>>>
>>> Handles do not even enter the discussion.
>>>
>>> You can assume that except in very exotic situations, there is never a
>>> need to have a
>>> control handle in MFC.  These exotic situations arise from time to time,
>>> but generally
>>> about once a year is the typical frequency.
>>>
>>> Also, there is always the question of why you are creating controls
>>> dynamically.  There
>>> are lots of good reasons to do so, but a huge number of bad reasons.  I
>>> find that most
>>> people, especially those new to MFC, tend to have bad reasons.  Can you
>>> say why you need
>>> to create them dynamically?
>>> joe
>>>
>>> On Fri, 3 Feb 2006 09:03:12 -0500, "Don" <someone@somewhere.net> wrote:
>>>
>>>>I'm making my first stab at an MFC program.  Basically a dialog box with
>>>>some controls.  I started out with basic edit boxes placed on the main
>>>>dialog using the resource editor in VC++ (6.0).  To set text, I have 
>>>>been
>>>>using the SetDlgItemText(IDC_MYEDITBOX, "Sample Text").  Works fine.
>>>>
>>>>Now I working with Check Boxes.  Okay, placed it using the dialog 
>>>>editor.
>>>>Looked for some sort of equivalent to SetDlgItemText to check and 
>>>>uncheck
>>>>the box using the control ID ("IDC_MYFIRSTCHECKBOX").  Nothing.
>>>>
>>>>Reading through Prosise's "Programming Windows with MFC", I found a
>>>>discussion using the CButton::SetCheck method and examples like:
>>>>
>>>>    m_wndMyCheckBox.SetCheck( BST_CHECKED )
>>>>
>>>>The key difference is that the checkbox is created in code and, 
>>>>therefore,
>>>>a
>>>>handle is available to it.
>>>>
>>>>So, is there a way to get a handle to controls placed on a dialog using
>>>>the
>>>>resource editor?  If so how?  Or is the preferred method of working with
>>>>controls to create them in the dialog's initialization code (or as
>>>>needed),
>>>>and thus have the handles directly.
>>>>
>>>>Any assistance will be greatly appreciated!
>>>>
>>>>Thanks!
>>>>
>>>>Don
>>>>
>>>>
>>> Joseph M. Newcomer [MVP]
>>> email: newcomer@flounder.com
>>> Web: http://www.flounder.com
>>> MVP Tips: http://www.flounder.com/mvp_tips.htm
>>
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm 


0
2/3/2006 10:36:57 PM
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:pv37u1pevl69kjh9vckupeop9duke3qkkg@4ax.com...
> Generally, ignore SetDlgItemText, it should be thought of as obsolete.
>
> Create a member variable to represent the control, and use the 
> SetWindowText method.
>
> SetDlgItemText sets the text, ignoring all reality of subclassing and 
> therefore bypasses
> the entire C++/MFC methodology.  And it certainly would not set the state 
> of a checkbox.
> The example from Prosise is the typical way of setting a check mark.
>

On the other hand, SetDlgItemInt is often handy (but only because there is 
no SetWindowTextInt).


0
alegr (1131)
2/4/2006 5:03:33 AM
> On the other hand, SetDlgItemInt is often handy (but only because there is 
> no SetWindowTextInt).


How about this:-
CString str;
int i = 5;
str.Format("%d" , i);
m_Edit.SetWindowText(str);

-- 
Vipin Aravind 


0
vipin (697)
2/4/2006 7:57:32 AM
Or take a look at my numeric edit control extension, which allows a formatting string to
be supplied at the SetWindowText time...
				joe

On Sat, 4 Feb 2006 13:27:32 +0530, "Vipin [MVP]" <Vipin@nospam.com> wrote:

>> On the other hand, SetDlgItemInt is often handy (but only because there is 
>> no SetWindowTextInt).
>
>
>How about this:-
>CString str;
>int i = 5;
>str.Format("%d" , i);
>m_Edit.SetWindowText(str);
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15973)
2/5/2006 1:41:03 AM
http://www.codeproject.com/editctrl/ncpedit.asp

Tom

"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:lslau1lfcp9qg7l9t3qiam2tmvbse1n6bs@4ax.com...
> Or take a look at my numeric edit control extension, which allows a 
> formatting string to
> be supplied at the SetWindowText time...
> joe
>


0
tserface (3860)
2/5/2006 6:41:34 AM
Reply:

Similar Artilces:

I need help to display a dialog from a resource-only DLL
Hi, I created a resource-only Dll to store string, dialog, icon and bitmap. With loadstring function i can load a string from this dll, but i don't know how dipslay a dialog from it. here is my code : UINT CDataResource::GetResourceDialog(int ResourceID) { // load resource LPCDLGTEMPLATE lpDialogTemplate = NULL; HGLOBAL hDialogTemplate = NULL; HINSTANCE hInst = AfxFindResourceHandle(MAKEINTRESOURCE(ResourceID), RT_DIALOG); HRSRC hResource = ::FindResource(hInst, MAKEINTRESOURCE(ResourceID), RT_DIALOG); hDialogTemplate = LoadResource(hInst, hResource); if (hDialogTemplate != NULL) ...

Accessing a Different GAL
How can i put a link(entry) to another companys Gal in my gal. Who would i have to contact and how would we set it up. I currently don't have access to their gal. For instance, I am employed by a govt. agency and i want to be able to see a different govt. agencies gal. remember both gals have entries from multiple sites within their own gal. You're best bet is to synchronize your directory with theirs. You can do this using Microsofts Identity Information Feature Pack, or some other 3rd party utility. When you set up the synchronization, ensure that their directory goes into...

Accessing class members ...
m_pEditBoxViewTemplate = new CMultiDocTemplate( IDR_MAINFRAME, NULL, RUNTIME_CLASS( CChildFrame ), // custom MDI child frame RUNTIME_CLASS( CEditBoxView )); ASSERT(m_pEditBoxViewTemplate); pDlgFrame = m_pEditBoxViewTemplate->CreateNewFrame(NULL, NULL); I need to be able to access a function within the CEditBoxView class, and I am not quite sure how. Any suggestions ? Dave wrote: > m_pEditBoxViewTemplate = new CMultiDocTemplate( IDR_MAINFRAME, > NULL, > RUNTIME_CLASS( CChildFrame ), // custom MDI child frame > RUNTIME_CLASS( CEditBoxView )); &...

Newbie, accnts. payable & accnts.receivable sample DB
Hi guys, I�m running access 2003, windows xp pro SP2 I've been commission in my work to do a small application to track and report the accounts payable and accounts receivable movements, I'm not an accounting savvy person :(, does anyone know of a link or sample access database that can help me with the basic structure of the tables and reports?, any help would be greatly appreciated. Thanks ...

Helo command rejected: Access denied
Hi all, I got a problem when i try to send message, the error message as below : Your message did not reach some or all of the intended recipients. Subject: testing Sent: 29/7/2004 11:55 The following recipient(s) could not be reached: 'support@xxx.COM' on 29/7/2004 11:56 The recipient name is not recognized The MTS-ID of the original message is: c=US;a= ;p=xxx (HK) Lt;l=xxxEX01-040729035523Z-29495 MSEXCH:IMS:xxx(HK) Ltd.:TDHK:xxxEX01 3554 (000B09B6) 554 <xxxex01.xxx.com>: Helo command rejected: Access denied ...

MS Access
Why doesn't MS support MS Access for Macintosh? Since I work in an educational environment that's mostly PC with MS Office begin the main suite, it would only be logical that since the PC version of MS Office contains MS Access for database entry, the Mac version of MS Office would also have MS Access. In article <BE09D66D.5FB8%redclawx@hotmail.com>, Red Claw <redclawx@hotmail.com> wrote: > Why doesn't MS support MS Access for Macintosh? Since I work in an > educational environment that's mostly PC with MS Office begin the main > suite, it would only ...

Access 2003 >> Access 2007 (Run-time error 2467)
Hi. I'm trying out how our access 2003 applications work in access 2007. Unfortunately, lots of forms refuse to open. Where the error occures is Form_Current event, which contains something like std = "SELECT ....." Me.Subform_Name![Field Name].RowSource = std The program reports an error: "Run-time error '2467': The expression you entered refers to an object that is closed or doesn't exist." Anyone has any ideas how to fix this? Technically, that shouldn't work in Access 2003 either, but it wasn't quite as sticky about the syntax. To refer t...

Problem with TransferSpreadsheet in Access 2007
I'm having a problem with the TransferSpreadsheet method in Access 2007. The TransferSpreadsheet method is exporting a query to Excel, and it has been working fine under Access 2002. Under 2007, however, Access seems to truncate up some of the query column names, with the result that Access doesn't recognize them and prompts me for values for those columns. The problem is reproducible, occurring on the same columns every time. If I open the query directly the column names are fine and it exports to Excel with no problems; it seems to happen only with the TransferSpreadsheet meth...

exchange 2003 email access
Can I setup exchange 2003 clients to login to it as apposed to being authenticated by the DOMAIN? I have two domains in diferrent locations but want to share one exchange and accessed by IP address as apposed to the computer name. Thanks, Raul Rego rrego@njpies.org Can you explain what you're trying to achieve a little more? Are you trying to get users from domain A to access an exchange server in domain B? "Raul Rego" wrote: > Can I setup exchange 2003 clients to login to it as apposed to being > authenticated by the DOMAIN? > > I have two domains in di...

Visio Newbie
Hello all, this is my first time using Visio for drawing a floor plan and I have a quick question. Yesterday, (Using a tape measure) I mapped out the floor plan of an office my company might be moving into. I wrote everything down in Inches. Is there a way once I get a room shape kinda close to teh measurements, that I can manually type in teh length for each wall? if not in inches, at least in feet. For example, I have one wall that is 154 inches ( 12.83 ft) Then the next wall is 242 incehs( 20.1 ft) The opposite wall of the first measurement is 288 inches, third wall 100 inches, then 13...

ASAP: Accessing ROot
I am having problems accessing the root on an Exchange 5.5 server. When I use "LDAP:\\Servername:Serverport" it directely goes to the default Naming Context. How do you overrided this. I have also tried RootDSE. Thanks ...

accessing autosaves after closing program?
Recently I’ve managed to close a few documents (excel and word) without saving them. Not very clever I know. I know as you are working in these programs you can autosave, which saves the document in a temporary file. But when you close a document the temporary file gets deleted / is not obviously accessible. 1. is it possible to access these so I could open the last autosave? Or 2. is it possible to change some setting / autosave location so these autosaved files are available after I close the program? Actually, autosave just overwrites the file in place but it has to be saved at least...

Exchange newbie problem
Hi all; A user on our domain was deleted when he should not have been. His mail box was not deleted. When his account was recreated, we tried to reconnect the old mailbox. But when selecting a user in the "Select a new user for this mailbox" dialog a message comes back saying that the user cannot be found. We tried several different users a none can be found even though they can get there mail just fine. We need to get the messages from this mailbox. Any ideas would be great -- Craig in the High Desert. craig@craignet.com But it's a dry heat. you should be able to reconnec...

C++ / Access Newbie
Hi Folks... I have a small commercial package written in C++ (targeted to Windows platforms) that uses its own proprietary database. We are just starting to investigate the option of replacing our database with a commercial package, such as Access or MySQL. Can anyone recommend informative reading that provides details on programming C++ with either of these two databases? At this stage we have no (any I mean ZERO) experience such programming. Any information would be helpful: recommendations for Access over MySQL (or vice versa), sources of such comparisons, licensing considerations, OD...

Applying Hyperlink in Access Genrated Email
I am trying to apply a hyperlink to an email that is generated out of Access and sent to Outlook The message body needs to say something like this: The Report is now posted on the server: LINK: \\Server\Test I need the \\Server\Test to be hyperlinked above Below is what I have so far On Error GoTo Err_cmdEmail_Click Dim StrTemp As String StrTemp = Format("\\bhihnbwfa01\Groups\HRR_WFA\300_General Employee Data\Org_View", HTML) Can this be done? Dim strDocName As String Dim strEmail As String Dim strMailSubject As String Dim strMsg As St...

newbie
joining the group Hey Newbie where are you from and what versiona re you using? Fliehigh "cthomas23@hotmail.com" wrote: > joining the group > ...

removing access to unsafe attachments
Every once in a while I will get the message that "OE has removed access to the following unsafe attachments in your mail" I have not thought much about it until I e-mailed myself some attachments from my home computer which I know does not have a virus and the attachments are not "unsafe" If it automatically removes access to it, can I somehow get access to the attachments I sent. I really need to have them here at work and they are too big to put on a disk and bring with me. Any help? Carol Husted Carol Husted Bashed at the keyboard and said: > Every onc...

Help with Excel ActiveX listbox controls
Hi! I�m trying to create listboxes that displays data from a named range spanning multiple columns. I am able to populate the listbox with data and use it without any problems. However, if the sheet that contains the listboxes changes, the size/dimensions of the listbox unexpectedly also changes. Since I have not written any procedures that control the height/width properties of the listboxes, I cannot determine why the dimensions of the listboxes are changing. I have attached a spreadsheet that illustrates this problem. When you open the spreadsheet, you should see two listboxes named Lis...

Real Newbie newbie question
Hi All - I hope you can help me! I have Finepix M603 camera and although I take reasonable shots in daytime, I'm not able to produce anything at night. eg On The Thames on New Years Eve, may people were using digital cameras and their screens should clear bright picture - mine was black! What setting should I set on mine? Any advice really appreciated. --- David Scott Hampshire, England Wrong group. Sorry....... -- --- David Scott Hampshire, England "Dave" <cadasco@SUPERhotmail.com> wrote in message news:50kuejF1fh28sU1@mid.individual.net... > Hi All - I hope...

eConnect newbie
Hi, I've installed eConnect 7.5 and am planning to use this to read & write xml files to GP can anyone give me samples or examples of how to do this, also my company is planning to upgrade to GP 9 shortly are there major changes between each version? Thanks in advance. JimB If you've installed eConnect, then you have several samples already. They are located in the samples folder underneath the eConnect installation. The changes from 7.5 to 9.0 are fairly minimal. Mostly, there are new xml elements that can be included, but many of those are optional. It's my gue...

Exchange 2003 web access questions
Hi there: We've recently added an Exchange 2003 server into our network, while leaving the original Exchange 2000 server up and running with a few mailboxes on it. I'm currently having a problem completing the transition to 2003 because some old code doesn't seem to work anymore. We have implemented a very limited email interface for our factory workers, so that they can only send email to approved addresses, and all emails are CC'd to supervisors. I wrote this interface a couple of years ago in ASP, and it does every thing we need. If we try to copy this interface over to t...

proper closing of modeless dialog box in dll
I have created a modeless dialog box from a dll and would like to know what the correct method is for shutting it down. here is what I do: in the oncancel handler for the dialog: CDialog::OnCancel(); DestroyWindow() ((CMyApp *) AfxGetApp())->pDlg = NULL That last line I am doing because the process that uses the dll may reopen the dialog box and the way I judge whether or not the dialogbox needs to be created is by testing whether pDlg is NULL. If it is not NULL then obviously I don't want to be putting another dialogbox on the screen. So, is it safe to be assigning NULL to pDlg, ...

Microsoft Access 2007
What is the maximum Access 2007 database size? 2 GB as it was with 2003, Look at this link for mare information http://office.microsoft.com/en-us/access/HA100307391033.aspx -- Good Luck BS"D "Fred Cody" wrote: > What is the maximum Access 2007 database size? > ...

MDI newbie ?
I want to add a "reload" command that will close the current(and only) document and reload it again. Here is what I have tried so far: <code> AfxGetMainWnd()->PostMessage(WM_COMMAND, ID_FILE_NEW); while(AfxGetApp()->GetOpenDocumentCount() > 0); AfxGetApp()->OpenDocumentFile(currentFluPath); </code> This doesn't work, because, as I've learned ID_FILE_NEW create just that, a new blank document so count is still 1. I can't figure out what I should check for, how I can know when the ID_FILE_NEW is done so that I can call OpenDocumentFile() Does ...

Access 2002 bug: "dynamic" forms problem
A while ago we had a discussion about A2002 (sub)form which changes dynamically from code (hide/unhide controls, change subfom's width, etc.). There's a problem if I make some changes in code when the form is open: if I save changes, A2002 saves controls positions & subform's size as well. This is a BIG A2002 BUG and it's really annoying. Why Access forms don't behave as Visual Basic forms? I don't want Access to change my (sub)forms' design properties... grrrrrrr.... Somebody has recommended not to save changes when I'm in debug and/or(?) break mode...