查找子窗体:childHandle := FindWindowEx(handle,0,'子窗体类','子窗体标题');
SendMessage(Button.Handle,WM_LBUTTONDOWN,0,0); 鼠标左键按下
SendMessage(Button.Handle,WM_LBUTTONUP,0,0); 鼠标左键抬起
SendMessage(Edit.Handle,WM_SETTEXT,255,Integer(PChar('abc'))); 传递文本
SendMessage(Edit.Handle,WM_Char,Wparam('Q'),2); 传递字符
SendMessage(Button.Handle,BM_SETSTYLE,BS_RADIOBUTTON,1); 改变Button风格
SendMessage(ComboBox.Handle,CB_SETDropPEDWIDTH,300,0); 改变CBDownWidth SendMessage这个函数有很多奇妙的用途
举例:
1,获得MEMO中的光标位置.
Lops:=SendMessage(memol.Handle,EM_LINEFROMCHAR,Memol.SelStart,0);//光标所在的行号
Cpos:=SendMessage(meno1.Handle,EM_LINEINDEX,Lpos,0);//光标所在的字符位置
LineLength:=SendMessage(memol.handle,EM_LINELENGTH,Cpos,0);//这行的字符数.
2,开关显示器.
SendMessage(Handle, WM_SYSCOMMAND, SC_MONITORPOWER,2);//关闭显示器.
SendMessage(Handle, WM_SYSCOMMAND, SC_MONITORPOWER, -1);//打开显示器.
3,有人问我如何让Memo翻页,我试了一下,
Next:
sendmessage(memo1.handle,wm_keydown,VK_NEXT,-1);
sendmessage(memo1.handle,wm_keyup,VK_NEXT,-1);
Prev:
sendmessage(memo1.handle,wm_keydown,VK_PRIOR,-1);
sendmessage(memo1.handle,wm_keyup,VK_PRIOR,-1); VK_PRIOR Page Up 键 0x21
VK_NEXT Page Down 键 0x22
VK_END End 键 0x23
VK_HOME Home 键 0x24
VK_LEFT 左箭头键 0x25
VK_UP 上箭头键 0x26
VK_RIGHT 右箭头键 0x27
VK_DOWN 下箭头键 0x28
具体例子unit Unit1;
interface
uses Windows, Messages,Tlhelp32, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var a,b:PAnsiChar;
h:HWND;
begin
h:= FindWindow(nil,'abc.txt - 记事本');
h:= FindWindowEx(h,0,'edit',nil);
SendMessage(h,WM_SETTEXT,255,Integer(PChar('我来测度了')));
ShowMessage( IntToStr(h));
end;