如何使窗体中的Panel控件始终在其它应用程序的最前端? 急!急!给个豆包吧。 (70分)

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

chensh

Unregistered / Unconfirmed
GUEST, unregistred user!
首先设在窗体From1中有控件Panel1。通过如下代码使Form1在所有应用程序的最后端,
且不出现在任务栏中,类似Windows桌面。
procedure TForm1.SetPos(var msg: TWMWINDOWPOSCHANGED); //窗体在最后端
begin
msg.WindowPos.hwndInsertAfter:=1;
end;

procedure TFmain.FormCreate(Sender: TObject);//不出现在任务栏
begin
SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
ShowWindow(Application.Handle, SW_HIDE);
SetWindowLong(Application.Handle, GWL_EXSTYLE,
GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW);
end;

那么如何使Panel1始终在其它应用程序的最前端呢?最好是源码。
 
用API函数SetWindowPos可以将任何窗体设置成为TopMost窗体, 即AlswaysOnTop:

function SetWindowPos(hWnd: HWND; hWndInsertAfter: HWND;
X, Y, cx, cy: Integer; uFlags: UINT): BOOL; stdcall;

其中:
hWnd: 窗体的 handle (参见已答问题如何得到窗体的handle)
hWndInsertAfter: 设置为 HWND_TOPMOST
其他信息可以用 GetWindowPlacement 函数得到

function GetWindowPlacement(hWnd: HWND; WindowPlacement: PWindowPlacement): BOOL; stdcall;

PWindowPlacement = ^TWindowPlacement;
{$EXTERNALSYM tagWINDOWPLACEMENT}
tagWINDOWPLACEMENT = packed record
length: UINT;
flags: UINT;
showCmd: UINT;
ptMinPosition: TPoint;
ptMaxPosition: TPoint;
rcNormalPosition: TRect;
end;
 
用楼上的方法试试吧!不过panel算是窗体吗?
 
试过了不好使呀,我是这样做了 在Form1.create事件中加入如下代码
GetWindowPlacement(mypanel.handle,@p);
SetWindowPos(mypanel.Handle,HWND_TOPMOST,
p.rcNormalPosition.Left, p.rcNormalPosition.Top,p.rcNormalPosition.Right-
p.rcNormalPosition.Left,p.rcNormalPosition.Bottom-p.rcNormalPosition.Top,
p.flags );
panel1还是始终跟随Form1在是后端。是我哪错了吗?

我的目的是想在最后端的窗体上出现最前端的Panel控件。我不想用两个窗体,才用Panel

 
各位大侠, 帮帮忙吧
 
剪切 -- 然后-- 粘贴

最后出现,它就最前端

 
接受答案了.
 
后退
顶部