Issue with SyntaxEditor and handling of WM_PRINT

SyntaxEditor for Windows Forms Forum

Posted 10 years ago by Matt Whitfield
Version: 4.0.0280
Platform: .NET 2.0
Environment: Windows XP (32-bit)
Avatar
Hello, I am using a reasonably standard screen snapshot technique to get preview images of the syntax editors in a tab set. However, the syntax editor itself refuses to draw, whereas all other controls are fine.

Here is the code I added to the sample application to reproduce it...

        private const int WM_PRINT = 0X317;
        private const int PRF_CLIENT = 4;
        private const int PRF_NON_CLIENT = 2;
        private const int PRF_CHILDREN = 0X10;
        private const int COMBINED_PRINTFLAGS = PRF_CLIENT | PRF_CHILDREN | PRF_NON_CLIENT;

        [System.Runtime.InteropServices.DllImport("USER32.DLL")]
        private extern static int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, int lParam);

        public System.Drawing.Image TakeSnapshot(IntPtr WindowHandle, int ImageWidth, int ImageHeight)
        {
            System.Drawing.Image clsRet = new System.Drawing.Bitmap(ImageWidth, ImageHeight);
            System.Drawing.Graphics clsGraphics = System.Drawing.Graphics.FromImage(clsRet);
            IntPtr ptrHDC = clsGraphics.GetHdc();
            SendMessage(WindowHandle, WM_PRINT, ptrHDC, COMBINED_PRINTFLAGS);
            clsGraphics.ReleaseHdc(ptrHDC);
            clsGraphics.Dispose();
            return clsRet;
        }
And then, some code in a button.

            Image i = TakeSnapshot(editor.Handle, editor.Width, editor.Height);
            i.Save("C:\\editor.bmp", ImageFormat.Bmp);
            i = TakeSnapshot(documentOutlineTreeView.Handle, documentOutlineTreeView.Width, documentOutlineTreeView.Height);
            i.Save("C:\\treeView.bmp", ImageFormat.Bmp);
Note that editor.bmp ends up just black, wheras treeView.bmp shows the image of the tree view.

Comments (3)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Matt,

We use a custom double buffer so that may be why it doesn't get pulled in for that Windows Message. We don't currently handle WM_PRINT specifically either.

However there is another method on SyntaxEditor called Render that may be useful for you. You pass it a PaintEventArgs and it should render onto whichever Graphics is in that event args.


Actipro Software Support

Posted 10 years ago by Matt Whitfield
Avatar
I got it working by subclassing SyntaxEditor and adding the following code:

        protected override void OnPrint(System.Windows.Forms.PaintEventArgs e)
        {
            this.Render(e);
        }
I think it would be well worth adding that line of code into the next maintenance release, however!

Thanks.
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Matt,

Ok it's added for the next maintenance release.


Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 10 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.