If the network printer is selected as the default device, why not just print normally?
Printing (as far as I know using win32 api, which I know you don't want to use) involves the evokation of a standard dialogue box in which the use gets to choose the printing device as well as many other attributes.
Clinton Portis
Practically a Posting Shark
833 posts since Oct 2005
Reputation Points: 237
Solved Threads: 118
It's 1:12am and I am wicked tired, but here is a link that will give you an overview of what you are about to get into if you choose to pursue the win32 api route:
http://en.allexperts.com/q/C-1040/Setting-Printer.htm
Other possible solutions may involve usb level programming (which I know just enough to be dangerous)
If you decide to go with win32 api, I'll break out the win32 bible tomorrow and come up with a simple code to print something.
Clinton Portis
Practically a Posting Shark
833 posts since Oct 2005
Reputation Points: 237
Solved Threads: 118
Here is just a very simplified taste o' win32 printer basics.
(based on pg. #633 - 637, "Programming Windows, 5th Edition. Petzold.) Simplified and translasted to c++ by me.
This code is based on a flowchart describing typical print routine (pg. #639, Petzold):SetAbortDoc
StartDoc
StartPage
Print 1 page
EndPage
User abort Printing?
Document Completed?
EndDoc
For simplicity I omitted the abort procedure:
int yChar = 0;
int iCharsPerLine = 0;
int iTotalPages = 0;
PTSTR ptstrBuffer;
TEXTMETRIC tm;
DOCINFO di;
PRINTDLG pd;
//Set Doc Info
di = {sizeof(DOCINFO), TEXT("My Print App, yo'.")};
//Set commong print dialog box attributes
pd.lStructSize = sizeof(PRINTDLG);
pd.hwndOwner = hwnd;
pd.hDevMode = NULL;
pd.hDevNames = NULL:
pd.hDC = NULL:
pd.Flags = PD_ALLPAGES | PD_COLLATE | PD_RETURNDC | PD_NOSELECTION;
pd.nFromPage = 0;
pd.nToPage = 0;
pd.nMinPage = 0;
pd.nMaxPage = 0;
pd.nCopies = 1;
pd.hInstance = NULL;
pd.iCustData = 0;
pd.lpfnPrintHook = NULL;
pd.lpfnSetupHook = NULL;
pd.lpfnPrintTemplateName = NULL;
pd.lpfnSetupTemplateName = NULL:
pd.hPrintTemplate = NULL;
pd. hSetupTemplate = NULL;
//Display Standard Print Dialog
PrntDlg(&pd);
//Calculate necessary metrics for file
GetTextMetrics(pd.hDC, &tm);
yChar = tm.tmHeight + tm. tmExternalLeading;
iCharsPerLine = GetDeviceCaps(pd.hDC, HORZRES) / tm.tmAveCharWidth;
iLnesPerPage = GetDeviceCaps(pd.hDC, VERTRES) / yChar;
iTotalPages = (iTotalLines + iLinesPerPage - 1) / iLinesPerPage;
//Allocate a buffer for each line of text
ptstrBuffer = new TCHAR[iCharsPerLine + 1];
// **Here is where the real printing work begins**
//Start Document
StartDoc(pd.hDC, &di);
//Print pages
for(int i=0; i<pd.nCopies; i++)
{
//Start Page
if(StartPage(pd.hDC) < 0)
{
break;
}
//Print lines of each page
for(int i=0; i < iLinesPerPage; i++)
{
iLineNum = iLinesPerPage * iPage + iLine;
if(iLineNum > iTotalLines)
{
break;
}
static_cast<int*> pstrBuffer = iCharsPerLine;
//Here is where the print command is sent to the printer.
//For this secenario, we are printing text from a multi-line edit control
//(like notepad for example)
//hwndEdit will be the ID handle for the edit control...
//Although not shown here, this handle was probably obtained using CreateWindow()
TextOut(pd.hDC, 0, yChar * iLine, pstrBuffer,
(int)SendMessage(hwndEdit, EM_GETLINE,
(WPARAM) iLineNum, (LPARAM) ptstrBuffer));
//End Page
if(EndPage(pd.hDC) < 0)
{
break;
}
}
}
//Clean-up
delete ptstrBuffer;
DeleteDC(pd, hDC);
Clinton Portis
Practically a Posting Shark
833 posts since Oct 2005
Reputation Points: 237
Solved Threads: 118