|
-
October 2nd, 2000, 07:28 PM
#1
Initialising CPrintDialog with my own DevMode....
In my application I am bringing up a CPrintDialog to allow the user to choose a printer, page orientation, etc. However, I cannot find a way to remember the settings so that the next time it comes up it will show the user the options they chose previously.
Thanks
Christian
-
October 3rd, 2000, 12:26 AM
#2
Re: Initialising CPrintDialog with my own DevMode....
Keep the PRINTDLG.hDevMode handle(or make a copy of DEVMODE), make sure it's not deleted, set it before calling the print dialog box.
The GDI book to read: http://www.fengyuan.com
-
October 3rd, 2000, 02:24 AM
#3
Re: Initialising CPrintDialog with my own DevMode....
How about writing them to the Registry? You could read them in like:
BOOL CMyListView::OnPreparePrinting(CPrintInfo *pInfo)
{
CWinApp *pApp = ::AfxGetApp();
ASSERT(pApp);
PRINTDLG *pDlg = &(pInfo->m_pPD->m_pd);
//get printer defaults
if(!pInfo->m_pPD->GetDefaults())
{
MessageBox("Unable to get printer defaults.\n", "OnPreparePrinting", STOP);
return FALSE;
}
/////////////////////////////////////////////////////////////////////
// load printer settings from registry
//lock, initialize, unlock device mode memory
DEVMODE *pDevMode = NULL;
if(!(pDevMode = (DEVMODE *)::GlobalLock(pDlg->hDevMode)))
{
TRACE0("GlobalLock (DEVMODE) failed.\n");
::GlobalFree(pDlg->hDevMode);
::GlobalFree(pDlg->hDevNames);
return FALSE;
}
//printer mode
::lstrcpy
(
(LPTSTR)(pDevMode->dmDeviceName),
(LPCTSTR)(pApp->GetProfileString(REG_SECTION_PRINTING, REG_ENTRY_DEVICENAME, (LPCTSTR)(pDevMode->dmDeviceName)))
);
pDevMode->dmSpecVersion = pApp->GetProfileInt(REG_SECTION_PRINTING, REG_ENTRY_SPECVERSION, pDevMode->dmSpecVersion);
pDevMode->dmDriverVersion = pApp->GetProfileInt(REG_SECTION_PRINTING, REG_ENTRY_DRIVERVERSION, pDevMode->dmDriverVersion);
pDevMode->dmSize = sizeof(DEVMODE); pDevMode->dmDriverExtra = 0;
//page mode
pDevMode->dmOrientation = pApp->GetProfileInt(REG_SECTION_PRINTING, REG_ENTRY_PAGEORIENTATION, REG_DEFAULT_PAGEORIENTATION);
pDevMode->dmPaperSize = pApp->GetProfileInt(REG_SECTION_PRINTING, REG_ENTRY_PAGESIZE, REG_DEFAULT_PAGESIZE);
pDevMode->dmFields = DM_ORIENTATION | DM_PAPERSIZE; ::GlobalUnlock(pDlg->hDevMode);
//lock, initialize, unlock device names memory
DEVNAMES *pDevNames = NULL;
if(!(pDevNames = (DEVNAMES *)::GlobalLock(pDlg->hDevNames)))
{
TRACE0("GlobalLock (DEVNAMES) failed.\n");
::GlobalFree(pDlg->hDevMode);
::GlobalFree(pDlg->hDevNames);
return FALSE;
}
//printer names
LPTSTR pStr = (LPTSTR)pDevNames;
pStr += pDevNames->wDriverOffset;
::lstrcpy(pStr, pApp->GetProfileString(REG_SECTION_PRINTING, REG_ENTRY_DRIVER, pStr));
pDevNames->wDeviceOffset = pDevNames->wDriverOffset + strlen(pStr) + 1;
pStr = (LPTSTR)pDevNames;
pStr += pDevNames->wDeviceOffset;
::lstrcpy(pStr, pApp->GetProfileString(REG_SECTION_PRINTING, REG_ENTRY_DEVICE, pStr));
pDevNames->wOutputOffset = pDevNames->wDeviceOffset + strlen(pStr) + 1;
pStr = (LPTSTR)pDevNames;
pStr += pDevNames->wOutputOffset;
::lstrcpy(pStr, pApp->GetProfileString(REG_SECTION_PRINTING, REG_ENTRY_OUTPUT, pStr));
pDevNames->wDefault = GetProfileInt(REG_SECTION_PRINTING, REG_ENTRY_DEFAULT, pDevNames->wDefault);
::GlobalUnlock(pDlg->hDevNames);
if(!pInfo->m_bPreview) //if we're printing
{
//commit print dialog box to user manipulation
pDlg->Flags &= ~PD_RETURNDEFAULT;
if(pInfo->m_pPD->DoModal() == IDCANCEL)
{
::GlobalFree(pDlg->hDevMode);
::GlobalFree(pDlg->hDevNames);
return FALSE;
}
}
//create device context
if(!(pDlg->hDC = pInfo->m_pPD->CreatePrinterDC()))
{
MessageBox("Unable to create printer device context.\n", "OnPreparePrinting", STOP);
::GlobalFree(pDlg->hDevMode);
::GlobalFree(pDlg->hDevNames);
return FALSE;
}
return TRUE;
}
Respectfully,
S. Bro
/* I would be happy to deal with my problems one at the time if they would only line up! */
-
August 18th, 2009, 08:45 AM
#4
Re: Initialising CPrintDialog with my own DevMode....
 Originally Posted by Feng Yuan
Keep the PRINTDLG.hDevMode handle(or make a copy of DEVMODE), make sure it's not deleted, set it before calling the print dialog box.
I am trying to do exactly the same thing but it doesn't work so far. MSDN says that ...the values of hDevMode and hDevNames in PRINTDLG may change when they are passed into PrintDlg. This is because these members are filled on both input and output.
When I set my stored hDevMode handle in the PRINTDLG structure before calling
Code:
CPrintDialog::DoModal()
, its value is changed during the call. Does it mean that I always have to store the current value of PRINTDLG.hDevMode?
In other words, I thought the hDevMode (being a HGLOBAL variable) acts like a pointer - I can pass it into the dialog, the data this variable points to is changed, but I can still use the same value of the hDevMode variable. Am I missing something?
-
August 19th, 2009, 04:41 AM
#5
Re: Initialising CPrintDialog with my own DevMode....
 Originally Posted by Pavel Kotrc
Does it mean that I always have to store the current value of PRINTDLG.hDevMode?
According to Microsoft KB article 193103, the answer is yes, the stored DEVMODE handle has to be updated each time you call
Code:
CPrintDialog::DoModal
because it discards the handle we passed into it and makes its own copy.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|