如何使用sendmessage向combobox控件输入字符串(100分)

  • 主题发起人 主题发起人 mcu
  • 开始时间 开始时间
M

mcu

Unregistered / Unconfirmed
GUEST, unregistred user!
本人编写一个程序控制另一个程序,被控程序出现对话框,对话框中有一个combobox,我要向combobox发生一个字符串,请教各位大虾该怎么做?
 
1、先取得COMBOBOX的句柄,:)不知道老兄会不会,就是用EnumChildWindows和GetClassName等函数,如果不明白再给你解释。<br>2、再用SendMessage(HWND, WM_SETTEXT, 0, INTEGER(SendText));<br>&nbsp; &nbsp;HWND:Combobox句柄<br>&nbsp; &nbsp;SendText:向Combobox中发送的字符串
 
借mcu的分数一问(我想mcu也想知道这些内容):<br>如何取得其它程序combobox中的所有Item?<br>假定handle已到得
 
1、声明回调函数,function CalBack(aa: Hwnd; bb: LPARAM): Boolean; stdcall;<br>&nbsp; &nbsp;function CalBack(aa: Hwnd; bb: LPARAM): Hwnd; stdcall;<br>&nbsp; &nbsp;var<br>&nbsp; &nbsp; &nbsp;aClassName, ComponetName: array[0.255] of Char;<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;Result := 0;<br>&nbsp; &nbsp; &nbsp;GetClassName(aa, aClassName, 255); &nbsp; &nbsp; &nbsp;// 得到控件类名<br>&nbsp; &nbsp; &nbsp;GetWindowText(aa, ComponetName, 255); &nbsp; // 得到控件标题<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp;// 根据标题判断是不是你要找的combobox<br>&nbsp; &nbsp; &nbsp;if (StrComp(aClassName, PChar('TCombobox')) = 0) and (aa &lt;&gt; 0) then<br>&nbsp; &nbsp; &nbsp; &nbsp;if (StrComp(ComponetName, PChar('Combobox1')) then<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result := aa;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ShowMessage('找到了!');<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp;end;<br><br>2、用FindWindow得到句柄<br>&nbsp; &nbsp; &nbsp;DestHwnd := FindWindow(......)<br>3、注册calback,等待回应,呵呵,到此就可以了!<br>&nbsp; &nbsp;function TForm1.Start();<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;EnumChildWindows(DestHwnd, @CalBack, 0);<br>&nbsp; &nbsp; &nbsp;SetActiveWindow(DestHwnd);<br>&nbsp; &nbsp;end; &nbsp; &nbsp;<br>不知道讲明白了没,如果还有不明之处,看看DELPHI5开发人员指南,写得很清楚。
 
我来回答我借楼主所开的贴提出的问题:<br>var hn:HWND;<br>&nbsp; S: string;<br>&nbsp; Count, I: Integer;<br>begin<br>&nbsp; &nbsp; memo1.Clear;<br>&nbsp; &nbsp; hn:=$00000314; &nbsp; &nbsp; &nbsp; &nbsp; // 这是要取所有Item的Combobox的句柄,假定句柄是 00000314<br>&nbsp; &nbsp; Count := SendMessage(hn,CB_GETCOUNT, 0, 0);<br>&nbsp; &nbsp; for I := 0 to Count - 1 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; SetLength(S, 255);<br>&nbsp; &nbsp; &nbsp; &nbsp; SetLength(S, SendMessage(hn,CB_GETLBTEXT, I, Integer(Pointer(S))));<br>&nbsp; &nbsp; &nbsp; &nbsp; memo1.Lines.Add(s);<br>&nbsp; &nbsp; end;<br>end;<br>
 
来自:qince, 时间:2004-1-31 15:51:00, ID:2428711<br>1、声明回调函数,function CalBack(aa: Hwnd; bb: LPARAM): Boolean; stdcall;<br>&nbsp; function CalBack(aa: Hwnd; bb: LPARAM): Hwnd; stdcall;<br>&nbsp; var<br>&nbsp; &nbsp; aClassName, ComponetName: array[0.255] of Char;<br>&nbsp; &nbsp; S: String;<br>&nbsp; begin<br>&nbsp; &nbsp; Result := 0;<br>&nbsp; &nbsp; GetClassName(aa, aClassName, 255); &nbsp; &nbsp; &nbsp;// 得到控件类名<br>&nbsp; &nbsp; GetWindowText(aa, ComponetName, 255); &nbsp; // 得到控件标题<br>&nbsp; &nbsp; <br>&nbsp; &nbsp; // 根据标题判断是不是你要找的combobox<br>&nbsp; &nbsp; if (StrComp(aClassName, PChar('TCombobox')) = 0) and (aa &lt;&gt; 0) then<br>&nbsp; &nbsp; &nbsp; if (StrComp(ComponetName, PChar('Combobox1')) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := aa;<br>[blue] &nbsp; &nbsp; &nbsp; &nbsp;S := '插入的内容';<br>&nbsp; &nbsp; &nbsp; &nbsp; SendMessage(aa, CB_ADDSTRING, 0, Longint(PChar(S)));[/blue]<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; end;<br><br>2、用FindWindow得到句柄<br>&nbsp; &nbsp; DestHwnd := FindWindow(......)<br>3、注册calback,等待回应,呵呵,到此就可以了!<br>&nbsp; function TForm1.Start();<br>&nbsp; begin<br>&nbsp; &nbsp; EnumChildWindows(DestHwnd, @CalBack, 0);<br>&nbsp; &nbsp; SetActiveWindow(DestHwnd);<br>&nbsp; end; &nbsp; &nbsp;<br>不知道讲明白了没,如果还有不明之处,看看DELPHI5开发人员指南,写得很清楚。
 
S := '插入的内容';<br>SendMessage(FndWnd, CB_ADDSTRING, 0, Longint(PChar(S)));
 
to wjh_wy:<br>&nbsp; 不会吧,老兄,上边已有贴了:)
 
多人接受答案了。
 

Similar threads

D
回复
0
查看
931
DelphiTeacher的专栏
D
D
回复
0
查看
724
DelphiTeacher的专栏
D
D
回复
0
查看
685
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部