根据窗体句柄h,取得memo的句柄h1,然后向memo赋值
h1:=FindWindowEx(h,0,'RE_show',nil);
SendMessage(h1,WM_SETTEXT,0,0);
不知道怎么使用sendmessage,求助高手
h1:=FindWindowEx(h,0,'RE_show',nil);
SendMessage(h1,WM_SETTEXT,0,0);
不知道怎么使用sendmessage,求助高手
UINT Msg, // message to send
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
ParametershWndIdentifies the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows. MsgSpecifies the message to be sent. wParamSpecifies additional message-specific information. lParamSpecifies additional message-specific information.
最好用spy++模拟一次
SendMessage(h1,WM_SETTEXT,0,PChar('dfsasfd'));
SendMessage(h1,WM_SETTEXT,0,Integer(PChar('dfsasfd')));
还要强转,忘了
En文:
The SendMessage function sends the specified message to a window or windows. The function calls the window procedure for the specified window and does not return until the window procedure has processed the message. 参数列表:
LRESULT SendMessage(
HWND hWnd, // handle of destination window,也就是消息发送的目标窗体对应的句柄,在D中如Button.Handle
UINT Msg, // message to send 被发送的消息代号
WPARAM wParam,// first message parameter 消息代号的第1个参数
LPARAM lParam // second message parameter 消息代号的第2个参数
);
Form2:unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;const
WM_ADDOPER = WM_USER + 1234; //窗体2执行两个整数相加type
TForm2 = class(TForm)
private
procedure DoWMAddOper(var Msg: TMessage); message WM_ADDOPER;
public
{ Public declarations }
end;var
Form2: TForm2;implementation{$R *.dfm}{ TForm2 }procedure TForm2.DoWMAddOper(var Msg: TMessage);
begin
// 结果 第1个参数 + 第2个参数
Msg.Result := Msg.LParam + Msg.WParam;
end;end.Form1:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
begin
//向Form2发WM_ADDOPE消息使其计算R12+24的,并结果显示
i := SendMessage(Form2.Handle, WM_ADDOPER, 12, 24);
ShowMessage(IntToStr(i));
end;end.
该消息是为了兼容以前的Windows版本,而使用了跨进程的通讯处理,所以即使是其他进程的窗体,系统也会将lParam中指向的字符串使用进程间通讯搞定
我也可以这样来写吗?
还有,我怎样获得那个编辑框的句柄啊?
请赐教!
对于VC写的东西,窗体的ID是固定的,所以你可以先在文本框填一些数据,用标题找到句柄,然后用GetDlgCtrlID得到ID,当然你用Spy++这种工具直接看ID和句柄更方便。以后就可以用GetDlgItem通过ID来定位这个编辑框的句柄了(当然还是得先找到主窗体的句柄)