Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Change title to an object from CPrintDialog class

Posted on 2001-06-30
12
481 Views
Last Modified: 2013-11-20
hi,
I would like to change on run time the title of CPrintDialog dialog. I cannot inherit it. is there a way to do so by using one of its members?
thanks in advance, RanBN
0
Comment
Question by:RanBN
  • 5
  • 3
  • 2
  • +1
12 Comments
 
LVL 2

Expert Comment

by:GloriousRain
ID: 6241904
Use SetWindowText in OnInitDialog, RanBN
Ex:
BOOL CYourDlg::OnInitDialog()
{
...
   SetWindowText("YourTitle");
...
}
0
 
LVL 2

Expert Comment

by:GloriousRain
ID: 6241909
ok, if you cannot inherit it, instantiate a CPrintDialog object then call SetWindowText()
Ex:
...
CPrintDialog dlg(FALSE);
dlg.SetWindowText("YourTitle")
...
0
 

Author Comment

by:RanBN
ID: 6241916
thanks but,
before DoModal(), hWnd member is NULL, therefore SetWindowText fails.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 42

Expert Comment

by:sedgwick
ID: 6241988
why can't u create your own CPrintDialog derived class?
in the constructor u can send a CString which would later be the title of your CPrintDialog:

//constructor
CMyPrintDialog::CMyPrintDialog(CString sTitle, bool bPrintSetupOnly, ...)
{
m_strTitle = sTitle;
}

CMyPrintDialog::OnInitDialog()
{
     CPrintDialog::OnInitDialog();
     
     SetWindowText(m_strTitle);
     return TRUE;  
}


the code to display your CPrintDialog:
CMyPrintDialog dlg("My Print Dialog", FALSE);    
dlg.DoModal();



good luck
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 6241989
the other way i think is to use modaless CPrintDialog and after ->Create() use SetWindowText to change its title, and ShowWindow() to display it.

0
 

Author Comment

by:RanBN
ID: 6242017
Hi and thanks again,
please let me be more specific about my request:
I would like to take the original CPrintDialog, the one which is located when I click on the standard toolBar "File->Print".
well, I would like to change it my my CMyView class. according the MSDN help, I should override massage OnPreparePrinting(CPrintInfo* pInfo).
in class CPrintInfo there is a member m_pPD which provides information about the Print dialog. does anyone know what to do with it in order to change caption?
thanks, RanBN
0
 

Author Comment

by:RanBN
ID: 6242097
Hi and thanks again,
please let me be more specific about my request:
I would like to take the original CPrintDialog, the one which is located when I click on the standard toolBar "File->Print".
well, I would like to change it my my CMyView class. according the MSDN help, I should override massage OnPreparePrinting(CPrintInfo* pInfo).
in class CPrintInfo there is a member m_pPD which provides information about the Print dialog. does anyone know what to do with it in order to change caption?
thanks, RanBN
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 6242106
as far as i know there's no member in PRINTDLG (m_pd) which is the caption. (according to MSDN)
0
 

Author Comment

by:RanBN
ID: 6242119
the m_pPD is a pointer to CPrintDialog, but its m_hWnd member is NULL when I have it OnPreparePrinting.
does anyone have an idea?
thanks, RanBN
0
 
LVL 12

Accepted Solution

by:
migel earned 150 total points
ID: 6276311
Hi!
here is method:
1. Derive your class from CPrintDialog
2. Override OnInitDialog and call here SetWindowText("Hello!") << for example
3. Override in the your view class OnPreparePrinting:

BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
  // free already allocated dialog:
if (m_pPD)
 delete m_pPD;
m_pPD = new CMyPrintDialog(FALSE, PD_ALLPAGES | PD_USEDEVMODECOPIES |
          PD_NOSELECTION);
// and pass it to the framework;
     return DoPreparePrinting(pInfo);
// note you shouldn`t delete allocated dialog
// since MFC frees it in the CPrintInfo destructor.
}

Hope it helps you.
0
 
LVL 12

Expert Comment

by:migel
ID: 6276312
oops
m_pPD
 must be
pInfo->m_pPD
0
 

Author Comment

by:RanBN
ID: 6276604
thanks alot
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Separate into files by filename 12 87
iSeries DB2 Query 2 96
Fibonacci challenge 11 132
firstChar challenge 13 119
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question