// ***********************************************************************
// Assembly : HZH_Controls
// Created : 08-08-2019
//
// ***********************************************************************
//
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
//
//
// Blog: https://www.cnblogs.com/bfyx
// GitHub:https://github.com/kwwwvagaa/NetWinformControl
// gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
//
// If you use this code, please keep this note.
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace HZH_Controls.Controls
{
///
/// Class win32.
///
public class win32
{
///
/// The wm mousemove
///
public const int WM_MOUSEMOVE = 0x0200;
///
/// The wm lbuttondown
///
public const int WM_LBUTTONDOWN = 0x0201;
///
/// The wm lbuttonup
///
public const int WM_LBUTTONUP = 0x0202;
///
/// The wm rbuttondown
///
public const int WM_RBUTTONDOWN = 0x0204;
///
/// The wm lbuttondblclk
///
public const int WM_LBUTTONDBLCLK = 0x0203;
///
/// The wm mouseleave
///
public const int WM_MOUSELEAVE = 0x02A3;
///
/// The wm paint
///
public const int WM_PAINT = 0x000F;
///
/// The wm erasebkgnd
///
public const int WM_ERASEBKGND = 0x0014;
///
/// The wm print
///
public const int WM_PRINT = 0x0317;
//const int EN_HSCROLL = 0x0601;
//const int EN_VSCROLL = 0x0602;
///
/// The wm hscroll
///
public const int WM_HSCROLL = 0x0114;
///
/// The wm vscroll
///
public const int WM_VSCROLL = 0x0115;
///
/// The em getsel
///
public const int EM_GETSEL = 0x00B0;
///
/// The em lineindex
///
public const int EM_LINEINDEX = 0x00BB;
///
/// The em linefromchar
///
public const int EM_LINEFROMCHAR = 0x00C9;
///
/// The em posfromchar
///
public const int EM_POSFROMCHAR = 0x00D6;
///
/// Posts the message.
///
/// The HWND.
/// The MSG.
/// The w parameter.
/// The l parameter.
/// true if XXXX, false otherwise.
[DllImport("USER32.DLL", EntryPoint = "PostMessage")]
public static extern bool PostMessage(IntPtr hwnd, uint msg,
IntPtr wParam, IntPtr lParam);
/*
BOOL PostMessage( HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
*/
// Put this declaration in your class //IntPtr
///
/// Sends the message.
///
/// The HWND.
/// The MSG.
/// The w parameter.
/// The l parameter.
/// System.Int32.
[DllImport("USER32.DLL", EntryPoint = "SendMessage")]
public static extern int SendMessage(IntPtr hwnd, int msg, IntPtr wParam,
IntPtr lParam);
///
/// Gets the caret blink time.
///
/// System.UInt32.
[DllImport("USER32.DLL", EntryPoint = "GetCaretBlinkTime")]
public static extern uint GetCaretBlinkTime();
///
/// The wm printclient
///
const int WM_PRINTCLIENT = 0x0318;
///
/// The PRF checkvisible
///
const long PRF_CHECKVISIBLE = 0x00000001L;
///
/// The PRF nonclient
///
const long PRF_NONCLIENT = 0x00000002L;
///
/// The PRF client
///
const long PRF_CLIENT = 0x00000004L;
///
/// The PRF erasebkgnd
///
const long PRF_ERASEBKGND = 0x00000008L;
///
/// The PRF children
///
const long PRF_CHILDREN = 0x00000010L;
///
/// The PRF owned
///
const long PRF_OWNED = 0x00000020L;
/* Will clean this up later doing something like this
enum CaptureOptions : long
{
PRF_CHECKVISIBLE= 0x00000001L,
PRF_NONCLIENT = 0x00000002L,
PRF_CLIENT = 0x00000004L,
PRF_ERASEBKGND = 0x00000008L,
PRF_CHILDREN = 0x00000010L,
PRF_OWNED = 0x00000020L
}
*/
///
/// Captures the window.
///
/// The control.
/// The bitmap.
/// true if XXXX, false otherwise.
public static bool CaptureWindow(System.Windows.Forms.Control control,
ref System.Drawing.Bitmap bitmap)
{
//This function captures the contents of a window or control
Graphics g2 = Graphics.FromImage(bitmap);
//PRF_CHILDREN // PRF_NONCLIENT
int meint = (int)(PRF_CLIENT | PRF_ERASEBKGND); //| PRF_OWNED ); // );
System.IntPtr meptr = new System.IntPtr(meint);
System.IntPtr hdc = g2.GetHdc();
win32.SendMessage(control.Handle, win32.WM_PRINT, hdc, meptr);
g2.ReleaseHdc(hdc);
g2.Dispose();
return true;
}
}
}