Posted 15 years ago
by Matt Whitfield
Version: 4.0.0280
Platform: .NET 2.0
Environment: Windows XP (32-bit)
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...And then, some code in a button.
Note that editor.bmp ends up just black, wheras treeView.bmp shows the image of the tree view.
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;
}
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);