Changing text in dialog box 
Author Message
 Changing text in dialog box

I would like to specify the range that a user can choose in a dialog
box.
I have:

Enter number:  (1-12)  ______

I will need to get the range (1-12) from a different variable in the
program.  How do I do this?



Mon, 31 May 2004 07:01:31 GMT  
 Changing text in dialog box
You can use the CSpinButtonCtrl.

Check out its methods

CSpinButtonCtrl::SetBuddy
CSpinButtonCtrl::SetRange

Quote:

> I would like to specify the range that a user can choose in a dialog
> box.
> I have:

> Enter number:  (1-12)  ______

> I will need to get the range (1-12) from a different variable in the
> program.  How do I do this?



Mon, 31 May 2004 09:22:03 GMT  
 Changing text in dialog box
Here is one simple way to do what I think you want.  Make a static control
to hold the "Enter number (1-12):" caption.  Give the static control a
unique ID and set its text programatically:

int imin = 1;   int imax = 12;
CString str;   str.Format("Enter number (%i-%i):", imin, imax);
GetDlgItem(IDC_CAPTION)->SetWindowText(str);

Quote:

> I would like to specify the range that a user can choose in a dialog
> box.
> I have:

> Enter number:  (1-12)  ______

> I will need to get the range (1-12) from a different variable in the
> program.  How do I do this?



Mon, 31 May 2004 10:42:12 GMT  
 Changing text in dialog box
I implemented the dialog box the way that you suggested.  It compiles fine, but
i get a run time error.  When i run the de{*filter*} it shows the error at the
arrow:

    CWnd *CWnd::GetDlgItem(int nID) const
    {
-->      ASSERT(::IsWindow(m_hWnd));

            if(m_pCtrl==NULL)
            ....

At first i had the call to GetDlgItem inside the menu class, and thought that
there might be problems accessing the variables of the dialog class.  Then i put
the call inside a function for the dialog class, and the same problem remained.
I used this same GetDlgItem function in other places in this program and it has
always worked.  if you have any suggestions of where i could start to look for
the problem, it would be helpful.
Thank,
jess

Quote:

> Here is one simple way to do what I think you want.  Make a static control
> to hold the "Enter number (1-12):" caption.  Give the static control a
> unique ID and set its text programatically:

> int imin = 1;   int imax = 12;
> CString str;   str.Format("Enter number (%i-%i):", imin, imax);
> GetDlgItem(IDC_CAPTION)->SetWindowText(str);


> > I would like to specify the range that a user can choose in a dialog
> > box.
> > I have:

> > Enter number:  (1-12)  ______

> > I will need to get the range (1-12) from a different variable in the
> > program.  How do I do this?



Wed, 02 Jun 2004 09:45:57 GMT  
 Changing text in dialog box

Quote:

> I implemented the dialog box the way that you suggested.  It compiles fine, but
> i get a run time error.  When i run the de{*filter*} it shows the error at the
> arrow:

>     CWnd *CWnd::GetDlgItem(int nID) const
>     {
> -->      ASSERT(::IsWindow(m_hWnd));

>             if(m_pCtrl==NULL)
>             ....

> At first i had the call to GetDlgItem inside the menu class, and thought that
> there might be problems accessing the variables of the dialog class.  Then i put
> the call inside a function for the dialog class, and the same problem remained.
> I used this same GetDlgItem function in other places in this program and it has
> always worked.  if you have any suggestions of where i could start to look for
> the problem, it would be helpful.
> Thank,
> jess

It is necessary, but not sufficient, to put the call inside the dialog
class.  The m_hWnd that the ASSERT checks is the HWND of the dialog.
The ASSERT is telling you that the dialog window has not yet been
created.  Of course, that means that whatever control you are accessing
has not yet been created either.  You can only access controls on a
dialog after the DoModal call.  Not before DoModal, and not in the
dialog constructor.   The place to do such things is in the OnInitDialog
function after it calls the CDialog base class.

--
Scott McPhillips [VC++ MVP]



Thu, 03 Jun 2004 00:37:05 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. How to change the color,size,font of text in a dialog box

2. How to change statit text in dialog box

3. How to change the color,size,font of text in a dialog box

4. Q: Changing a dialog box's title text

5. changing the font for text items in a dialog box

6. Dynamically changing text of a menu in a Dialog box

7. Change the background color of a dialog box and change text color of Edit Box, Static Text, Rich Edit

8. Changing Rich Text Box : Text

9. Wrapping text in text box or edit box

10. changing ont of text box

11. Changing the Font in a text box

12. Changing text color in a CEdit box

 

 
Powered by phpBB® Forum Software