有关GetTopWindow()函数的使用方法,请高手指教!(35分)

  • 主题发起人 主题发起人 ctx
  • 开始时间 开始时间
C

ctx

Unregistered / Unconfirmed
GUEST, unregistred user!
请详细说明GetTopWindow()函数的使用方法,
最好举demo!
当其参数为空时,应返回顶层窗口,但是我编译时,会出错!
请指教!!仅有35分,全部送上!!
 
procedure TForm1.Button1Click(Sender: TObject);
var
WindowText: array[0..255] of char;
TheWindow: HWND;
ThePreviousWindow: HWND;
begin

{get the handle to the Form1 child window at the
top of the Z order relative to its siblings}
TheWindow:=GetTopWindow(Form1.Handle);

{get the text displayed on this window...}
GetWindowText(TheWindow,WindowText,255);

{...and display it in the label}
Label2.Caption:='Top Window: '+WindowText;

{now get the window just under it in the Z order}
ThePreviousWindow:=GetNextWindow(TheWindow,GW_HWNDNEXT);

{get the text displayed on this window...}
GetWindowText(ThePreviousWindow,WindowText,255);

{...and display it in the label}
Label3.Caption:='Next To Top: '+WindowText;
end;
 
To:wjiachun
当其参数为空时,应返回顶层窗口,此时该函数应如何使用??
请指教!!
 
; 函数功能:该函数检查与特定父窗口相联的子窗口z序,并返回在z序顶部的子窗口的句柄。
函数原型:HWND GetTopWindow(HWND hWnd);
参数:
hWnd:被查序的父窗口的句柄。如果该参数为NULL,函数返回Z序顶部的窗口句柄。
返回值;如果函数成功,返回值为在Z序顶部的子窗口句柄。如果指定的窗口无子窗口,返回值为NULL。

??我不明白你的意思了。
 
算了,把你的代码贴上来看看。
 
To:wjiachun
procedure TForm1.Timer2Timer(Sender: TObject);
var
lprect:Trect;
hCurrentWindow:HWnd;
rect:TRECT;
hwndz: HWnd;
begin
hCurrentWindow:=GetTopWindow(null);
if iswindowvisible(hCurrentWindow) then
begin
GetWindowRect(hCurrentWindow,rect);
if ((rect.Right-rect.Left)>Screen.Width) and ((rect.Bottom-rect.Top)>Screen.Height) then
begin
hwndz:=FindWindow('name',nil);
if hwndz<>0 then
begin
timer1.Enabled:=false;
SendMessage(hwndz,WM_CLOSE,0,0);
end;
end
else
timer1.Enabled:=true;
end;
end;
此段代码有问题吗?为什么提示我‘类型转换错误’?
 
哇塞,吐血!上面我贴的是<font color=red>中文</font>的家伙,还是看看英文的帮助吧:
hWnd: A handle to the parent window whose child windows are to be searched. If this
value is <font color=red>zero</font>, this function will return the first child window belonging to
the desktop window.
在Delphi中你应该用 <font color=red>0</font> !
 
HWND GetTopWindow(
HWND hWnd // handle of parent window
);
hWnd
Identifies the parent window whose child windows are to be examined.
If this parameter is NULL, the function returns a handle of the
window at the top of the Z order.
 
接受答案了.
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
913
SUNSTONE的Delphi笔记
S
后退
顶部