Q: Changing a dialog box's title text 
Author Message
 Q: Changing a dialog box's title text

Hi,

     I would appreciate if somebody could tell me how to change the
title text of a dialog box.  I have created a dialog box in MFC and
assign a class CABCDlg (of base CDialog) to the dialog box.  In the main
program, I declare a variable testDlg:

CABCDlg    testDlg;

     I searched through VC++'s CD and found the SetWindowText()
function.  However, when I tried to use the function by issuing the
command testDlg.SetWindowText(), the program returned error (Debug
Assertion Failed).  I also tried to add the title's text when declaring
the function:  CABCDlg    testDlg(_T("Hello")); but the program cannot
compile.
     Thank you for any input to a very inexperienced VC++ programmer.
8-)

Artur
10.23.2000

--
--------------------------------------------------------------------------

Please remove "REMOVE" when replying by email address.  Thanks.



Fri, 11 Apr 2003 03:00:00 GMT  
 Q: Changing a dialog box's title text


Fri, 19 Jun 1992 00:00:00 GMT  
 Q: Changing a dialog box's title text

You have to use SetWindowText() in OnInitDialog() of your dialog.

--
Ajay Kalra [MVP - VC++]

Note: Please post all replies to newsgroup only.


Quote:
> Hi,

>      I would appreciate if somebody could tell me how to change the
> title text of a dialog box.  I have created a dialog box in MFC and
> assign a class CABCDlg (of base CDialog) to the dialog box.  In the main
> program, I declare a variable testDlg:

> CABCDlg    testDlg;

>      I searched through VC++'s CD and found the SetWindowText()
> function.  However, when I tried to use the function by issuing the
> command testDlg.SetWindowText(), the program returned error (Debug
> Assertion Failed).  I also tried to add the title's text when declaring
> the function:  CABCDlg    testDlg(_T("Hello")); but the program cannot
> compile.
>      Thank you for any input to a very inexperienced VC++ programmer.
> 8-)

> Artur
> 10.23.2000

> --
> --------------------------------------------------------------------------

> Please remove "REMOVE" when replying by email address.  Thanks.



Fri, 11 Apr 2003 03:00:00 GMT  
 Q: Changing a dialog box's title text
SetWindowText() is the way to go, but you have to call it after the window
was created, that is in InitDialog function after calling
CDialog::InitDialog().

Dan


Quote:

> Hi,

>      I would appreciate if somebody could tell me how to change the
> title text of a dialog box.  I have created a dialog box in MFC and
> assign a class CABCDlg (of base CDialog) to the dialog box.  In the main
> program, I declare a variable testDlg:

> CABCDlg    testDlg;

>      I searched through VC++'s CD and found the SetWindowText()
> function.  However, when I tried to use the function by issuing the
> command testDlg.SetWindowText(), the program returned error (Debug
> Assertion Failed).  I also tried to add the title's text when declaring
> the function:  CABCDlg    testDlg(_T("Hello")); but the program cannot
> compile.
>      Thank you for any input to a very inexperienced VC++ programmer.
> 8-)

> Artur
> 10.23.2000

> --
> --------------------------------------------------------------------------

> Please remove "REMOVE" when replying by email address.  Thanks.



Fri, 11 Apr 2003 03:00:00 GMT  
 Q: Changing a dialog box's title text

Thanks for your hint.  One more question:  I declared a variable in the derived
CDialog class' Dialog Data in the public area (see code below).  This way I can
pass the title from the main program into the dialog:  testDlg.dialogTitle =
_T("Test"); .  It works fine, but I want to make sure if this is the correct way
to go.  Thanks.

class CABCDlg : public CDialog
{
public:
    CABCDlg (Cwnd* pParent = NULL);

// Dialog Data
//{{AFX_DATA (CABCDlg)
    enum { IDD = <some ID> };
    CString    dialogTitle;    // <------******
    ...

Quote:

> SetWindowText() is the way to go, but you have to call it after the window
> was created, that is in InitDialog function after calling
> CDialog::InitDialog().

> Dan

--
--------------------------------------------------------------------------
Please remove "REMOVE" when replying by email address.  Thanks.


Fri, 11 Apr 2003 03:00:00 GMT  
 Q: Changing a dialog box's title text

Couple of things:

1. Put the title in the constructor of your dialog.

CABCDlg(CString& title, CWnd* pParent = NULL);

and hide the dialog variable:

private:
CString m_dialogTitle.

This way, in the constructor you can set m_dialogTitle to the one passed in
the constructor.

2. If you did not want to do above suggestion, provid a access method for
your title:

CString& GetTitle(){ return m_dialogTitle;}
void SetTitle(CString& title){m_dialogTitle = title;}

--
Ajay Kalra [MVP - VC++]

Note: Please post all replies to newsgroup only.


Quote:
> Thanks for your hint.  One more question:  I declared a variable in the
derived
> CDialog class' Dialog Data in the public area (see code below).  This way
I can
> pass the title from the main program into the dialog:  testDlg.dialogTitle
=
> _T("Test"); .  It works fine, but I want to make sure if this is the
correct way
> to go.  Thanks.

> class CABCDlg : public CDialog
> {
> public:
>     CABCDlg (Cwnd* pParent = NULL);

> // Dialog Data
> file://{{AFX_DATA (CABCDlg)
>     enum { IDD = <some ID> };
>     CString    dialogTitle;    // <------******
>     ...


> > SetWindowText() is the way to go, but you have to call it after the
window
> > was created, that is in InitDialog function after calling
> > CDialog::InitDialog().

> > Dan

> --
> --------------------------------------------------------------------------
> Please remove "REMOVE" when replying by email address.  Thanks.



Fri, 11 Apr 2003 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Change background color of dialog box title

2. Change title for dialog box dynamically

3. change title for dialog box dynamically

4. Changing color of Dialog's Title bar

5. problem:Getting window's text from other process-difference between text and title

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

7. How to change statit text in dialog box

8. Changing text in dialog box

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

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

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

12. Changing a picture dialog box's bitmap.

 

 
Powered by phpBB® Forum Software