天天看點

C# Win32API

public class Win32API

{

#region ==== Kernel32.dll ====

/// <summary>

/// 取得目前線程ID

/// </summary>

/// <returns></returns>

[DllImport("kernel32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]

public static extern uint GetCurrentThreadId();

public static extern IntPtr CreateFile(

string lpFileName,

FileAccess dwDesiredAccess,

FileShare dwShareMode,

int lpSecurityAttributes,

FileMode dwCreationDisposition,

int dwFlagsAndAttributes,

IntPtr hTemplateFile);

/// 打開程序

/// <param name="dwDesiredAccess">想得到的通路權限</param>

/// <param name="bInheritHandle">指定傳回的句柄是否可以被繼承</param>

/// <param name="dwProcessId">指定要打開的程序的ID</param>

public static extern IntPtr OpenProcess(DesiredAccess dwDesiredAccess, bool bInheritHandle, uint dwProcessId);

/// 結束其它程序

/// <param name="hProcess"></param>

/// <param name="uExitCode"></param>

public static extern bool TerminateProcess(IntPtr hProcess, uint uExitCode);

///

/// <param name="lpBaseAddress"></param>

/// <param name="lpBuffer"></param>

/// <param name="nSize"></param>

/// <param name="lpNumberOfBytesRead"></param>

public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, IntPtr lpBuffer, uint nSize, out uint lpNumberOfBytesRead);

/// <param name="dwFlags"></param>

/// <param name="th32ProcessID"></param>

public static extern IntPtr CreateToolhelp32Snapshot(uint dwFlags, uint th32ProcessID);

//[DllImport("kernel32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]

//public static extern bool Process32First(IntPtr hSnapshot, LPPROCESSENTRY32W lppe);

#endregion

#region ==== User32.dll ====

/// 繼續下一個鈎子

/// <param name="hhk"></param>

/// <param name="nCode"></param>

/// <param name="wParam"></param>

/// <param name="lParam"></param>

[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]

public static extern int CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);

/// 獲得一個頂層視窗的句柄,該視窗的類名和視窗名與給定的字元串相比對。這個函數不查找子視窗。在查找時不區分大小寫。

/// <param name="lpClassName">指向一個指定了類名的空結束字元串,或一個辨別類名字元串的成員的指針。如果該參數為一個成員,則它必須為前次調用theGlobafAddAtom函數産生的全局成員。該成員為16位,必須位于IpClassName的低 16位,高位必須為 0。</param>

/// <param name="lpWindowName">指向一個指定了視窗名(視窗标題)的空結束字元串。如果該參數為空,則為所有視窗全比對。</param>

/// <returns>如果函數成功,傳回值為具有指定類名和視窗名的視窗句柄;如果函數失敗,傳回值為NULL</returns>

public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

/// 檢取表示鍵名的字元串

public static extern int GetKeyNameText(IntPtr lParam, string lpBuffer, int nSize);

/// <param name="hWnd">收消息的視窗的句柄</param>

/// <param name="Msg">指定被發送的消息</param>

public static extern long SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

/// 改變一個子視窗,彈出式視窗式頂層視窗的尺寸,位置和Z序。子視窗,彈出式視窗,及頂層視窗根據它們在螢幕上出現的順序排序、頂層視窗設定的級别最高,并且被設定為Z序的第一個視窗。

/// <param name="hWnd">視窗句柄</param>

/// <param name="hWndInsertAfter">在z序中的位于被置位的視窗前的視窗句柄</param>

/// <param name="X">以客戶坐标指定視窗新位置的左邊界</param>

/// <param name="Y">以客戶坐标指定視窗新位置的頂邊界</param>

/// <param name="cx">以像素指定視窗的新的寬度</param>

/// <param name="cy">以像素指定視窗的新的高度</param>

/// <param name="uFlags">視窗尺寸和定位的标志</param>

public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, SWP_Flags uFlags);

/// 安裝鈎子

/// <param name="idHook">鈎子類型</param>

/// <param name="lpfn">鈎子函數的位址</param>

/// <param name="hMod">鈎子函數所在DLL的執行個體名柄. 如果一個局部的鈎子, 該參數的值為 NULL</param>

/// <param name="dwThreadId">要安裝鈎子的線程, 0 為全局鈎子</param>

/// <returns>鈎子句柄</returns>

public static extern IntPtr SetWindowsHookEx(WH_Codes idHook, HookProc lpfn, IntPtr hMod, uint dwThreadId);

/// 解除安裝鈎子

/// <param name="hhk">要解除安裝的鈎子的句柄</param>

public static extern bool UnhookWindowsHookEx(IntPtr hhk);

#region ==== 檔案系統 ====

#region ==== 磁盤和驅動器管理類 API ===

}

本文轉自94cool部落格園部落格,原文連結:http://www.cnblogs.com/94cool/archive/2010/04/27/1722030.html,如需轉載請自行聯系原作者

繼續閱讀