c 控制代碼相關 往別的程式加自己的內容

2021-06-17 21:57:01 字數 2465 閱讀 8713

using system;

using system.collections.generic;

using system.componentmodel;

using system.data;

using system.drawing;

using system.linq;

using system.text;

using system.windows.forms;

using system.runtime.interopservices;

private void button1_click(object sender, eventargs e)

//驗證當前窗體是乙個正在執行的

if (calculatorhandle == intptr.zero)

執行左鍵按下

//mouse_event(mouseeventflag.leftdown, 775, 1173, 0, uintptr.zero);

執行左鍵鬆開 

//mouse_event(mouseeventflag.leftup, 775, 1173, 0, uintptr.zero);

//獲得焦點 

uint wm_setfocus = 0x07;

sendmessage(calculatorhandle, wm_setfocus, intptr.zero, intptr.zero);

//找子視窗

intptr gg = findwindowex(ff, intptr.zero, "shell embedding", null);

intptr hh = findwindowex(gg, intptr.zero, "shell docobject view", null);

intptr ii = findwindowex(hh, intptr.zero, "internet explorer_server", null);

// a set of calculations.

setforegroundwindow(ii);

sendkeys.sendwait("做實驗-0-");

sendkeys.sendwait("^");

}//得到乙個應用程式視窗的控制代碼.

[dllimport("user32.dll", charset = charset.unicode)]

public static extern intptr findwindow(string lpclassname,

string lpwindowname);

// 啟用應用程式視窗.

[dllimport("user32.dll")]

public static extern bool setforegroundwindow(intptr hwnd);

//[dllimport("user32.dll")]

//static extern void mouse_event(mouseeventflag flags, int dx, int dy, uint data, uintptr extrainfo);

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

private static extern int sendmessage(intptr hwnd, uint msg, intptr wparam, intptr lparam);

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

private static extern int sendmessage(intptr hwnd, int msg, intptr wparam, string lparam);

//sendmessage的三個引數意思分別為

//引數1:接收訊息的控制項的控制代碼

//引數2:訊息型別   比如wm_lbuttondown

//引數3:訊息的附加資訊   比如要傳遞一些文字啊.或者座標資訊

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

private static extern intptr findwindowex(intptr hwndparent, intptr hwndchildafter, string lpszclass, string lpszwindow);

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

private static extern intptr findwindowex(intptr hwndparent, int hwndchildafter, string lpszclass, string lpszwindow);

//[flags]

//enum mouseeventflag : uint

// }

}

C 呼叫其他程式,比如控制別的程式上的按鈕

dllimport user32.dll entrypoint findwindow setlasterror true private static extern intptr findwindow string lpclassname,string lpwindowname dllimport ...

經典c演算法相關程式

程式51 題目 學習使用按位與 1.程式分析 0 0 0 0 1 0 1 0 0 1 1 1 2.程式源 include stdio.h main 程式52 題目 學習使用按位或 1.程式分析 0 0 0 0 1 1 1 0 1 1 1 1 2.程式源 include stdio.h main 程式...

C 獲取程式中相關路徑

12621 獲取程式的基目錄。獲取模組的完整路徑,包含檔名 system.diagnostics.process.getcurrentprocess mainmodule.filename 獲取和設定當前目錄 該程序從中啟動的目錄 的完全限定目錄。system.environment.current...