程序通訊-sendmessage的使用方法
用過sendmessage進行程序通訊的同學都知道,這個函式一般都搭配findwindow使用。通過findwindow查詢程序控制代碼,然後使用sendmessage 向這個控制代碼傳送資訊。這介面使用起來比較簡單,但是當初也是費了好大的勁,只為用作記錄。
使用者介面需要有一下幾個元素,設定本地的視窗名稱,目標的視窗名稱,傳送資料,以及接受資料。
//win32 api函式
[dllimport("user32.dll", entrypoint = "sendmessage")]
private static extern int sendmessage(int hwnd, int msg, int wparam, ref copydatastruct lparam);
[dllimport("user32.dll", entrypoint = "findwindow")]
private static extern int findwindow(string lpclassname, string lpwindowname);
const int wm_copydata = 0x004a;
public struct copydatastruct
protected override void defwndproc(ref message m)
}private void recvonedatapacket(string strresult, string strtype)
{//throw new notimplementedexception();
listboxrecv.items.add(strresult);
這個介面在當初做的時候,老是出錯,就在這個地方。
cds = (copydatastruct)m.getlparam(t);
我也不知道為什麼,也許是因為訊息值的定義吧。不清楚,反正以後得注意了。
程序間通訊SendMessage
postmessage貌似只能用於程序內通訊,不同程序間通訊可以用sendmessage和共享記憶體等方式。這裡理出sendmessage的用法,方便日後查閱。傳送訊息的程序 char sztemp 1024 sprintf sztemp,layeredwindow d iwndid 視窗名 hwn...
SendMessage程序間簡單通訊問題
主要api findwindow lpctstrlpclassname,lpctstrlpwindowname 通過程序名得到程序handle sendmessage uintmessage,wparamwparam 0,lparamlparam 0 the result of the messag...
SendMessage程序間簡單通訊問題
本例以兩個vc dialog 主要api findwindow lpc tstrlpclassname,lpctstrlpwindowname 通過程序名得到程序handle sendmessage uintmessage,wparamwparam 0,lparamlparam 0 the resu...