Click here to Skip to main content
16,014,705 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CreateWindow from DLL Pin
User 66584-Apr-02 10:26
User 66584-Apr-02 10:26 
GeneralRe: CreateWindow from DLL Pin
Joaquín M López Muñoz4-Apr-02 10:23
Joaquín M López Muñoz4-Apr-02 10:23 
GeneralRe: CreateWindow from DLL Pin
Jeremy Falcon4-Apr-02 10:23
professionalJeremy Falcon4-Apr-02 10:23 
GeneralRe: CreateWindow from DLL Pin
Tim Smith4-Apr-02 11:53
Tim Smith4-Apr-02 11:53 
GeneralCImageList + BitBlt Pin
4-Apr-02 8:15
suss4-Apr-02 8:15 
GeneralRe: CImageList + BitBlt Pin
Shog94-Apr-02 9:15
sitebuilderShog94-Apr-02 9:15 
GeneralRe: CImageList + BitBlt Pin
4-Apr-02 9:39
suss4-Apr-02 9:39 
GeneralCPrintDialog Pin
Rick Crone4-Apr-02 8:14
Rick Crone4-Apr-02 8:14 
I want to specify a ‘default’ printer that may not be the Windows users default printer when the print dialog executes.

This code works, but I am concerned about a few of areas.

1.) See where I’m using the cp variable to update the printer name? Could this code overwrite memory beyond the area allocated for the printer name?

2.) Notes from the HELP file indicate I should free the DC. Do I need to do that? How would I do it?

3.) I’m saving and restoring flags to get the print dialog to display. I bet there is a better solution to that problem, what is it?



CPrintDialog dlg(FALSE,
PD_ALLPAGES |
PD_HIDEPRINTTOFILE |
PD_NOPAGENUMS |
PD_RETURNDC |
PD_USEDEVMODECOPIES);


/*
We are saving the current Flags here so we can put them back after the call
to GetDefaults()... calls to DoModal() will not pop the dialog unlesss we
do this.
rgc
*/
DWORD save_flags = dlg.m_pd.Flags;
dlg.GetDefaults();


/* **** from the HELP files ****
Note that when you call the constructor with bPrintSetupOnly set to FALSE,
the PD_RETURNDC flag is automatically used. After calling DoModal,
GetDefaults, or GetPrinterDC, a printer DC will be returned in m_pd.hDC.
This DC must be freed by the caller of CPrintDialog.
*/


LPDEVNAMES lpDev = (LPDEVNAMES)::GlobalLock(dlg.m_pd.hDevNames);

// next line is test code to get the current printer
//LPCTSTR lpszDevice = (LPCTSTR)lpDev + lpDev->wDeviceOffset;

char *cp = (char *)lpDev + lpDev->wDeviceOffset;

CString def_prn = "\\\\MCL002NT\\CLIREQ";
strcpy(cp,def_prn);

// next line is test code to check to see that the printer has changed
//lpszDevice = (LPCTSTR)lpDev + lpDev->wDeviceOffset;

/*
Restore the saved flags so we can pop the dialog with DoModal().
rgc
*/
dlg.m_pd.Flags = save_flags;//PD_RETURNDEFAULT = FALSE;


::GlobalUnlock(dlg.m_pd.hDevNames);

dlg.DoModal()
// - - - - - - - - - - - - -


Rick Crone
GeneralRe: CPrintDialog Pin
Shog94-Apr-02 9:42
sitebuilderShog94-Apr-02 9:42 
GeneralRe: CPrintDialog Pin
Rick Crone4-Apr-02 11:28
Rick Crone4-Apr-02 11:28 
GeneralRe: CPrintDialog Pin
Shog94-Apr-02 12:26
sitebuilderShog94-Apr-02 12:26 
GeneralRe: CPrintDialog Pin
Rick Crone9-Apr-02 4:13
Rick Crone9-Apr-02 4:13 
GeneralRe: CPrintDialog Pin
Shog99-Apr-02 5:18
sitebuilderShog99-Apr-02 5:18 
GeneralRe: CPrintDialog Pin
Rick Crone9-Apr-02 6:21
Rick Crone9-Apr-02 6:21 
GeneralRe: CPrintDialog Pin
Shog99-Apr-02 7:27
sitebuilderShog99-Apr-02 7:27 
GeneralRe: CPrintDialog Pin
Rick Crone9-Apr-02 7:43
Rick Crone9-Apr-02 7:43 
Generalpointer to a function Pin
moredip4-Apr-02 8:07
moredip4-Apr-02 8:07 
GeneralRe: pointer to a function Pin
Tim Smith4-Apr-02 8:08
Tim Smith4-Apr-02 8:08 
GeneralRe: pointer to a function Pin
moredip4-Apr-02 8:24
moredip4-Apr-02 8:24 
GeneralRe: pointer to a member function Pin
Paul M Watt4-Apr-02 8:22
mentorPaul M Watt4-Apr-02 8:22 
GeneralRe: pointer to a function Pin
moredip4-Apr-02 8:31
moredip4-Apr-02 8:31 
GeneralXor function Pin
Mazdak4-Apr-02 5:56
Mazdak4-Apr-02 5:56 
GeneralRe: Xor function Pin
Tomasz Sowinski4-Apr-02 6:01
Tomasz Sowinski4-Apr-02 6:01 
GeneralRe: Xor function Pin
Mazdak4-Apr-02 6:37
Mazdak4-Apr-02 6:37 
GeneralCListCtrl GetSelectionMark() probs Pin
dazinith4-Apr-02 4:47
dazinith4-Apr-02 4:47 

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.