GetWindowText 有注解
不能用它从另一个应用程序的编辑控件中获取文字,就不可以用吗VB声明
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
说明
取得一个窗体的标题(caption)文字,或者一个控件的内容(在vb里使用:使用vb窗体或控件的caption或text属性)
返回值
Long,复制到lpString的字串长度;不包括空中止字符。会设置GetLastError
参数表
参数 类型及说明
hwnd Long,欲获取文字的那个窗口的句柄
lpString String,预定义的一个缓冲区,至少有cch+1个字符大小;随同窗口文字载入
cch Long,lpString缓冲区的长度
注解
不能用它从另一个应用程序的编辑控件中获取文字,
不能用它从另一个应用程序的编辑控件中获取文字,就不可以用吗VB声明
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
说明
取得一个窗体的标题(caption)文字,或者一个控件的内容(在vb里使用:使用vb窗体或控件的caption或text属性)
返回值
Long,复制到lpString的字串长度;不包括空中止字符。会设置GetLastError
参数表
参数 类型及说明
hwnd Long,欲获取文字的那个窗口的句柄
lpString String,预定义的一个缓冲区,至少有cch+1个字符大小;随同窗口文字载入
cch Long,lpString缓冲区的长度
注解
不能用它从另一个应用程序的编辑控件中获取文字,
解决方案 »
- Tms的advchart有用过的么
- 如何从多个表格各读一列并在DBGRID中显示
- delphi dbedit 数值计算
- cxgrid+delphi5漏洞问题
- 用ADO的connection对象连接数据库时如果出现错误,如何扑获?如何显示错误?
- 请问:isnumeric函数怎么用?
- 巨菜问题,求助
- 利用ADO方式访问数据库,如何定义全局ADOconnection ?另外datamodule如何使用?
- SetupBuilder V1.50是不错的打包工具,哪位兄台有注册版或注册码,高分求!急急急!!!
- 请问这几句话有错误吗,(添在一个button的click事件里)为什么错误告诉我“在sql语句后找到字符”
- 快快帮忙,十分火急!!!谢谢各位!
- socket两个小问
这个函数的功能就是取得窗体标题栏内的文字的,
取不到控件中的文本内容,
如果想取使用
wm_gettext消息来做
// The TClipboard provides easy clipboard access. But what if you // want to add (several) custom defined items to the clipboard?
// For all actions is the unit Clipboard required.uses Clipboard;
// First you have to register your own clipboard format// This can be done ny a Windows API function (unit ShellAPI)constMyClipboardFormatStr = 'MyData';
varMyClpFormat : integer;
MyClpFormat:=RegisterClipboardFormat(MyClipboardFormatStr);
// The variable SLMClpFormat will contain a unique format handle for// your own clipboard format.// Then you can start copy items to the clipboard. You will need a// function for pointer incrementation which is given here:procedure IncPointer(var p : Pointer;increment : integer);begin p:=PChar(p)+Increment;end;
// Say you have a data record defined astypePMyDataRec = ^TMyDataRec;TMyDataRec = record Name : string[50]; Value : integer;end;// This will work of course also with other types
// Furthermore let's say the data records are stored in a Listbox// and shall be copied to a list box.
// Copy like this:procedure TForm1.CopyItems; var i : integer; dh : THandle; ic : integer; p : Pointer; pi : pInteger;
begin ic:=List1.SelCount; { get number of items to be copied } dh:=GlobalAlloc(GMEM_FIXED or GMEM_ZEROINIT,(SizeOf(TMyDataRec)*ic)+SizeOf(Integer)); { alloc memory for all items plus for a integer variable giving you the number of copied items } p:=GlobalLock(dh); { Lock the allocated memory } pi:=pInteger(p); pi^:=ic; { write number of items to allocated memory } IncPointer(p,SizeOf(Integer)); { increment the pointer behind the written data }// You don't have to create an instance of clipboard, this is done automatically
for i:=1 to List1.Items.Count do { check all items if they are selected } begin if List1.Items[i-1].Selected then begin { This one is selected -> copy it o the clipboard } PMyDataRec(p)^:=PMyDataRec(List1.Items[i-1].Data)^; { of course data must point to a TMyDataRec } IncPointer(p,SizeOf(TMyDataRec)); { increment the pointer behind the written data } end; end;
// You have now filled the allocated memory with all items that shall be copied.// Now you can put them to the clipboard Clipboard.Open; { Open the clipboard will prevent overwriting of so far copied items } Clipboard.Clear; { Clear the clipboard first } Clipboard.SetAsHandle(MyClpFormat,Dh); { Copy to clipboard } Clipboard.Close; { finally close the clipboard } GlobalUnlock(dh);{ and unlock the allocate memory. But don't free it, it will be used by the clipboard }
if ic=0 then GlobalFree(dh); { You can free it if you haven't copied anything }end;
// Check first if your items are still available before pasting them from the clipbard
if Clipboard.HasFormat(MyClpFormat) thenbegin Form1.Paste1.Enabled:=true; { Yes, they are still available }end;
// And this is, how you paste them after Paste1 is clickedprocedure TMDIForm.Paste1Click(Sender: TObject); var dh : THandle; pdr : PSLMDataRec; i,ic : integer; p : Pointer; pi : pInteger; li : TListItem;
begin if Clipboard.HasFormat(MyClpFormat) then// We have already checked, but maybe another application has overwritten the// clipboard in between.... begin ClipBoard.Open; { First open the clipboard again } dh:=Clipboard.GetAsHandle(MyClpFormat); { Catch the handle to the stored items } p:=GlobalLock(dh); { and lock it } pi:=pInteger(p); { The first item is an integer giving the number of items } ic:=pi^; { so get the number of items } IncPointer(p,SizeOf(integer)); { increment the pointer behind the read data } for i:=1 to ic do { get all copied items one after another } begin li:=List1.Items.Add; { first create a new listbox item } pdr:=New(PMyDataRec); { Then create a new pointer to a TMyDataRec } pdr^:=PMyDataRec(p)^; { and fill it with data from the clipboard } IncPointer(p,SizeOf(TSLMDataRec)); { increment the pointer behind the written data }
li.Data:=pdr; { Set the data pointer of the list item to the new record } LI.Caption:=pdr^.Name; { Let the item display the record field "Name" }
// You can of course add more record fields if the item has subitems: LI.SubItems.Add(IntTostr(Value));
end; { All data retrieved from clipboard } Clipboard.Close; { Close it } GlobalUnlock(dh); { and unlock the pointer, but don't free it. This will be done by the clipboard itself, if necessary } end;end;
这个例子用到了指针不知道可以用吗?
procedure TForm1.Edit1Click(Sender: TObject);begin IF ActiveControl IS TCustomEdit THEN BEGIN WITH TCustomEdit(ActiveControl) DO BEGIN Cut1.Enabled := SelLength > 0; Copy1.Enabled := SelLength > 0; Paste1.Enabled := ClipBoard.HasFormat(CF_TEXT); END; END ELSE BEGIN Cut1.Enabled := False; Copy1.Enabled := False; Paste1.Enabled := False; END;end;
procedure TForm1.Cut1Click(Sender: TObject);begin IF ActiveControl IS TDBEdit THEN WITH TDBEdit(ActiveControl).DataSource.DataSet DO Edit; TCustomEdit(ActiveControl).CutToClipboard; IF ActiveControl IS TDBEdit THEN WITH TDBEdit(ActiveControl).DataSource.DataSet DO Post;end;
procedure TForm1.Copy1Click(Sender: TObject);begin TCustomEdit(ActiveControl).CopyToClipboard;end;
procedure TForm1.Paste1Click(Sender: TObject);begin IF ActiveControl IS TDBEdit THEN WITH TDBEdit(ActiveControl).DataSource.DataSet DO Edit; TCustomEdit(ActiveControl).PasteFromClipboard; IF ActiveControl IS TDBEdit THEN WITH TDBEdit(ActiveControl).DataSource.DataSet DO Post;end;
OK? Edit1 is the top-level edit menu - when it's clicked, before the menu drops down, it checks if the active control is some kind of edit. If so, it enables Cut and Copy based on whether anything is selected, and it enables Paste base on whether there's text in the clipboard. If not, it disables all three.
To Copy from the active edit control, you just call CopyToClipboard; no problemo. To Cut or Paste, you're *CHANGING* the contents of the active edit control - if it's a DBEdit you need to get into edit mode and post your change afterward.
这第2个是把一个edit的复制我需要的是比如现在csdn网页焦点输入里的这个网页里的输入组件文字