There is an example in:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cscon/html/vclrfcodeprintingformvisualc.asp
for printing a form in C#:
[System.Runtime.InteropSer
vices.DllI
mport("gdi
32.dll")]
public static extern long BitBlt (IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage;
private void CaptureScreen()
{
Graphics mygraphics = this.CreateGraphics();
Size s = this.Size;
memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryI
mage);
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width
, this.ClientRectangle.Heigh
t, dc1, 0, 0, 13369376);
mygraphics.ReleaseHdc(dc1)
;
memoryGraphics.ReleaseHdc(
dc2);
}
private void printDocument1_PrintPage(S
ystem.Obje
ct sender, System.Drawing.Printing.Pr
intPageEve
ntArgs e)
{
e.Graphics.DrawImage(memor
yImage, 0, 0);
}
private void printButton_Click(System.O
bject sender, System.EventArgs e)
{
CaptureScreen();
printDocument1.Print();
}
Can anybody translate this code into Visual C++ .NET? Thanks in advance.
--------------------------
public:
[System::Runtime::InteropS
static long BitBlt (IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private:
System::Drawing::Bitmap *memoryImage;
private:
void CaptureScreen()
{
Graphics *mygraphics = this->CreateGraphics();
System::Drawing::Size s = this->Size;
memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
Graphics *memoryGraphics = Graphics::FromImage(memory
IntPtr dc1 = mygraphics->GetHdc();
IntPtr dc2 = memoryGraphics->GetHdc();
BitBlt(dc2, 0, 0, this->ClientRectangle.Widt
mygraphics->ReleaseHdc(dc1
memoryGraphics->ReleaseHdc
}
private:
System::Void button1_Click(System::Obje
{
CaptureScreen();
printDocument1->Print();
}
private:
System::Void printDocument1_PrintPage(S
{
e->Graphics->DrawImage(mem
}
};