RichTextBox PrintWindow -- let's get real

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • WoodBeeProgrammer

    RichTextBox PrintWindow -- let's get real

    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.FromIm age (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;


  • Rami Saad

    #2
    Re: RichTextBox PrintWindow -- let's get real

    class Test {
    delegate bool CallBack(int hWnd, int lParam);
    [DllImport("user 32.dll")]
    static extern int EnumWindows(Cal lBack hWnd, int lParam);
    static bool PrintWindow(int hWnd, int lParam) {
    Console.WriteLi ne(hWnd);
    return true;
    }
    static void Main() {
    CallBack e = new CallBack(PrintW indow);
    EnumWindows(e, 0);
    }
    }

    --
    Rami Saad
    Microsoft GTSC Developer support for Middle East


    "WoodBeeProgram mer" <WoodBeeProgram mer@spamex.com> wrote in message
    news:1077353565 .476826@utility .isomedia.com.. .[color=blue]
    > 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[/color]
    dc,[color=blue]
    > uint reservedFlag);
    >
    > System.IntPtr hwnd = rtf.Handle;
    > Bitmap bm = new Bitmap (rtf.Size.Width , rtf.Size.Height );
    > if (bm != null)
    > {
    > using (Graphics g = Graphics.FromIm age (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;
    >
    >[/color]


    Comment

    • WoodBeeProgrammer

      #3
      Re: RichTextBox PrintWindow -- let's get real

      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" <rami.saad@egds c.microsoft.com > wrote in message
      news:O7WwMpU#DH A.2064@TK2MSFTN GP11.phx.gbl...[color=blue]
      > class Test {
      > delegate bool CallBack(int hWnd, int lParam);
      > [DllImport("user 32.dll")]
      > static extern int EnumWindows(Cal lBack hWnd, int lParam);
      > static bool PrintWindow(int hWnd, int lParam) {
      > Console.WriteLi ne(hWnd);
      > return true;
      > }
      > static void Main() {
      > CallBack e = new CallBack(PrintW indow);
      > EnumWindows(e, 0);
      > }
      > }
      >
      > --
      > Rami Saad
      > Microsoft GTSC Developer support for Middle East
      >
      >
      > "WoodBeeProgram mer" <WoodBeeProgram mer@spamex.com> wrote in message
      > news:1077353565 .476826@utility .isomedia.com.. .[color=green]
      > > 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[/color]
      > dc,[color=green]
      > > uint reservedFlag);
      > >
      > > System.IntPtr hwnd = rtf.Handle;
      > > Bitmap bm = new Bitmap (rtf.Size.Width , rtf.Size.Height );
      > > if (bm != null)
      > > {
      > > using (Graphics g = Graphics.FromIm age (bm))
      > > {
      > > if (g == null) return null;
      > > System.IntPtr bmDC = g.GetHdc ();
      > > bool ok = PrintWindow (hwnd, bmDC, 0); // RETURNS FALSE--[/color][/color]
      WHY?????[color=blue][color=green]
      > > g.ReleaseHdc (bmDC);
      > > }
      > > }
      > > return bm;
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...