How to change "Caption" of Dialog in run-time  
Author Message
CryBaby





PostPosted: Visual C++ General, How to change "Caption" of Dialog in run-time Top

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://www.hide-link.com/ ~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;



Visual C++14  
 
 
Ovidiu Cucu





PostPosted: Visual C++ General, How to change "Caption" of Dialog in run-time Top

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(); // ... // ...


 
 
CryBaby





PostPosted: Visual C++ General, How to change "Caption" of Dialog in run-time Top

Done, Love u so much, my lover