How to change "Caption" of Dialog in run-time

I need to push two options from menu (two different function), and call the same Dialog, and change to different Caption (Dialog title) due to which function call

Caption Location: http://140.134.4.20/~d8825313/1.GIF

Example
OnCopyFile(){
<... set "Copy" title to dlgOper Dialog ...>
dlgOper.DoModal();
}
OnMoveFile(){
<... set "Move" title to dlgOper Dialog ...>
dlgOper.DoModal();
}

I have tried dlgOper.SetWindowTextA(), dlgOper.SetDlgItemTextA(), and didn't work;



Answer this question

How to change "Caption" of Dialog in run-time

  • cikitani

    It doesn't work because, before calling DoModal, the dialog window is not yet created (the CDialog-derived object has not yet attached a window).
    One solution is to add a public member to your CDialog-derived class (e.g. CString m_strCaption), set its value before calling DoModal, then call SetWindowText in the WM_INITDIALOG message handler (OnInitDialog).
    Example:

     

    class CMyDialog : public CDialog
    {
      // ...
    public:
      CString m_strCaption;
      // ...
    };
    // ...
    BOOL CMyDialog::OnInitDialog()
    {
      // ...
      SetWindowText(m_strCaption);
      // ...
    }
    // ...
      // ...
    CMyDialog dlgOper;
    // ...
    dlgOper.m_strCaption = _T("Baba Safta is programming"); dlgOper.DoModal(); // ... // ...


  • awperli

    Done, Love u so much, my lover

  • How to change "Caption" of Dialog in run-time