Click here to Skip to main content
15,907,001 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
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 
Ok so here is the function that I have that is suppose to read values from the registry and setup the CPrintDialog with those values:
<br />
void CMainFrame::OnFileCheckPrintSetup() <br />
{<br />
	// Pull the values out of the registry.<br />
	DEVMODE *hDevMode;<br />
	UINT nl;<br />
	CString csDeviceName, csPortName, csDriverName;<br />
	theApp.GetProfileBinary("CheckPrinter", "DevMode",  (LPBYTE*)&hDevMode, &nl);<br />
	theApp.GetProfileString("CheckPrinter", "DeviceName",  csDeviceName);<br />
	theApp.GetProfileString("CheckPrinter", "PortName",  csPortName);<br />
	theApp.GetProfileString("CheckPrinter", "DriverName",  csDriverName);<br />
<br />
	CPrintDialog dlg(TRUE);<br />
	LPDEVMODE pDM;<br />
	HGLOBAL hDEVNAMES;<br />
	HGLOBAL hDEVMODE;<br />
	BOOL bLoadedData=FALSE;<br />
<br />
	if(!csDeviceName.IsEmpty()&&!csPortName.IsEmpty()&&!csDriverName.IsEmpty())<br />
	{<br />
		bLoadedData=TRUE;<br />
<br />
		// Setup the values for the print setup dialog.<br />
		pDM = hDevMode;<br />
		int size = sizeof(DEVMODE);<br />
		hDEVMODE = GlobalAlloc(GHND, size);<br />
		void *pV = GlobalLock(hDEVMODE);<br />
		memcpy(pV, pDM, size);<br />
		GlobalUnlock(pV);<br />
		delete pDM;<br />
		pDM = NULL;<br />
		<br />
		size = sizeof(DEVNAMES);<br />
		size += (csDeviceName.GetLength() + 1) * sizeof(TCHAR);<br />
		size += (csPortName.GetLength() + 1) * sizeof(TCHAR);<br />
		size += (csDriverName.GetLength() + 1) * sizeof(TCHAR);<br />
		<br />
		hDEVNAMES = GlobalAlloc(GHND, size);<br />
		LPDEVNAMES pDN = (LPDEVNAMES)GlobalLock(hDEVNAMES);<br />
		pDN->wDefault = 0;<br />
		pDN->wDriverOffset = sizeof(DEVNAMES);<br />
		pDN->wDeviceOffset = (WORD)(pDN->wDriverOffset + csDriverName.GetLength() + 1);<br />
		pDN->wOutputOffset = (WORD)(pDN->wDeviceOffset + csDeviceName.GetLength() + 1);<br />
		_tcsncpy((TCHAR *)((int)pDN + pDN->wDriverOffset), csDriverName, csDriverName.GetLength());<br />
		_tcsncpy((TCHAR *)((int)pDN + pDN->wDeviceOffset), csDeviceName, csDeviceName.GetLength());<br />
		_tcsncpy((TCHAR *)((int)pDN + pDN->wOutputOffset), csPortName, csPortName.GetLength());<br />
		GlobalUnlock(pDN);<br />
<br />
		dlg.m_pd.hDevMode = hDEVMODE;<br />
		dlg.m_pd.hDevNames = hDEVNAMES;<br />
	}<br />
	<br />
<br />
	<br />
	if(dlg.DoModal()==IDOK)<br />
	{<br />
		// Write the values to the registry.<br />
		DEVMODE *dm=dlg.GetDevMode();<br />
		theApp.WriteProfileBinary("CheckPrinter", "DevMode",  (LPBYTE)dm, sizeof(DEVMODE));<br />
		theApp.WriteProfileString("CheckPrinter", "DeviceName",  (LPCTSTR) dlg.GetDeviceName());<br />
		theApp.WriteProfileString("CheckPrinter", "PortName",  (LPCTSTR) dlg.GetPortName());<br />
		theApp.WriteProfileString("CheckPrinter", "DriverName",  (LPCTSTR) dlg.GetDriverName());<br />
<br />
		if(bLoadedData)<br />
			GlobalUnlock(pDM);<br />
	}<br />
	else<br />
	{<br />
		if(bLoadedData)<br />
			GlobalFree(hDEVMODE);<br />
	}<br />
	<br />
	if(bLoadedData)<br />
	GlobalFree(hDEVNAMES);<br />
}<br />


It reads/saves them fine, the problem is that it isn't correctly setting up the CPrintDialog with the read in options. Am I missing something?
Thanks,
Chad
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 
AnswerRe: How to change the different view in the CSplitterWnd Pin
David Crow5-May-05 9:40
David Crow5-May-05 9:40 
GeneralUsing WinPCap Pin
sarmed5-May-05 8:04
sarmed5-May-05 8:04 
GeneralRe: Using WinPCap Pin
CodeBeetle26-May-05 6:50
CodeBeetle26-May-05 6:50 

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.