Using CreateDC with user defined data
jeffg@iqpuucp.aa.iqsc.com
Monday, February 19, 1996
I am trying to create a printer device using user defined information.
My main default printer is an HP LaserJet, but I need to be able to
print to a second printer for certain data. After parsing, I am
getting the following strings.
CString sDeviceName = "HP DeskJet 1200C";
CString sDriverName = "HPDSKJET";
CString sOutputName = "LPT1:"
These are then used in the following way:
CDC dcPrint;
dcPrint.CreateDC( sDriverName, sDeviceName, sOutputName, NULL );
The CreateDC uses the following code:
_AFXWIN_INLINE BOOL CDC::CreateDC(LPCTSTR lpszDriverName,
LPCTSTR lpszDeviceName, LPCTSTR lpszOutput, const void* lpInitData)
{ return Attach(::CreateDC(lpszDriverName,
lpszDeviceName, lpszOutput, (const DEVMODE*)lpInitData)); }
Which calls the Attach:
BOOL CDC::Attach(HDC hDC)
{
ASSERT(m_hDC == NULL); // only attach once, detach on destroy
ASSERT(m_hAttribDC == NULL); // only attach to an empty DC
if (hDC == NULL)
return FALSE;
CHandleMap* pMap = afxMapHDC(TRUE); // create map if not exist
ASSERT(pMap != NULL);
pMap->SetPermanent(m_hDC = hDC, this);
SetAttribDC(m_hDC); // Default to same as output
return TRUE;
}
Which fails when the hDC is equal to NULL.
Any ideas what might be wrong here? I'm really under the gun to get
this working.
Niels Ull Jacobsen -- nuj@kruger.dk
Tuesday, February 20, 1996
>
>
> I am trying to create a printer device using user defined information.
> My main default printer is an HP LaserJet, but I need to be able to
> print to a second printer for certain data. After parsing, I am
> getting the following strings.
>
> CString sDeviceName = "HP DeskJet 1200C";
> CString sDriverName = "HPDSKJET";
> CString sOutputName = "LPT1:"
>
> These are then used in the following way:
>
> CDC dcPrint;
> dcPrint.CreateDC( sDriverName, sDeviceName, sOutputName, NULL );
>
> The CreateDC uses the following code:
[...]
Obviously, the call which fails is
::CreateDC(lpszDriverName, lpszDeviceName, lpszOutput, (const DEVMODE*)lpInitData);
Are you programming in Win32? In this case, read up on ::CreateDC. It
doesn't work like in 16 bit Windows.
You don't need the sOutputName, and the sDriverName should probably be NULL or
"WINSPOOL", depending on whether you're running under 95 or NT.
For some reason the MFC docs haven't been updated on this point.
> Any ideas what might be wrong here? I'm really under the gun to get
> this working.
--
Niels Ull Jacobsen, Kruger A/S
Everything stated herein is THE OFFICIAL POLICY of the entire Kruger
group and should be taken as legally binding in every respect. Pigs
will grow wings and fly.
Mark F. Fling -- mfling@mail.stratacorp.com
Wednesday, February 21, 1996
[Mini-digest: 2 responses]
>I am trying to create a printer device using user defined information.
>My main default printer is an HP LaserJet, but I need to be able to
>print to a second printer for certain data. After parsing, I am
>getting the following strings.
>
>CString sDeviceName = "HP DeskJet 1200C";
>CString sDriverName = "HPDSKJET";
>CString sOutputName = "LPT1:"
>
>These are then used in the following way:
>
>CDC dcPrint;
>dcPrint.CreateDC( sDriverName, sDeviceName, sOutputName, NULL );
Looks like you've transposed the sDeviceName and sDriverName in your
parse. I'll bet your printer name is HPDSKJET and the driver is "HP
DeskJet 1200C".
Probably a typing error during posting, but just in case....
-----From: "jeffg"
Yes, I read this where you put in WinSpool for win32. However, this
then uses the default printer. I need to be able to select an
alternative printer, possibly on an alternative port. (ie: one printer
for reports, one for checks).
| Вернуться в корень Архива
|