using System;
using System.Collections.Generic;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Text;
namespace WindowsApi
{
public class ApiMethod
{
#region Dll Import
[DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
[DllImport("User32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("User32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, IntPtr lParam);
[DllImport("user32.dll")]
public static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
/// <summary>
/// 獲得窗體大小 得到的矩形 為窗體起始 到結束的 坐標。
/// </summary>
/// <param name="hwnd">窗體句柄</param>
/// <param name="lpRect">裝數據的矩形對象</param>
/// <returns></returns>
[DllImport("user32.dll", EntryPoint = "GetWindowRect")]
public static extern int GetWindowRect(IntPtr hwnd, ref System.Drawing.Rectangle lpRect);
[DllImport("user32.dll", EntryPoint = "GetWindow")]
public static extern IntPtr GetWindow(IntPtr hwnd, int cmd);
/// <summary>
/// 獲得窗體 用戶區域大小 其他同 GetWindowRect
/// </summary>
/// <param name="hwnd"></param>
/// <param name="lpRect"></param>
/// <returns></returns>
[DllImport("user32.dll", EntryPoint = "GetClientRect")]
public static extern int GetClientRect(IntPtr hwnd, ref System.Drawing.Rectangle lpRect);
[DllImport("user32.dll", EntryPoint = "GetDlgItem")]
public static extern IntPtr GetDlgItem(IntPtr hwnd, int cmd);
/// <summary>
/// 通過全屏幕坐標獲取控件句柄
/// </summary>
/// <param name="w">坐標</param>
/// <returns>坐標位置的控件句柄</returns>
[DllImport("user32.dll", EntryPoint = "WindowFromPoint")]
public static extern IntPtr WindowFromPoint(Point w);
/// <summary>
/// 移動窗體的Windows函數
/// </summary>
/// <param name="hWnd">窗體句柄</param>
/// <param name="x">新坐標起點x坐標</param>
/// <param name="y">先坐標末點y坐標</param>
/// <param name="nWidth">新寬度</param>
/// <param name="nHeight">新高度</param>
/// <param name="BRePaint">是否移動後重繪制窗體(如果選false會導致桌面窗體圖像滯留)</param>
/// <returns></returns>
[DllImport("user32.dll", EntryPoint = "MoveWindow")]
public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool BRePaint);
[DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Auto)]
public static extern int ShowWindow(IntPtr hWnd, int code);
/// <summary>
/// 使指定窗體獲得鍵盤輸入焦點
/// </summary>
/// <param name="hWnd">窗體句柄</param>
/// <returns>若函數調用成功,則返回原先擁有鍵盤焦點的窗口句柄。若hWnd參數無效或窗口未與調用線程的消息隊列相關,則返回值為NULL</returns>
[DllImport("user32.dll", EntryPoint = "SetFocus")]
public static extern IntPtr SetFocus(IntPtr hWnd);
[DllImport("user32.dll", EntryPoint = "GetFocus")]
public static extern IntPtr GetFocus();
[DllImport("user32.dll", EntryPoint = "GetCapture")]
public static extern IntPtr GetCapture();
/// <summary>
/// 移動鼠標到指定位置
/// </summary>
/// <param name="x">指定位置x坐標</param>
/// <param name="y">指定位置y坐標</param>
/// <returns></returns>
[DllImport("user32.dll", EntryPoint = "SetCursorPos")]
public static extern bool SetCursorPos(int x, int y);
/// <summary>
/// 鼠標事件
/// </summary>
/// <param name="dwFlags">事件名稱</param>
/// <param name="dx">x位移</param>
/// <param name="dy">y位移</param>
/// <param name="dwData"></param>
/// <param name="dwExtraInfo"></param>
[DllImport("user32.dll", EntryPoint = "mouse_event")]
public extern static void mouse_event(int dwFlags, int dx, int dy, int dwData, IntPtr dwExtraInfo);
/// <summary>
/// 獲取當前活躍窗口
/// </summary>
/// <returns></returns>
[DllImport("user32.dll", EntryPoint = "GetActiveWindow")]
public static extern IntPtr GetActiveWindow();
[DllImport("user32.dll", EntryPoint = "GetForegroundWindow")]
public static extern IntPtr GetForegroundWindow();
/// <summary>
/// 獲取當前窗體最近一次活躍的窗口 獲得messagebox
/// </summary>
/// <param name="hWnd"></param>
/// <returns></returns>
[DllImport("user32.dll", EntryPoint = "GetLastActivePopup")]
public static extern IntPtr GetLastActivePopup(IntPtr hWnd);
/// <summary>
/// 獲得窗口句柄的編號
/// </summary>
/// <param name="hWnd"></param>
/// <param name="nlndex"></param>
/// <returns></returns>
[DllImport("user32.dll", EntryPoint = "GetWindowLong")]
public static extern long GetWindowLong(IntPtr hWnd, int nlndex);
/// <summary>
/// 得到此控件的類名
/// </summary>
/// <param name="hWnd"></param>
/// <param name="classname">接收數據的要首先給出空間</param>
/// <param name="nlndex">所要取得的最大字符數,如果設置為0 則什麼都沒有</param>
/// <returns></returns>
[DllImport("user32.dll", EntryPoint = "GetClassName")]
public static extern int GetClassName(IntPtr hWnd, StringBuilder classname, int nlndex);
public const int SRCCOPY = 0x00CC0020; // BitBlt dwRop parameter
[DllImport("gdi32.dll")]
public static extern bool BitBlt(IntPtr hObject, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hObjectSource, int nXSrc, int nYSrc, int dwRop);
[DllImport("gdi32.dll")]
public static extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int nWidth, int nHeight);
[DllImport("gdi32.dll")]
public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
[DllImport("gdi32.dll")]
public static extern bool DeleteDC(IntPtr hDC);
[DllImport("gdi32.dll")]
public static extern bool DeleteObject(IntPtr hObject);
[DllImport("gdi32.dll")]
public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
[DllImport("user32.dll")]
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtralnfo);
/// <summary>
/// 獲取操作系統分辨率
/// </summary>
/// <param name="nIndex"></param>
/// <returns></returns>
[DllImport("user32.dll")]
public static extern int GetSystemMetrics(int nIndex);
[DllImport("user32.dll")]
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
public static extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, ref int lpdwProcessId);
[DllImport("user32.dll")]
public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);
#endregion
#region 封裝方法
/// <summary>
/// 窗口置前
/// </summary>
/// <param name="hWnd">窗口句柄</param>
public static void SetWindowPos(IntPtr hWnd)
{
SetWindowPos(hWnd, -1, 0, 0, 0, 0, 0x4000 | 0x0001 | 0x0002);
}
/// <summary>
/// 通過進程名獲得主窗口句柄
/// </summary>
/// <param name="processName">進程名</param>
/// <returns>窗口句柄對象</returns>
public static IntPtr GetProcessMainFormHandle(string processName)
{
Process pro = null;
Process[] pros = Process.GetProcessesByName(processName);
if (pros.Length > 0)
{
pro = pros[0];
}
IntPtr m_WindowHandle = IntPtr.Zero;
m_WindowHandle = pro.MainWindowHandle;
return m_WindowHandle;
}
/// <summary>
/// 獲得桌面的圖像
/// </summary>
/// <returns></returns>
public static Bitmap CaptureScreen()
{
return CaptureWindow(GetDesktopWindow());
}
public static Bitmap windowFullScreen()
{
//建立屏幕Graphics
Graphics grpScreen = Graphics.FromHwnd(IntPtr.Zero);
//根據屏幕大小建立位圖
Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, grpScreen);
//建立位圖相關Graphics
Graphics grpBitmap = Graphics.FromImage(bitmap);
//建立屏幕上下文
IntPtr hdcScreen = grpScreen.GetHdc();
//建立位圖上下文
IntPtr hdcBitmap = grpBitmap.GetHdc();
//將屏幕捕獲保存在圖位中
BitBlt(hdcBitmap, 0, 0, bitmap.Width, bitmap.Height, hdcScreen, 0, 0, 0x00CC0020);
//關閉位圖句柄
grpBitmap.ReleaseHdc(hdcBitmap);
//關閉屏幕句柄
grpScreen.ReleaseHdc(hdcScreen);
//釋放位圖對像
grpBitmap.Dispose();
//釋放屏幕對像
grpScreen.Dispose();
//返回捕獲位圖
return bitmap;
}
/// <summary>
/// 通過窗體句柄獲取此窗體的圖像
/// </summary>
/// <param name="handle"></param>
/// <returns></returns>
public static Bitmap CaptureWindow(IntPtr handle)
{
// get te hDC of the target window
IntPtr hdcSrc = GetWindowDC(handle);
// get the size
Rectangle windowRect = new Rectangle();
GetWindowRect(handle, ref windowRect);
int width = windowRect.Width - windowRect.X;
int height = windowRect.Height - windowRect.Y;
// create a device context we can copy to
IntPtr hdcDest = CreateCompatibleDC(hdcSrc);
// create a bitmap we can copy it to,
// using GetDeviceCaps to get the width/height
IntPtr hBitmap = CreateCompatibleBitmap(hdcSrc, width, height);
// select the bitmap object
IntPtr hOld = SelectObject(hdcDest, hBitmap);
// bitblt over
BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, SRCCOPY);
// restore selection
SelectObject(hdcDest, hOld);
// clean up
DeleteDC(hdcDest);
ReleaseDC(handle, hdcSrc);
// get a .NET image object for it
Image img = Image.FromHbitmap(hBitmap);
// free up the Bitmap object
DeleteObject(hBitmap);
return (Bitmap)img;
}
public static void SendKeyup(string key)
{
byte bkey = byte.Parse(key);
keybd_event(bkey, 0, APICode.KEYEVENTF_KEYUP, 0);
}
public static void SendKeydown(string key)
{
byte bkey = byte.Parse(key);
keybd_event(bkey, 0, APICode.KEYEVENTF_KEYDOWN, 0);
}
public static void MouseDown(string button)
{
switch (button)
{
case "left":
mouse_event(APICode.Mouse_LeftDown, 0, 0, 0, IntPtr.Zero);
break;
case "right":
mouse_event(APICode.Mouse_RightDown, 0, 0, 0, IntPtr.Zero);
break;
case "middle":
mouse_event(APICode.Mouse_MiddleDown, 0, 0, 0, IntPtr.Zero);
break;
}
}
public static void MouseUp(string button)
{
switch (button)
{
case "left":
mouse_event(APICode.Mouse_LeftUp, 0, 0, 0, IntPtr.Zero);
break;
case "right":
mouse_event(APICode.Mouse_RightUp, 0, 0, 0, IntPtr.Zero);
break;
case "middle":
mouse_event(APICode.Mouse_MiddleUp, 0, 0, 0, IntPtr.Zero);
break;
}
}
public static void MouseMove(int x, int y)
{
SetCursorPos(x, y);
}
/// <summary>
/// 獲取系統寬度度
/// </summary>
/// <returns></returns>
public static int GetSystemX()
{
return GetSystemMetrics(APICode.SM_CXSCREEN);
}
/// <summary>
/// 獲取系統高度
/// </summary>
/// <returns></returns>
public static int GetSystemY()
{
return GetSystemMetrics(APICode.SM_CYSCREEN);
}
#endregion
}
public class APICode
{
/// <summary>
/// WM_KEYDOWN 按下一個鍵
/// </summary>
public static int WM_KEYDOWN = 0x0100;
/// <summary>
/// 釋放一個鍵
/// </summary>
public static int WM_KEYUP = 0x0101;
//按下某鍵,並已發出WM_KEYDOWN, WM_KEYUP消息
public static int WM_CHAR = 0x102;
//當用translatemessage函數翻譯WM_KEYUP消息時發送此消息給擁有焦點的窗口
public static int WM_DEADCHAR = 0x103;
//當用戶按住ALT鍵同時按下其它鍵時提交此消息給擁有焦點的窗口
public static int WM_SYSKEYDOWN = 0x104;
//當用戶釋放一個鍵同時ALT 鍵還按著時提交此消息給擁有焦點的窗口
public static int WM_SYSKEYUP = 0x105;
//當WM_SYSKEYDOWN消息被TRANSLATEMESSAGE函數翻譯後提交此消息給擁有焦點的窗口
public static int WM_SYSCHAR = 0x106;
//當WM_SYSKEYDOWN消息被TRANSLATEMESSAGE函數翻譯後發送此消息給擁有焦點的窗口
public static int WM_SYSDEADCHAR = 0x107;
//在一個對話框程序被顯示前發送此消息給它,通常用此消息初始化控件和執行其它任務
public static int WM_INITDIALOG = 0x110;
//當用戶選擇一條菜單命令項或當某個控件發送一條消息給它的父窗口,一個快捷鍵被翻譯
public static int WM_COMMAND = 0x111;
//當用戶選擇窗口菜單的一條命令或//當用戶選擇最大化或最小化時那個窗口會收到此消息
public static int WM_SYSCOMMAND = 0x112;
//發生了定時器事件
public static int WM_TIMER = 0x113;
//當一個窗口標准水平滾動條產生一個滾動事件時發送此消息給那個窗口,也發送給擁有它的控件
public static int WM_HSCROLL = 0x114;
//當一個窗口標准垂直滾動條產生一個滾動事件時發送此消息給那個窗口也,發送給擁有它的控件
public static int WM_VSCROLL = 0x115;
//當一個菜單將要被激活時發送此消息,它發生在用戶菜單條中的某項或按下某個菜單鍵,它允許程序在顯示前更改菜單
public static int WM_INITMENU = 0x116;
//當一個下拉菜單或子菜單將要被激活時發送此消息,它允許程序在它顯示前更改菜單,而不要改變全部
public static int WM_INITMENUPOPUP = 0x117;
//當用戶選擇一條菜單項時發送此消息給菜單的所有者(一般是窗口)
public static int WM_MENUSELECT = 0x11F;
//當菜單已被激活用戶按下了某個鍵(不同於加速鍵),發送此消息給菜單的所有者
public static int WM_MENUCHAR = 0x120;
//當一個模態對話框或菜單進入空載狀態時發送此消息給它的所有者,一個模態對話框或菜單進入空載狀態就是在處理完一條或幾條先前的消息後沒有消息它的列隊中等待
public static int WM_ENTERIDLE = 0x121;
//在windows繪制消息框前發送此消息給消息框的所有者窗口,通過響應這條消息,所有者窗口可以通過使用給定的相關顯示設備的句柄來設置消息框的文本和背景顏色
public static int WM_CTLCOLORMSGBOX = 0x132;
//當一個編輯型控件將要被繪制時發送此消息給它的父窗口通過響應這條消息,所有者窗口可以通過使用給定的相關顯示設備的句柄來設置編輯框的文本和背景顏色
public static int WM_CTLCOLOREDIT = 0x133;
//當一個列表框控件將要被繪制前發送此消息給它的父窗口通過響應這條消息,所有者窗口可以通過使用給定的相關顯示設備的句柄來設置列表框的文本和背景顏色
public static int WM_CTLCOLORLISTBOX = 0x134;
//當一個按鈕控件將要被繪制時發送此消息給它的父窗口通過響應這條消息,所有者窗口可以通過使用給定的相關顯示設備的句柄來設置按紐的文本和背景顏色
public static int WM_CTLCOLORBTN = 0x135;
//當一個對話框控件將要被繪制前發送此消息給它的父窗口通過響應這條消息,所有者窗口可以通過使用給定的相關顯示設備的句柄來設置對話框的文本背景顏色
public static int WM_CTLCOLORDLG = 0x136;
//當一個滾動條控件將要被繪制時發送此消息給它的父窗口通過響應這條消息,所有者窗口可以通過使用給定的相關顯示設備的句柄來設置滾動條的背景顏色
public static int WM_CTLCOLORSCROLLBAR = 0x137;
//當一個靜態控件將要被繪制時發送此消息給它的父窗口通過響應這條消息,所有者窗口可以 通過使用給定的相關顯示設備的句柄來設置靜態控件的文本和背景顏色
public static int WM_CTLCOLORSTATIC = 0x138;
//當鼠標輪子轉動時發送此消息個當前有焦點的控件
public static int WM_MOUSEWHEEL = 0x20A;
//雙擊鼠標中鍵
public static int WM_MBUTTONDBLCLK = 0x209;
//釋放鼠標中鍵
public static int WM_MBUTTONUP = 0x208;
//移動鼠標時發生,同WM_MOUSEFIRST
public static int WM_MOUSEMOVE = 0x200;
//按下鼠標左鍵
public static int WM_LBUTTONDOWN = 0x201;
//釋放鼠標左鍵
public static int WM_LBUTTONUP = 0x202;
//雙擊鼠標左鍵
public static int WM_LBUTTONDBLCLK = 0x203;
//按下鼠標右鍵
public static int WM_RBUTTONDOWN = 0x204;
//釋放鼠標右鍵
public static int WM_RBUTTONUP = 0x205;
//雙擊鼠標右鍵
public static int WM_RBUTTONDBLCLK = 0x206;
//按下鼠標中鍵
public static int WM_MBUTTONDOWN = 0x207;
public static int WM_USER = 0x0400;
public static int MK_LBUTTON = 0x0001;
public static int MK_RBUTTON = 0x0002;
public static int MK_SHIFT = 0x0004;
public static int MK_CONTROL = 0x0008;
public static int MK_MBUTTON = 0x0010;
public static int MK_XBUTTON1 = 0x0020;
public static int MK_XBUTTON2 = 0x0040;
//創建一個窗口
public static int WM_CREATE = 0x01;
//當一個窗口被破壞時發送
public static int WM_DESTROY = 0x02;
//移動一個窗口
public static int WM_MOVE = 0x03;
//改變一個窗口的大小
public static int WM_SIZE = 0x05;
//一個窗口被激活或失去激活狀態
public static int WM_ACTIVATE = 0x06;
//一個窗口獲得焦點
public static int WM_SETFOCUS = 0x07;
//一個窗口失去焦點
public static int WM_KILLFOCUS = 0x08;
//一個窗口改變成Enable狀態
public static int WM_ENABLE = 0x0A;
//設置窗口是否能重畫
public static int WM_SETREDRAW = 0x0B;
//應用程序發送此消息來設置一個窗口的文本
public static int WM_SETTEXT = 0x0C;
//應用程序發送此消息來復制對應窗口的文本到緩沖區
public static int WM_GETTEXT = 0x0D;
//得到與一個窗口有關的文本的長度(不包含空字符)
public static int WM_GETTEXTLENGTH = 0x0E;
//要求一個窗口重畫自己
public static int WM_PAINT = 0x0F;
//當一個窗口或應用程序要關閉時發送一個信號
public static int WM_CLOSE = 0x10;
//當用戶選擇結束對話框或程序自己調用ExitWindows函數
public static int WM_QUERYENDSESSION = 0x11;
//用來結束程序運行
public static int WM_QUIT = 0x12;
//當用戶窗口恢復以前的大小位置時,把此消息發送給某個圖標
public static int WM_QUERYOPEN = 0x13;
//當窗口背景必須被擦除時(例在窗口改變大小時)
public static int WM_ERASEBKGND = 0x14;
//當系統顏色改變時,發送此消息給所有頂級窗口
public static int WM_SYSCOLORCHANGE = 0x15;
//當系統進程發出WM_QUERYENDSESSION消息後,此消息發送給應用程序,通知它對話是否結束
public static int WM_ENDSESSION = 0x16;
//當隱藏或顯示窗口是發送此消息給這個窗口
public static int WM_SHOWWINDOW = 0x18;
//發此消息給應用程序哪個窗口是激活的,哪個是非激活的
public static int WM_ACTIVATEAPP = 0x1C;
//當系統的字體資源庫變化時發送此消息給所有頂級窗口
public static int WM_FONTCHANGE = 0x1D;
//當系統的時間變化時發送此消息給所有頂級窗口
public static int WM_TIMECHANGE = 0x1E;
//發送此消息來取消某種正在進行的摸態(操作)
public static int WM_CANCELMODE = 0x1F;
//如果鼠標引起光標在某個窗口中移動且鼠標輸入沒有被捕獲時,就發消息給某個窗口
public static int WM_SETCURSOR = 0x20;
//當光標在某個非激活的窗口中而用戶正按著鼠標的某個鍵發送此消息給//當前窗口
public static int WM_MOUSEACTIVATE = 0x21;
//發送此消息給MDI子窗口//當用戶點擊此窗口的標題欄,或//當窗口被激活,移動,改變大小
public static int WM_CHILDACTIVATE = 0x22;
//此消息由基於計算機的訓練程序發送,通過WH_JOURNALPALYBACK的hook程序分離出用戶輸入消息
public static int WM_QUEUESYNC = 0x23;
//此消息發送給窗口當它將要改變大小或位置
public static int WM_GETMINMAXINFO = 0x24;
//發送給最小化窗口當它圖標將要被重畫
public static int WM_PAINTICON = 0x26;
//此消息發送給某個最小化窗口,僅//當它在畫圖標前它的背景必須被重畫
public static int WM_ICONERASEBKGND = 0x27;
//發送此消息給一個對話框程序去更改焦點位置
public static int WM_NEXTDLGCTL = 0x28;
//每當打印管理列隊增加或減少一條作業時發出此消息
public static int WM_SPOOLERSTATUS = 0x2A;
//當button,combobox,listbox,menu的可視外觀改變時發送
public static int WM_DRAWITEM = 0x2B;
//當button, combo box, list box, list view control, or menu item 被創建時
public static int WM_MEASUREITEM = 0x2C;
//此消息有一個LBS_WANTKEYBOARDINPUT風格的發出給它的所有者來響應WM_KEYDOWN消息
public static int WM_VKEYTOITEM = 0x2E;
//此消息由一個LBS_WANTKEYBOARDINPUT風格的列表框發送給他的所有者來響應WM_CHAR消息
public static int WM_CHARTOITEM = 0x2F;
//當繪制文本時程序發送此消息得到控件要用的顏色
public static int WM_SETFONT = 0x30;
//應用程序發送此消息得到當前控件繪制文本的字體
public static int WM_GETFONT = 0x31;
//應用程序發送此消息讓一個窗口與一個熱鍵相關連
public static int WM_SETHOTKEY = 0x32;
//應用程序發送此消息來判斷熱鍵與某個窗口是否有關聯
public static int WM_GETHOTKEY = 0x33;
//此消息發送給最小化窗口,當此窗口將要被拖放而它的類中沒有定義圖標,應用程序能返回一個圖標或光標的句柄,當用戶拖放圖標時系統顯示這個圖標或光標
public static int WM_QUERYDRAGICON = 0x37;
//發送此消息來判定combobox或listbox新增加的項的相對位置
public static int WM_COMPAREITEM = 0x39;
//顯示內存已經很少了
public static int WM_COMPACTING = 0x41;
//發送此消息給那個窗口的大小和位置將要被改變時,來調用setwindowpos函數或其它窗口管理函數
public static int WM_WINDOWPOSCHANGING = 0x46;
//發送此消息給那個窗口的大小和位置已經被改變時,來調用setwindowpos函數或其它窗口管理函數
public static int WM_WINDOWPOSCHANGED = 0x47;
//當系統將要進入暫停狀態時發送此消息
public static int WM_POWER = 0x48;
//當一個應用程序傳遞數據給另一個應用程序時發送此消息
public static int WM_COPYDATA = 0x4A;
//當某個用戶取消程序日志激活狀態,提交此消息給程序
public static int WM_CANCELJOURNA = 0x4B;
//當某個控件的某個事件已經發生或這個控件需要得到一些信息時,發送此消息給它的父窗口
public static int WM_NOTIFY = 0x4E;
//當用戶選擇某種輸入語言,或輸入語言的熱鍵改變
public static int WM_INPUTLANGCHANGEREQUEST = 0x50;
//當平台現場已經被改變後發送此消息給受影響的最頂級窗口
public static int WM_INPUTLANGCHANGE = 0x51;
//當程序已經初始化windows幫助例程時發送此消息給應用程序
public static int WM_TCARD = 0x52;
//此消息顯示用戶按下了F1,如果某個菜單是激活的,就發送此消息個此窗口關聯的菜單,否則就發送給有焦點的窗口,如果//當前都沒有焦點,就把此消息發送給//當前激活的窗口
public static int WM_HELP = 0x53;
//當用戶已經登入或退出後發送此消息給所有的窗口,//當用戶登入或退出時系統更新用戶的具體設置信息,在用戶更新設置時系統馬上發送此消息
public static int WM_USERCHANGED = 0x54;
//公用控件,自定義控件和他們的父窗口通過此消息來判斷控件是使用ANSI還是UNICODE結構
public static int WM_NOTIFYFORMAT = 0x55;
//當用戶某個窗口中點擊了一下右鍵就發送此消息給這個窗口
//public static int WM_CONTEXTMENU = ??;
//當調用SETWINDOWLONG函數將要改變一個或多個 窗口的風格時發送此消息給那個窗口
public static int WM_STYLECHANGING = 0x7C;
//當調用SETWINDOWLONG函數一個或多個 窗口的風格後發送此消息給那個窗口
public static int WM_STYLECHANGED = 0x7D;
//當顯示器的分辨率改變後發送此消息給所有的窗口
public static int WM_DISPLAYCHANGE = 0x7E;
//此消息發送給某個窗口來返回與某個窗口有關連的大圖標或小圖標的句柄
public static int WM_GETICON = 0x7F;
//程序發送此消息讓一個新的大圖標或小圖標與某個窗口關聯
public static int WM_SETICON = 0x80;
//當某個窗口第一次被創建時,此消息在WM_CREATE消息發送前發送
public static int WM_NCCREATE = 0x81;
//此消息通知某個窗口,非客戶區正在銷毀
public static int WM_NCDESTROY = 0x82;
//當某個窗口的客戶區域必須被核算時發送此消息
public static int WM_NCCALCSIZE = 0x83;
//移動鼠標,按住或釋放鼠標時發生
public static int WM_NCHITTEST = 0x84;
//程序發送此消息給某個窗口當它(窗口)的框架必須被繪制時
public static int WM_NCPAINT = 0x85;
//此消息發送給某個窗口僅當它的非客戶區需要被改變來顯示是激活還是非激活狀態
public static int WM_NCACTIVATE = 0x86;
//發送此消息給某個與對話框程序關聯的控件,widdows控制方位鍵和TAB鍵使輸入進入此控件通過應
public static int WM_GETDLGCODE = 0x87;
//當光標在一個窗口的非客戶區內移動時發送此消息給這個窗口 非客戶區為:窗體的標題欄及窗 的邊框體
public static int WM_NCMOUSEMOVE = 0xA0;
//當光標在一個窗口的非客戶區同時按下鼠標左鍵時提交此消息
public static int WM_NCLBUTTONDOWN = 0xA1;
//當用戶釋放鼠標左鍵同時光標某個窗口在非客戶區十發送此消息
public static int WM_NCLBUTTONUP = 0xA2;
//當用戶雙擊鼠標左鍵同時光標某個窗口在非客戶區十發送此消息
public static int WM_NCLBUTTONDBLCLK = 0xA3;
//當用戶按下鼠標右鍵同時光標又在窗口的非客戶區時發送此消息
public static int WM_NCRBUTTONDOWN = 0xA4;
//當用戶釋放鼠標右鍵同時光標又在窗口的非客戶區時發送此消息
public static int WM_NCRBUTTONUP = 0xA5;
//當用戶雙擊鼠標右鍵同時光標某個窗口在非客戶區十發送此消息
public static int WM_NCRBUTTONDBLCLK = 0xA6;
//當用戶按下鼠標中鍵同時光標又在窗口的非客戶區時發送此消息
public static int WM_NCMBUTTONDOWN = 0xA7;
//當用戶釋放鼠標中鍵同時光標又在窗口的非客戶區時發送此消息
public static int WM_NCMBUTTONUP = 0xA8;
//當用戶雙擊鼠標中鍵同時光標又在窗口的非客戶區時發送此消息
public static int WM_NCMBUTTONDBLCLK = 0xA9;
public static int SW_HIDE = 0;
public static int SW_SHOWNORMAL = 1;
public static int Mouse_Move = 0x0001;
public static int Mouse_LeftDown = 0x0002;
public static int Mouse_LeftUp = 0x0004;
public static int Mouse_RightDown = 0x0008;
public static int Mouse_RightUp = 0x0010;
public static int Mouse_MiddleDown = 0x0020;
public static int Mouse_MiddleUp = 0x0040;
public static int Mouse_Wheel = 0x0800;
public static int Mouse_Absolute = 0x8000;
public static int KEYEVENTF_EXTENDEDKEY = 0x1;
public static int KEYEVENTF_KEYUP = 0x2;
public static int KEYEVENTF_KEYDOWN = 0x00;
/// <summary>
/// 獲取系統寬度
/// </summary>
public const int SM_CXSCREEN = 0;
/// <summary>
/// 獲取系統高度
/// </summary>
public const int SM_CYSCREEN = 1;
public static int SW_SHOWMINIMIZED = 2;
public static int SW_SHOWMAXIMIZED = 3;
public static int SW_MAXIMIZE = 3;
public static int SW_SHOWNOACTIVATE = 4;
public static int SW_SHOW = 5;
public static int SW_MINIMIZE = 6;
public static int SW_SHOWMINNOACTIVE = 7;
public static int SW_SHOWNA = 8;
public static int SW_RESTORE = 9;
}
}
轉自:http://blog.sina.com.cn/s/blog_469dcb490100mq5u.html