How do I change the caption on an MFC Dialog box (dynamically) 
Author Message
 How do I change the caption on an MFC Dialog box (dynamically)

I have a dialog box that I would like the caption heading for, depending on
the selection made from a menu.

I have tried:

 CString CaptionText = _T("Dynamic Heading");
 dlgDialogBox.SetWindowText(CaptionText);

and I keep getting an assertion failure.  The SetWindowText function is
supposed to take a CString object, so I'm confused.  (My normal state of
existence!)

Any suggestions would be appreciated.  Thanks.

Stephen



Wed, 13 Oct 2004 12:00:45 GMT  
 How do I change the caption on an MFC Dialog box (dynamically)

CWnd::SetWindowText
void SetWindowText( LPCTSTR lpszString );

Parameters

lpszString

Points to a CString object or null-terminated string to be used as the new
title or control text.

Remarks

Sets the window?s title to the specified text. If the window is a control,
the text within the control is set.

This function causes aWM_SETTEXT message to be sent to this window.

CWnd Overview |  Class Members |  Hierarchy Chart

See Also   CWnd::GetWindowText,::SetWindowText



Quote:
> I have a dialog box that I would like the caption heading for, depending
on
> the selection made from a menu.

> I have tried:

>  CString CaptionText = _T("Dynamic Heading");
>  dlgDialogBox.SetWindowText(CaptionText);

> and I keep getting an assertion failure.  The SetWindowText function is
> supposed to take a CString object, so I'm confused.  (My normal state of
> existence!)

> Any suggestions would be appreciated.  Thanks.

> Stephen



Wed, 13 Oct 2004 12:53:42 GMT  
 How do I change the caption on an MFC Dialog box (dynamically)
I assume you did this "SetWindowText" in the initdialog? The possible reason
for error is the dialog box neither created or it is not "DoModel"ed

Soorej


Quote:
> I have a dialog box that I would like the caption heading for, depending
on
> the selection made from a menu.

> I have tried:

>  CString CaptionText = _T("Dynamic Heading");
>  dlgDialogBox.SetWindowText(CaptionText);

> and I keep getting an assertion failure.  The SetWindowText function is
> supposed to take a CString object, so I'm confused.  (My normal state of
> existence!)

> Any suggestions would be appreciated.  Thanks.

> Stephen



Wed, 13 Oct 2004 14:17:33 GMT  
 How do I change the caption on an MFC Dialog box (dynamically)
Quote:
> > I have tried:

> >  CString CaptionText = _T("Dynamic Heading");
> >  dlgDialogBox.SetWindowText(CaptionText);

I'm assuming the next line reads:
dlgDialogBox.DoModal();
or summik like that

In that case, your problem is that you are changing the text of a control
that doesn't exist yet, which is clearly impossible and causes the crash.
To resolve this, I recommend adding a CString to your dialog declaration.
Then in the InitDialog function, add a call to set the window text to the
CString.
Final, simply set the cstring before domodal

//In the function that create the dialog
dlgDialogBox.CaptionTest="Dynamic"
dlgDialogBox.DoModal();

//In the dialog definition (.h file, inside the class bit)
public:
CString CaptionTest

//In the InitDialog handler
SetWindowText(CaptionText);

Hope that helps,
Robin



Fri, 15 Oct 2004 04:19:20 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Change the caption of the dialog box

2. Change title for dialog box dynamically

3. change title for dialog box dynamically

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

5. Changing Button Caption Dynamically

6. Dynamically change caption of a menu

7. Problems with List box in dynamically created dialog box

8. Problems with List box in dynamically created dialog box

9. PBM: Message box not displayed after main dialog box is closed in MFC dialog-based app

10. Window Caption for a Dialog Box Control

11. How to change on runtime the caption of a C++ dialog app main window

12. How to change on runtime the caption of a C++ dialog app main window

 

 
Powered by phpBB® Forum Software