帮忙看看这段代码为什么不能显示指定edit控件的内容

silicon_crystal 2002-07-06 09:46:21
目的:通过得到鼠标所指的edit控件的内容
程序创建一个窗口。在窗体上按下鼠标后,开始获得鼠标所指的任何窗口的句柄。
在某个edit控件上释放鼠标后得到那个edit控件的文字。


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Edit2: TEdit;
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
//加粗当前鼠标移过的窗口
procedure InvertTracker(hwndDest : Integer);
end;

var
Form1: TForm1;
mlngHwndCaptured: Integer;
hWndLast: Integer;
implementation

{$R *.dfm}

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if SetCapture(handle) <> 0 then // 开始捕捉
Cursor := crUpArrow;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var pt : TPoint;
begin
if GetCapture() <> 0 then // 处于捕捉状态
begin
pt.X := X;
pt.Y := Y;
getcursorpos(pt);
// ClientToScreen(pt); // 获得鼠标的屏幕位置
// 获得窗口句柄
mlngHwndCaptured := WindowFromPoint(pt);

if hWndLast <> mlngHwndCaptured then
begin
if hWndLast <> 0 then // 使窗口边框加粗
InvertTracker(hWndLast);
InvertTracker(mlngHwndCaptured);
hWndLast := mlngHwndCaptured;
end
end;
// 显示坐标和窗口句柄
Caption := ‘X: ‘ + IntToStr(x) + ‘, Y: ‘ + IntToStr(y)
+ ‘, hWnd: ‘ + IntToStr(mlngHwndCaptured);

end;
procedure TForm1.InvertTracker(hwndDest: Integer);
var
hdcDest, hPen, hOldPen, hOldBrush : Integer;
cxBorder, cxFrame, cyFrame, cxScreen, cyScreen, cr : Integer;
rc : TRect;
Const NULL_BRUSH = 5;
Const R2_NOT = 6;
Const PS_INSIDEFRAME = 6;
begin
cxScreen := GetSystemMetrics(0);
cyScreen := GetSystemMetrics(1);
cxBorder := GetSystemMetrics(5);
cxFrame := GetSystemMetrics(32);
cyFrame := GetSystemMetrics(33);
GetWindowRect(hwndDest, rc);

hdcDest := GetWindowDC(hwndDest);

SetROP2(hdcDest, R2_NOT);
cr := clBlack;
hPen := CreatePen(PS_INSIDEFRAME, 3 * cxBorder, cr);

hOldPen := SelectObject(hdcDest, hPen);
hOldBrush := SelectObject(hdcDest, GetStockObject(NULL_BRUSH));
Rectangle(hdcDest, 0, 0, rc.Right - rc.Left, rc.Bottom - rc.Top);
SelectObject(hdcDest, hOldBrush);
SelectObject(hdcDest, hOldPen);

ReleaseDC(hwndDest, hdcDest);
DeleteObject(hPen);
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var strCaption: PChar;
pass,classname:array [0..254] of char;
lens,style_mh:longint;
begin
If mlngHwndCaptured <> 0 Then
begin // 获得窗口标题
strCaption := StrAlloc(1000);
GetWindowText(mlngHwndCaptured, strCaption, 1000);
Caption := StrPas(strCaption);
InvalidateRect(0, PRect(0), True);
mlngHwndCaptured := 0;
Cursor := crDefault;
ReleaseCapture;
StrDispose(strCaption);
hWndLast := 0;
/////////////////////////////////////////////////////////////////
//取得文字
/////////////////////////////////////////////////////////////////
getclassname(mlngHwndCaptured,classname,sizeof(classname));
lens:=sendmessage(mlngHwndCaptured,wm_gettextlength,0,0)+1;
sendmessage(mlngHwndCaptured,wm_gettext,lens,longint(@pass));//取得文字
edit1.Text:=string(pass);
end
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Left := 0;
Top :=0;
ClientHeight := 76;
end;

end.
...全文
94 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
gzllich 2002-07-07
  • 打赏
  • 举报
回复
真的看不到
surfguy 2002-07-07
  • 打赏
  • 举报
回复
同志们,要注意缩小包围圈
silicon_crystal 2002-07-07
  • 打赏
  • 举报
回复
算了我知道了。windows2000不支持来自非自己运行环境的那个消息。
在window98下没问题的。
除非你能给他个虚拟环境好象有这样的代码的。不过现在想不起来了。
xyxx 2002-07-06
  • 打赏
  • 举报
回复
眼花燎乱,顶!
ihihonline 2002-07-06
  • 打赏
  • 举报
回复
燎乱;走
johnsonrao 2002-07-06
  • 打赏
  • 举报
回复
眼花,UP!

5,927

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧