Solved

Change title to an object from CPrintDialog class

Posted on 2001-06-30
12
483 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
[X]
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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Turn a spreadsheet into a vba executable. 2 103
Separate into files by filename 12 92
building a service to accessed via telnet client, want colors ? 4 108
Line meaning 9 99
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 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