windows 簡單api應用

2022-02-19 09:29:29 字數 3060 閱讀 4838

//呼叫系統函式 將滑鼠移動到相應位置

[dllimport("user32.dll", entrypoint = "setcursorpos")]

public extern static bool setcursorpos(int x, int y);

//獲取當前滑鼠的絕對位置

[structlayout(layoutkind.sequential)]

public struct point

[dllimport("user32")]

public extern static bool getcursorpos(out point p);

//是否顯示滑鼠箭頭

[dllimport("user32")]

public extern static int showcursor(bool bshow);

//呼叫系統函式 模擬滑鼠事件函式

[dllimport("user32", entrypoint = "mouse_event")]

private static extern int mouse_event(int dwflags, int dx, int dy, int cbuttons, int dwextrainfo);

例如: private const int mouseeventf_leftdown = 0x0002; //模擬滑鼠左鍵按下

private const int mouseeventf_leftup = 0x0004; //模擬滑鼠左鍵抬起

private const int mouseeventf_rightdown = 0x0008; //模擬滑鼠右鍵按下

private const int mouseeventf_rightup = 0x0010; //模擬滑鼠右鍵抬起

private const int mouseeventf_absolute = 0x8000;//滑鼠絕對位置

mouse_event(mouseeventf_leftdown|mouseeventf_leftup | mouseeventf_absolute, 0, 0, 0, 0);//點選 其中 int dx, int dy沒有效果

[dllimport("user32.dll")]

static extern intptr setactivewindow(intptr hwnd);//啟用窗體

[dllimport("user32.dll")]

[return: marshalas(unmanagedtype.bool)]

static extern bool setforegroundwindow(intptr hwnd);//把窗體頂層顯示

//獲取窗體的控制代碼,其中第乙個引數可以為null,第二個引數是任務管理器中「應用程式的 名稱」

[dllimport("user32.dll")]

static extern intptr findwindow(string strclass, string strwindow);

//獲取視窗的相對的位置 高寬

[dllimport("user32.dll")]

private static extern bool getwindowrect(intptr hwnd, out rect lprect);

[dllimport("user32.dll")]

private static extern bool iszoomed(intptr hwnd);//判斷視窗最大化,最大化則返回true

//以什麼樣的方式顯示窗體

[dllimport("user32.dll")]

private static extern bool showwindow(intptr hwnd, int ncmdshow);

//showwindow引數

private const int sw_shownormal = 1;

private const int sw_restore = 9;

private const int sw_shownoactivate = 4;

//sendmessage引數

private const int wm_keydown = 0x100;

private const int wm_keyup = 0x101;

private const int wm_syschar = 0x106;

private const int wm_syskeyup = 0x105;

private const int wm_syskeydown = 0x104;

private const int wm_char = 0x102;

showwindow(parenthwnd, sw_restore); //還原視窗

滑鼠滾輪事件

[dllimport("user32.dll")]

static extern void mouse_event(int flags, int dx, int dy, int buttons, int extrainfo);

const int mouseeventf_move = 0x1;

const int mouseeventf_leftdown = 0x2;

const int mouseeventf_leftup = 0x4;

const int mouseeventf_rightdown = 0x8;

const int mouseeventf_rightup = 0x10;

const int mouseeventf_middledown = 0x20;

const int mouseeventf_middleup = 0x40;

const int mouseeventf_wheel = 0x800;

const int mouseeventf_absolute = 0x8000;

protected override bool processcmdkey(ref message msg, keys key)

}return base.processcmdkey(ref msg, key);

}

Windows操作登錄檔API簡單例子

windows操作登錄檔api簡單例子 操作登錄檔主要包括下面幾個系統api 1 regopenkeyex 開啟登錄檔項 2 regclosekey 關閉登錄檔項 3 regcreatekeyex 建立登錄檔項 4 regdeletekey 刪除登錄檔項 5 regqueryvalueex 讀取登錄...

windows路徑操作API函式

pathremoveargs 去除路徑的引數 pathremovebackslash 去除路徑最後的反斜槓 pathaddbackslash 在路徑最後加上反斜槓 pathremoveblanks 去除路徑前後的空格 pathaddextension 在檔案路徑後面加上副檔名 pathremovee...

windows路徑操作API函式

windows 路徑操作 api函式 路徑截斷與合併函式 pathremoveargs 去除路徑的引數 pathremovebackslash 去除路徑最後的反斜槓 pathaddbackslash 在路徑最後加上反斜槓 pathremoveblanks 去除路徑前後的空格 pathaddexten...