C 給其他程式發訊息

2021-09-06 19:14:37 字數 1971 閱讀 6386

1、相關宣告函式,sendmessage可定義兩種格式。

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

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

[dllimport("user32.dll")]

private static extern intptr findwindow(string lpclassname, string lpwindowname);

[dllimport("user32.dll")]

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

[dllimport("user32.dll")]

public static extern intptr sendmessage(intptr hwnd, uint msg, intptr wparam, string lparam);

[dllimport("user32.dll")]

public static extern intptr postmessage(intptr hwnd, int wmsg, intptr wparam, string lparam);

2、相關訊息

public const uint wm_settext = 0x000c;

public const uint wm_char = 0x0102;

public const uint em_setsel = 0x00b1;

3、用spy++觀察是哪個視窗處理訊息,然後用findwindow找到視窗控制代碼

intptr main = findwindow("tfrmmain", null);

或自己啟動,比如記事本

process vprocess = process.start("notepad.exe");

while (vprocess.mainwindowhandle == intptr.zero) vprocess.refresh();

注:啟動之後可以直接發鍵值

sendkeys.send("01234/n");sendkeys.send("56789/n");

或列舉所有程序

process vp2 = process.getprocesses();

用findwindowex找子視窗控制代碼,一層層找下去。

intptr panel1 = findwindowex(main, intptr.zero, "tpanel", null);

intptr panel2 = findwindowex(panel1, intptr.zero, "tpanel", null);

如果有多個同類子視窗,findwindowex第二個引數,控制從哪個子視窗開始找何開始找。

intptr edit1 = findwindowex(panel2, (intptr)null, "tedit", null);

intptr edit2 = findwindowex(panel2, edit1, "tedit", null);

逐個發訊息

sendmessage(edit1, wm_char, (uint)keys.f3, 0);

用迴圈發

string end="hello";

for(int i=0;i<5;i++)

sendmessage(edit1, wm_char, (uint)end[i], 0);

發字串

sendmessage(vhandle, wm_settext, intptr.zero, "測試/r/n換行");

選中7個文字

sendmessage(vhandle, em_setsel, 0, 7);

python 給微信好友發訊息

傳送搞定了,接收沒搞定,有時間再搞 pip install wxpy from future import unicode literals from threading import timer from wxpy import import requests 機械人 bot bot defget...

突然不發訊息給ActiveMQ但能接收

今天專案在聯調過程中,activemq突然不好使了。在此之前一月內,專案組的人都沒有去修改 重啟過mq服務。雖然現在知道是由於許可權的問題導致只能收不能發 站在activemq角度是收不到,但可以發 只是到現在還不知道原來沒變過的 怎麼以前可以用,現在卻不行了?通過查詢示例 發現有connectio...

python實現智 給微信女友定時發訊息

匯入模組 from wxpy import 初始化機械人,掃碼登陸 bot bot author zhi date 2020 6 20 0020 13 34 from future import unicode literals from threading import timer from wx...