RichTextBox PrintWindow -- let's get real


W

WoodBeeProgrammer

How come everybody on this newsgroup answers easy questions but not hard
questions?

Does PrintWindow work with RichTextBox? If not, WHY NOT? And if not,
what's the workaround?

TIA


[DllImport ("User32.dll")]
public extern static bool PrintWindow (System.IntPtr hWnd, System.IntPtr dc,
uint reservedFlag);

System.IntPtr hwnd = rtf.Handle;
Bitmap bm = new Bitmap (rtf.Size.Width, rtf.Size.Height);
if (bm != null)
{
using (Graphics g = Graphics.FromImage (bm))
{
if (g == null) return null;
System.IntPtr bmDC = g.GetHdc ();
bool ok = PrintWindow (hwnd, bmDC, 0); // RETURNS FALSE-- WHY?????
g.ReleaseHdc (bmDC);
}
}
return bm;
 
Ad

Advertisements

R

Rami Saad

class Test {
delegate bool CallBack(int hWnd, int lParam);
[DllImport("user32.dll")]
static extern int EnumWindows(CallBack hWnd, int lParam);
static bool PrintWindow(int hWnd, int lParam) {
Console.WriteLine(hWnd);
return true;
}
static void Main() {
CallBack e = new CallBack(PrintWindow);
EnumWindows(e, 0);
}
}
 
Ad

Advertisements

W

WoodBeeProgrammer

Rami, thanks for answering this post, i don't understand what i should do
with the class Test. I'm trying to use the PrintWindow function defined in
User32.dll to render the contents of a RichTextBox offscreen.



Rami Saad said:
class Test {
delegate bool CallBack(int hWnd, int lParam);
[DllImport("user32.dll")]
static extern int EnumWindows(CallBack hWnd, int lParam);
static bool PrintWindow(int hWnd, int lParam) {
Console.WriteLine(hWnd);
return true;
}
static void Main() {
CallBack e = new CallBack(PrintWindow);
EnumWindows(e, 0);
}
}

--
Rami Saad
Microsoft GTSC Developer support for Middle East


WoodBeeProgrammer said:
How come everybody on this newsgroup answers easy questions but not hard
questions?

Does PrintWindow work with RichTextBox? If not, WHY NOT? And if not,
what's the workaround?

TIA


[DllImport ("User32.dll")]
public extern static bool PrintWindow (System.IntPtr hWnd, System.IntPtr dc,
uint reservedFlag);

System.IntPtr hwnd = rtf.Handle;
Bitmap bm = new Bitmap (rtf.Size.Width, rtf.Size.Height);
if (bm != null)
{
using (Graphics g = Graphics.FromImage (bm))
{
if (g == null) return null;
System.IntPtr bmDC = g.GetHdc ();
bool ok = PrintWindow (hwnd, bmDC, 0); // RETURNS FALSE-- WHY?????
g.ReleaseHdc (bmDC);
}
}
return bm;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top