Click here to Skip to main content
15,898,036 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Create random garbage in the form of a string? Pin
carrie5-Jan-03 12:54
carrie5-Jan-03 12:54 
AnswerRe: Create random garbage in the form of a string? Pin
Taka Muraoka5-Jan-03 13:02
Taka Muraoka5-Jan-03 13:02 
GeneralRe: Create random garbage in the form of a string? Pin
RobJones5-Jan-03 13:13
RobJones5-Jan-03 13:13 
GeneralRe: Create random garbage in the form of a string? Pin
carrie5-Jan-03 14:11
carrie5-Jan-03 14:11 
GeneralRe: Create random garbage in the form of a string? Pin
Taka Muraoka5-Jan-03 14:41
Taka Muraoka5-Jan-03 14:41 
GeneralCompiler crashing template Pin
Ben Burnett5-Jan-03 12:31
Ben Burnett5-Jan-03 12:31 
GeneralNever mind, I fixed it. Pin
Ben Burnett5-Jan-03 12:42
Ben Burnett5-Jan-03 12:42 
GeneralSetting HP LaserJet to manual feed Pin
redouglass5-Jan-03 11:51
redouglass5-Jan-03 11:51 
I have an old HP LaserJet 4 printer, which is a wonderfully reliable old piece of iron they will
probably bury with me. Under DOS I knew how to write code to put it in manual feed mode so I
could print envelopes fed into the manual feed bin. Now I am trying to figure out how to do so
using Microsoft VC++ under Windows (98, ME, 2000, and XP). I have written a short test procedure
(see TestPrint below), which does print the desired text but does not switch to the manual feed
bin as it I intended. The test procedure calls a function (HaveCapability) to test whether manual
feed is available and the fuction correctly determines that it is.

I would greatly appreciate any help you can give me in solving this problem.

//*********************************************************************************
void TestPrint()
{
// Instantiate a CPrintDialog.
CPrintDialog *printDlg = new CPrintDialog(FALSE, PD_ALLPAGES | PD_RETURNDC, NULL);
printDlg->GetDefaults();

//Set up to see if printer has a manual feed mode (pDevMode->dmDefaultSource == DMBIN_MANUAL)
LPDEVMODE pDevMode = NULL;
WORD nOldDefaultSource;
BOOL bHaveCapability = HaveCapability(printDlg->GetDeviceName(), printDlg->GetPortName(), DMBIN_MANUAL);

//If printer has a manual feed mode, select it
if (bHaveCapability == TRUE)
{
pDevMode = printDlg->GetDevMode();
nOldDefaultSource = pDevMode->dmDefaultSource;
pDevMode->dmDefaultSource = DMBIN_MANUAL;
}

// Obtain handle to the device context.
HDC hdcPrn = printDlg->GetPrinterDC();
if (hdcPrn == NULL)
{
delete printDlg;
return;
}
CDC* pDC = new CDC;
pDC->Attach(hdcPrn); // attach handle to a printer DC

pDC->StartDoc("Test print job");// begin a new print job

//Set the font
int nPointSizeX10 = 140;
CFont fntCurrent;
fntCurrent.CreatePointFont(nPointSizeX10, "Times New Roman", pDC);
CFont* pOldFont = pDC->SelectObject(&fntCurrent);

//Get the line height
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
int nLineHeight = tm.tmHeight + tm.tmInternalLeading;

//Specify where to print on page
int nLineX = 10;
int nLineY = 10;

pDC->StartPage(); // begin a new page

//Create and print the test text
CString csTestText;
for (int i = 0; i < 4; i++)
{
csTestText.Format("Line %i", i + 1);

pDC->TextOut(nLineX, nLineY, csTestText);
nLineY += nLineHeight;
}

pDC->EndPage(); // end a page

pDC->SelectObject(pOldFont);//Restore font

pDC->EndDoc(); // end a print job

//Restore original paper source
if (bHaveCapability == TRUE)
{
pDevMode->dmDefaultSource = nOldDefaultSource;
}

pDC->Detach(); // detach the printer DC
delete pDC;
delete printDlg;
}

//***********************************************************************************
/* Notes on HaveCapability

HaveCapability calls DeviceCapabilities to determine whether specified capability is available.
The following is from the MSDN library regarding use of DeviceCapabilities.

DWORD DeviceCapabilities(
LPCTSTR pDevice, // printer name
LPCTSTR pPort, // port name
DC_BINS, // device capability
LPTSTR pOutput, // output buffer
CONST DEVMODE *pDevMode); // device data buffer

Retrieves a list of available paper bins. The pOutput buffer receives an array of WORD values
that indicate the available paper sources for the printer. The return value indicates the number
of entries in the array. For a list of the possible array values, see the description of the
dmDefaultSource member of the DEVMODE structure. If pOutput is NULL, the return value indicates
the required number of entries in the array.

Possible WORD values
DMBIN_ONLYONE
DMBIN_LOWER
DMBIN_MIDDLE
DMBIN_MANUAL
DMBIN_ENVELOPE
DMBIN_ENVMANUAL
DMBIN_AUTO
DMBIN_TRACTOR
DMBIN_SMALLFMT
DMBIN_LARGEFMT
DMBIN_LARGECAPACITY
DMBIN_CASSETTE
DMBIN_FORMSOURCE
*/
BOOL HaveCapability(CString csDeviceName, CString csPortName, WORD nCapabilityToTest)
{
WORD pOutput[64];//Should be big enough

DWORD nNumEntries = DeviceCapabilities(
csDeviceName,
csPortName,
DC_BINS,
(char*)pOutput,
NULL);

if (nNumEntries != -1)
{
for (DWORD i = 0; i < nNumEntries; i++)
{
if (pOutput[i] == nCapabilityToTest)
return TRUE;
}
}

return FALSE;
}

GeneralStuck: CString to char Pin
Matt Newman5-Jan-03 11:42
Matt Newman5-Jan-03 11:42 
GeneralRe: Stuck: CString to char Pin
Matt Gullett5-Jan-03 12:10
Matt Gullett5-Jan-03 12:10 
GeneralRe: Stuck: CString to char Pin
Matt Newman5-Jan-03 12:37
Matt Newman5-Jan-03 12:37 
GeneralRe: Stuck: CString to char Pin
carrie5-Jan-03 12:44
carrie5-Jan-03 12:44 
GeneralRe: Stuck: CString to char Pin
Matt Newman5-Jan-03 14:09
Matt Newman5-Jan-03 14:09 
GeneralRe: Stuck: CString to char Pin
Matt Gullett5-Jan-03 12:45
Matt Gullett5-Jan-03 12:45 
GeneralRe: Stuck: CString to char Pin
Matt Newman5-Jan-03 14:12
Matt Newman5-Jan-03 14:12 
GeneralRe: Stuck: CString to char Pin
RobJones5-Jan-03 12:50
RobJones5-Jan-03 12:50 
GeneralRe: Stuck: CString to char Pin
Matt Newman5-Jan-03 14:16
Matt Newman5-Jan-03 14:16 
GeneralRe: Stuck: CString to char Pin
Michael Dunn5-Jan-03 15:42
sitebuilderMichael Dunn5-Jan-03 15:42 
GeneralRe: Stuck: CString to char Pin
Matt Gullett5-Jan-03 16:53
Matt Gullett5-Jan-03 16:53 
GeneralRe: Stuck: CString to char Pin
Matt Newman6-Jan-03 12:13
Matt Newman6-Jan-03 12:13 
GeneralRe: Stuck: CString to char Pin
nobitaplus2-Nov-09 13:49
nobitaplus2-Nov-09 13:49 
GeneralUse Resource to Load and Show images Pin
HellShrimp4free5-Jan-03 10:38
HellShrimp4free5-Jan-03 10:38 
GeneralRe: Use Resource to Load and Show images Pin
Michael Dunn5-Jan-03 10:49
sitebuilderMichael Dunn5-Jan-03 10:49 
GeneralRe: Use Resource to Load and Show images Pin
HellShrimp4free5-Jan-03 11:24
HellShrimp4free5-Jan-03 11:24 
GeneralRe: Use Resource to Load and Show images Pin
Michael Dunn5-Jan-03 11:39
sitebuilderMichael Dunn5-Jan-03 11:39 

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.