using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Text;
namespace ScreenCap
{
public sealed class API
{
[DllImport("USER32.DLL", EntryPoint= "PostMessage")]
public static extern bool PostMessage(IntPtr hwnd, uint msg,
IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("gdi32.dll")]
public static extern int SetBkColor(
IntPtr hdc, // handle to DC
int crColor // background color value
);
[DllImport("gdi32.dll")]
public static extern int GetBkColor(IntPtr hdc);
[DllImport("user32.dll",EntryPoint="GetDC")]
public static extern IntPtr GetDC(IntPtr ptr);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr GetDesktopWindow();
[DllImport("user32")]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter,
int x, int y, int cx, int cy, int flags);
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
internal static extern int MapWindowPoints(IntPtr hWndFrom, IntPtr hWndTo, ref Point pt, int cPoints);
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern IntPtr GetWindowDC(IntPtr hwnd);
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern int ReleaseDC(IntPtr hWnd,IntPtr hDC);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int RegisterWindowMessage(string msg);
[DllImport("gdi32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern bool BitBlt(IntPtr hDC, int x, int y, int nWidth, int nHeight, IntPtr hSrcDC, int xSrc, int ySrc, int dwRop);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr DefWindowProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
[DllImport("ole32.dll", PreserveSig=false)]
public static extern IntPtr CreateILockBytesOnHGlobal(IntPtr hGlobal, bool fDeleteOnRelease);
// public static extern ILockBytes CreateILockBytesOnHGlobal(IntPtr hGlobal, bool fDeleteOnRelease);
// [DllImport("ole32.dll", PreserveSig=false)]
// public static extern IntPtr StgCreateDocfileOnILockBytes(IntPtr iLockBytes, STGM grfMode, int reserved);
// public static extern IStorage StgCreateDocfileOnILockBytes(ILockBytes iLockBytes, STGM grfMode, int reserved);
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern int SendMessage(IntPtr hWnd, int message, IntPtr wParam, IntPtr lParam);
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool GetWindowRect( IntPtr hWnd,ref Rectangle lpRect);
[DllImport("user32.dll")]
public static extern IntPtr GetSystemMenu(IntPtr hwnd, bool bRevert);
[DllImport("USER32.DLL")]
public static extern int SendMessage(
IntPtr hwnd,
int wMsg,
int wParam,
IntPtr lParam
);
[DllImport("USER32.DLL")]
public static extern int SendMessage(
IntPtr hwnd,
int wMsg,
int wParam,
StringBuilder lParam
);
[DllImport("USER32.DLL")]
public static extern int SendMessage(
IntPtr hwnd,
int wMsg,
int wParam,
string lParam
);
[DllImport("USER32.DLL")]
public static extern int SendMessage(
IntPtr hwnd,
int wMsg,
bool wParam,
string lParam
);
[DllImport("USER32.DLL")]
public static extern int SendMessage(
IntPtr hwnd,
int wMsg,
bool wParam,
int lParam
);
#region
public const int SRCCOPY =0x00CC0020; /* dest = source */
public const int SRCPAINT =0x00EE0086; /* dest = source OR dest */
public const int SRCAND =0x008800C6; /* dest = source AND dest */
public const int SRCINVERT =0x00660046; /* dest = source XOR dest */
public const int SRCERASE =0x00440328; /* dest = source AND (NOT dest ) */
public const int NOTSRCCOPY =0x00330008; /* dest = (NOT source) */
public const int NOTSRCERASE =0x001100A6; /* dest = (NOT src) AND (NOT dest) */
public const int MERGECOPY =0x00C000CA; /* dest = (source AND pattern) */
public const int MERGEPAINT =0x00BB0226; /* dest = (NOT source) OR dest */
public const int PATCOPY =0x00F00021; /* dest = pattern */
public const int PATPAINT =0x00FB0A09; /* dest = DPSnoo */
public const int PATINVERT =0x005A0049; /* dest = pattern XOR dest */
public const int DSTINVERT =0x00550009; /* dest = (NOT dest) */
public const int BLACKNESS =0x00000042; /* dest = BLACK */
public const int WHITENESS =0x00FF0062; /* dest = WHITE */
static int wm_mouseenter=-1;
public static int WM_MOUSEENTER
{
get
{
if (wm_mouseenter == -1)
{
wm_mouseenter =RegisterWindowMessage("WinFormsMouseEnter");
}
return wm_mouseenter;
}
}
public const int EM_GETOLEINTERFACE = WM_USER + 60;
public const int SC_MOVE =0xF010;
/*
* WM_NCHITTEST and MOUSEHOOKSTRUCT Mouse Position Codes
*/
public const int HTERROR =(-2);
public const int HTTRANSPARENT =(-1);
// public const int HTNOWHERE = 0;
// public const int HTCLIENT =1;
public const int HTCAPTION = 2;
public const int HTSYSMENU = 3;
public const int HTGROWBOX = 4;
public const int HTSIZE = HTGROWBOX;
public const int HTMENU = 5;
public const int HTHSCROLL = 6;
public const int HTVSCROLL = 7;
public const int HTMINBUTTON = 8;
public const int HTMAXBUTTON =9;
public const int HTLEFT = 10;
public const int HTRIGHT =11;
public const int HTTOP =12;
public const int HTTOPLEFT = 13;
public const int HTTOPRIGHT = 14;
public const int HTBOTTOM = 15;
public const int HTBOTTOMLEFT = 16;
public const int HTBOTTOMRIGHT = 17;
public const int HTBORDER = 18;
public const int HTCLOSE = 20;
public const int HTHELP = 21;
/*
* WM_NCHITTEST and MOUSEHOOKSTRUCT Mouse Position Codes
*/
/*
#define HTERROR (-2)
#define HTTRANSPARENT (-1)
#define HTNOWHERE 0
#define HTCLIENT 1
#define HTCAPTION 2
#define HTSYSMENU 3
#define HTGROWBOX 4
#define HTSIZE HTGROWBOX
#define HTMENU 5
#define HTHSCROLL 6
#define HTVSCROLL 7
#define HTMINBUTTON 8
#define HTMAXBUTTON 9
#define HTLEFT 10
#define HTRIGHT 11
#define HTTOP 12
#define HTTOPLEFT 13
#define HTTOPRIGHT 14
#define HTBOTTOM 15
#define HTBOTTOMLEFT 16
#define HTBOTTOMRIGHT 17
#define HTBORDER 18
#define HTREDUCE HTMINBUTTON
#define HTZOOM HTMAXBUTTON
#define HTSIZEFIRST HTLEFT
#define HTSIZELAST HTBOTTOMRIGHT
#if(WINVER >= 0x0400)
#define HTOBJECT 19
#define HTCLOSE 20
#define HTHELP 21
#endif /* WINVER >= 0x0400 */