c#通过SendMessage发送消息

c#通过SendMessage发送消息,改变其他程序的下拉框控件(ComboBox)的值

IntPtr mwh = (IntPtr)Convert.ToInt32(handle);                         //ComboBox的句柄
int result = SendMessage(mwh, 0x014D, -1, selectStr);            //改变ComboBox的值,selectStr为预期的下拉框选项

int mwh_p = GetWindowLong(mwh, -8);                                   //获取ComboBox所属窗口的句柄
           
IntPtr mwh2 = (IntPtr)Convert.ToInt32(mwh_p);                      //转换ComboBox所属窗口的句柄

string cbn_selchange;

int cb_id = GetWindowLong(mwh, -12);                                    //获取ComboBox的控件ID

cbn_selchange = "0001" + string.Format("{0:X4}", cb_id);     

IntPtr s1 = (IntPtr)Convert.ToInt32(Tools.ToD(cbn_selchange, 16));

SendMessage(mwh2, 0x0111, s1, mwh);                    //给ComboBox所属窗口发送WM_COMMAND命令,第3个参数wParam是(CBN_SELCHANGE(高

位) + 控件ID(低位))

SendMessage(mwh2, 0x0111, s1, mwh);可以参考SPY++捕捉的消息日志

GetWindowLong的参数可以参考:

http://blog.csdn.net/hnhyhongmingjiang/archive/2008/03/06/2154410.aspx

SendMessage的参数可以参考:

http://topic.csdn.net/t/20050713/18/4142641.html

原文地址:https://www.cnblogs.com/hssbsw/p/2344486.html