PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Compact Framework Printing with CF

Reply

Printing with CF

 
Thread Tools Rate Thread
Old 07-09-2006, 03:09 PM   #1
ackesa
Guest
 
Posts: n/a
Default Printing with CF


Hello,

I'm trying to print from an CF-Application on an usb-printer. I can
print a screenshot on the printer by using some API-Functions. But now
I'm trying to print my own Graphic (All Data of an DataTable; the
result should look like a datagrid). I've been starting with this code:

DEVMODE dm = new DEVMODE();

dm.dmSize = System.Convert.ToInt16(Marshal.SizeOf(dm));

dm.dmOrientation = (Int16)PageOrientation.DMORIENT_LANDSCAPE;

dm.dmPrintQuality = DMRES_DRAFT;

//IntPtr hPrinterDC = CreateDC(null, "PCL Inkjet", null, ref dm);

IntPtr hPrinterDC = CreateDC("pcl.dll", "PCL Inkjet", "LPT2", ref dm);

// --- 2--- mit DeviceContext Dokument Starten

//DOCINFO di = new DOCINFO();

//di.cbSize = Marshal.SizeOf(di);

//di.fwType = 0;

//di.lpszDocName = IntPtr.Zero; //
Marshal.StructureToPtr(@"\printdocument.txt", true);

//di.lpszOutput = IntPtr.Zero;//
Marshal.StructureToPtr(@"\printdocument.prn", true);

//di.lpszDataType = IntPtr.Zero;

//di.fwType = 0;

String lpszDocName = @"\Image.bmp";

String lpszOutput = @"\Image.prn";

String lbszDataType = "";

int cbMemSize = 20 + GetStringAllocSize(lpszDocName) +

GetStringAllocSize(lpszOutput) + GetStringAllocSize(lbszDataType);

IntPtr p = LocalAlloc(0x40, cbMemSize);

DOCINFO di = new DOCINFO();

di.cbSize = 20;

di.fwType = 0;

di.lpszDocName = new IntPtr(p.ToInt32() + 20);

di.lpszOutput = new IntPtr(di.lpszDocName.ToInt32() +
GetStringAllocSize(lpszDocName));

di.lpszDataType = IntPtr.Zero;

Marshal.StructureToPtr(lpszDocName, di.lpszDocName, false);

//Marshal.StructureToPtr(lpszOutput, di.lpszOutput, false);

if (StartDoc(hPrinterDC, ref di) > 0)

{

//--- 3 --- Graphic von Hdc erzeugen

//Graphics g = Graphics.FromHdc(hPrinterDC);

//--- 4 --- draw eg. a Text

g.DrawString("Hallo!",

new Font("Arial", 20, FontStyle.Regular),

new SolidBrush(Color.Black),

new RectangleF(20, 20, 20, 20));

//--- 5 --- StartPage

StartPage(hPrinterDC);

//TODO scale

//--- 6 --- EndPage

EndPage(hPrinterDC);

//--- 7 --- EndDocument

EndDoc(hPrinterDC);

//--- 8 --- CleanUp

g.Dispose();

}

DeleteDC(hPrinterDC);



The printer put's a sheet of paper, but doesn't print anything.

I also tried the following instead of g.DrawString (...)

String str = "Hello World!";

TextOut(hPrinterDC, 50, 140, 0, IntPtr.Zero, str, (ushort)str.Length,
IntPtr.Zero);



But this didn't work either.

What's wrong with my code? does anyone has an other idea?



Many thanks in advance,

Sabine

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off