Click here to Skip to main content
15,906,816 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralPlease help in getting Unicode Filenames into a file Pin
stvprg5-May-05 11:52
stvprg5-May-05 11:52 
GeneralSaving printer options Pin
crowbarcberg5-May-05 11:09
crowbarcberg5-May-05 11:09 
GeneralRe: Saving printer options Pin
PJ Arends5-May-05 12:25
professionalPJ Arends5-May-05 12:25 
GeneralRe: Saving printer options Pin
crowbarcberg5-May-05 17:27
crowbarcberg5-May-05 17:27 
GeneralRe: Saving printer options Pin
Ryan Binns5-May-05 18:09
Ryan Binns5-May-05 18:09 
GeneralRe: Saving printer options Pin
crowbarcberg6-May-05 2:44
crowbarcberg6-May-05 2:44 
GeneralRe: Saving printer options Pin
PJ Arends6-May-05 5:47
professionalPJ Arends6-May-05 5:47 
GeneralRe: Saving printer options Pin
PJ Arends6-May-05 6:45
professionalPJ Arends6-May-05 6:45 
crowbarcberg wrote:
DEVMODE *dm=pd.GetDevMode();
theApp.WriteProfileBinary("CheckPrinter", "DevMode", (LPBYTE)&dm, sizeof(dm));


dm is a pointer, so what you are saving here is the address of the DEVMODE structure, not the data in the DEVMODE structure.
theApp.WriteProfileBinary("CheckPrinter", "DevMode", (LPBYTE)dm, sizeof(DEVMODE));

crowbarcberg wrote:
Also how would I get the same options back into a CPrintDialog object so that a user could change the options?

That is the fun part. You have to rebuild the hDevMode and hDevNames members of the m_pd member of the CPrintDialog dialog. Remember that those are HGLOBAL handles to movable global memory objects, not pointers to a locally allocated memory block. Here is code that I use to do this:
LPDEVMODE pDM = pConfig->StringToDevMode(pConfig->DevMode);
int size = sizeof(DEVMODE);
HGLOBAL hDEVMODE = GlobalAlloc(GHND, size);
void *pV = GlobalLock(hDEVMODE);
memcpy(pV, pDM, size);
GlobalUnlock(pV);
delete pDM;
pDM = NULL;

size = sizeof(DEVNAMES);
size += (pConfig->Printer.GetLength() + 1) * sizeof(TCHAR);
size += (pConfig->Port.GetLength() + 1) * sizeof(TCHAR);
size += (pConfig->Driver.GetLength() + 1) * sizeof(TCHAR);

HGLOBAL hDEVNAMES = GlobalAlloc(GHND, size);
LPDEVNAMES pDN = (LPDEVNAMES)GlobalLock(hDEVNAMES);
pDN->wDefault = 0;
pDN->wDriverOffset = sizeof(DEVNAMES);
pDN->wDeviceOffset = (WORD)(pDN->wDriverOffset + pConfig->Driver.GetLength() + 1);
pDN->wOutputOffset = (WORD)(pDN->wDeviceOffset + pConfig->Printer.GetLength() + 1);
_tcsncpy((TCHAR *)((int)pDN + pDN->wDriverOffset), pConfig->Driver, pConfig->Driver.GetLength());
_tcsncpy((TCHAR *)((int)pDN + pDN->wDeviceOffset), pConfig->Printer, pConfig->Printer.GetLength());
_tcsncpy((TCHAR *)((int)pDN + pDN->wOutputOffset), pConfig->Port, pConfig->Port.GetLength());
GlobalUnlock(pDN);

CPrintSetupDialog dlg(this);
dlg.m_pd.hDevMode = hDEVMODE;
dlg.m_pd.hDevNames = hDEVNAMES;

if (dlg.DoModal() == IDOK)
{
    pConfig->Printer = dlg.GetDeviceName();
    pConfig->Driver = dlg.GetDriverName();
    pConfig->Port = dlg.GetPortName();
    m_EditSendTo.SetWindowText(pConfig->Printer);

    pDM = dlg.GetDevMode();
    pConfig->DevMode = pConfig->DevModeToString(pDM);
    GlobalUnlock(pDM);
}
else
{
    GlobalFree (hDEVMODE);
}

GlobalFree (hDEVNAMES);



crowbarcberg wrote:
And finally where should I call the CDC::CreateDC() function from the view class so that the CPrintDialog dialog won't be displayed again? Currently I have OnPreparePrinting(), OnBeginPrinting(), OnEndPrinting(), and OnPrint() functions extended in my view class.

The Print dialog is called from OnPreparePrinting(), so I think I would do it there. Have a look in MSDN[^] for more information. I have done this only in a dialog based app so I did not have the Doc-View framework at my disposal and have not had to worry about which function to override.



"You're obviously a superstar." - Christian Graus about me - 12 Feb '03

"Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04

Within you lies the power for good - Use it!
Honoured as one of The Most Helpful Members of 2004

GeneralRe: Saving printer options Pin
crowbarcberg6-May-05 9:14
crowbarcberg6-May-05 9:14 
GeneralRe: Saving printer options Pin
PJ Arends6-May-05 10:59
professionalPJ Arends6-May-05 10:59 
GeneralRe: Saving printer options Pin
crowbarcberg6-May-05 11:15
crowbarcberg6-May-05 11:15 
GeneralRe: Saving printer options Pin
PJ Arends6-May-05 13:46
professionalPJ Arends6-May-05 13:46 
GeneralRe: Saving printer options Pin
crowbarcberg6-May-05 15:31
crowbarcberg6-May-05 15:31 
GeneralRe: Saving printer options Pin
crowbarcberg13-May-05 6:22
crowbarcberg13-May-05 6:22 
GeneralRe: Saving printer options Pin
crowbarcberg13-May-05 6:30
crowbarcberg13-May-05 6:30 
GeneralRe: Saving printer options Pin
PJ Arends13-May-05 9:11
professionalPJ Arends13-May-05 9:11 
GeneralVS 6.0 - service pack info Pin
john john mackey5-May-05 10:23
john john mackey5-May-05 10:23 
GeneralRe: VS 6.0 - service pack info Pin
Kevin McFarlane5-May-05 10:30
Kevin McFarlane5-May-05 10:30 
GeneralRe: VS 6.0 - service pack info Pin
Anonymous5-May-05 10:43
Anonymous5-May-05 10:43 
GeneralRe: VS 6.0 - service pack info Pin
Kevin McFarlane5-May-05 12:05
Kevin McFarlane5-May-05 12:05 
GeneralRe: VS 6.0 - service pack info Pin
David Crow6-May-05 4:25
David Crow6-May-05 4:25 
GeneralSound Led Pin
RickyC5-May-05 9:26
RickyC5-May-05 9:26 
GeneralRe: Sound Led Pin
Ravi Bhavnani5-May-05 10:07
professionalRavi Bhavnani5-May-05 10:07 
GeneralRe: Sound Led Pin
RickyC5-May-05 10:09
RickyC5-May-05 10:09 
QuestionHow to change the different view in the CSplitterWnd Pin
wwwht5-May-05 9:03
wwwht5-May-05 9:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.