DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: forget66
今日帖子: 61
在线用户: 14
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 zhangzhifeng886 (zhangzhifeng886) ★☆☆☆☆ -
普通会员
2023/5/8 17:34:03
标题:
窗体showmodal后, 跑到主程序后面去了的问题 浏览:1393
加入我的收藏
楼主: 主程序调用的bpl,弹出窗体,切换程序,showmodal窗体跑程序后面去了,设置了fsStayOnTop,不起作用
同时设置了SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE); 也没有起到作用
此帖子包含附件:
GIF 图像
大小:396.7K
----------------------------------------------
-
作者:
男 zhyhero (zhyhero) ★☆☆☆☆ -
盒子活跃会员
2023/5/8 20:43:31
1楼: 我不知道你是怎么具体代码实现。
我猜测是不是与创建窗体时指定的Owner有关。
----------------------------------------------
z@S7
作者:
男 21968578 (咪咪糊糊) ★☆☆☆☆ -
普通会员
2023/5/9 3:47:12
2楼: 我也遇到过这种情况,还没解决。
----------------------------------------------
-
作者:
男 jljaaj (小强) ▲▲▲△△ -
普通会员
2023/5/9 8:18:43
3楼: 这个问题,还真存在
----------------------------------------------
-
作者:
男 tms2021 (TMS2021) ▲△△△△ -
普通会员
2023/5/9 9:55:16
4楼: 这个好像与delphi无关,我用c#开发的程序也是这样
----------------------------------------------
欢迎加入Delphi的QQ群:462884906
作者:
男 461500377 (糖果) ▲▲△△△ -
普通会员
2023/5/9 10:14:08
5楼: 我最近也遇到了,我是Delphi窗体嵌入了一个wpf,一个winform程序,把嵌入的程序改成无焦点的就可以了,具体什么原因导致的不太清楚
----------------------------------------------
-
作者:
男 luckyrandom (luckyrandom) ★☆☆☆☆ -
普通会员
2023/5/9 12:48:05
6楼: N年前就碰到了。。这个应该是Windows底层BUG?
ShowModal、MessageBox等都有这个问题
----------------------------------------------
SQL SERVER DBA QQ:315054403 曾经的Delphier  缘在上海
作者:
男 jfhyn (贺兰之边) ★☆☆☆☆ -
普通会员
2023/5/9 14:55:07
7楼: BringToFront
----------------------------------------------
-
作者:
男 zhangzhifeng886 (zhangzhifeng886) ★☆☆☆☆ -
普通会员
2023/5/9 15:56:40
8楼: 还是没有解决,顶一下
----------------------------------------------
-
作者:
男 yam (yam) ★☆☆☆☆ -
盒子活跃会员
2023/5/9 18:57:51
9楼: 去掉有关皮肤的控件试试看。
----------------------------------------------
-
作者:
男 pcplayer (pcplayer) ★☆☆☆☆ -
普通会员
2023/5/9 18:59:56
9楼: 这个不是 Delphi 的问题。我用其它非 Delphi 开发的软件的时候也遇到过。遇到这种情况就用 Alt+Tab 组合键把它切换到后面再次切换到前面,说不定那个对话框就出来了。
----------------------------------------------
-
作者:
男 duanly (duanly) ▲▲▲▲▲ -
普通会员
2023/5/10 11:51:29
10楼: Application.ProcessMessages 试试
----------------------------------------------
-
作者:
女 google220 (google220) ★☆☆☆☆ -
普通会员
2023/5/11 0:10:29
11楼: 我们也发现这样的问题,一直没有办法解决。基本无解,只能做成类似资源管理器的卡片式结构。
----------------------------------------------
菩提本无树,明镜亦非台,本来无一物,何处惹尘埃
作者:
女 google220 (google220) ★☆☆☆☆ -
普通会员
2023/5/11 0:10:59
12楼: showmodal已经不流行了。谢谢。
----------------------------------------------
菩提本无树,明镜亦非台,本来无一物,何处惹尘埃
作者:
男 dbyoung (dbyoung) ★☆☆☆☆ -
普通会员
2023/5/11 8:08:44
13楼: 个人使用经验,供参考。

1、Application;
   Delphi 的窗体是由 Application 管理的。
   如果你在 DLL 中使用窗体,必须将主窗体的 Application 传进 DLL 之中;
   这样 DLL 窗体的消息循环由主窗体接管;可控;
   否则,就由 DLL 窗体自己处理消息循环了,不可控了;

2、Applicaition.MainForm;
   你在 DLL 窗体中,不可避免要使用到一些 Delphi 组件,
   有些组件是依赖 Application.MainForm 的,这是 Delphi VCL 框架决定的。
   如果你的主调用程序是 Delphi 写的,一般情况下是没有问题的,
   因为 Applicaition.MainForm 是存在的;
   如果你的主调用程序不是 Delphi 写的,譬如 VC/C#,
   这样 Applicaition.MainForm 就不存在了。
   这些依赖 Application.MainForm 的组件就会出问题。这也是 Delphi VCL 框架决定的。

通过以上分析,出现这个问题的原因,一般是发生在跨语言调用 DLL 时;
第一点容易做到;
第二点有点难度。要么修改 Delphi VCL 源码,要么不使用依赖 Application.MainForm 的组件;

Delphi 有源码,好处是可以调试进源码,知道为何出错了。
多看看 Delphi VCL 源码吧。
----------------------------------------------
武汉天气不好
作者:
男 luckyrandom (luckyrandom) ★☆☆☆☆ -
普通会员
2023/5/11 12:59:40
14楼: 就是纯delphi程序,也经常出现对话框隐藏在后面,切换其他程序再切换回来,就显示出来了
----------------------------------------------
SQL SERVER DBA QQ:315054403 曾经的Delphier  缘在上海
作者:
男 iamdream (银河恒久远,梦想无止境!) ★☆☆☆☆ -
大贡献会员
2023/5/13 14:13:43
15楼: BPL方式是特殊的DLL,Delphi已经处理好VCL组件了,我记得静态引用没问题的,动态加载是否需要更多处理则不太确定。
我有一段代码,工作中用的,似乎还行,你把它赋给Application.OnActivate事件试试:
procedure TForm1.AppActivate(Sender: TObject);
var
  fActive: TForm;
  hActive: THandle;
  hTopMost: THandle;
  i: Integer;
begin
  fActive := Screen.ActiveForm;
  //If the current window is the main window and is disabled, the next visible
  // window will be obtained, that is, the modal window or the window displaying
  // the modal dialog box
  if Assigned(fActive) and not IsWindowEnabled(fActive.Handle) and
     (Handle = fActive.Handle) and (Screen.FormCount > 1) then begin
    //get next visible form (may be modal state)
    for i := 1 to Screen.FormCount -1 do begin
      if Screen.Forms[i].Visible then begin
        fActive := Screen.Forms[i];
        Break;
      end;
    end;
  end;

  hActive := GetActiveWindow;
  // fsModal in fActive.FormState : For Modal form
  // not IsWindowEnabled(hActive) : For Dialogs (Modal state)
  // GetAncestor(Handle, GA_PARENT) = GetDesktopWindow : For "Params.WndParent := GetDesktopWindow"
  if Assigned(fActive) and ((fsModal in fActive.FormState) or not IsWindowEnabled(hActive)) then begin
    if (hActive <> fActive.Handle) and (Application.MainFormOnTaskbar or
          (hActive <> Self.Handle) or (GetAncestor(Handle, GA_PARENT) = GetDesktopWindow)) then begin
      fActive.BringToFront;
      if not IsWindowEnabled(fActive.Handle) then begin
        SetForegroundWindow(FindTopMostWindow(fActive.Handle));
      end;
    end
    else if (hActive = fActive.Handle) and IsWindowEnabled(hActive) then
    begin
      //Handles the case that the child Modal window pops up from the Modal
      // window and the previous parent window can still be edited after
      // switching through the taskbar icon (windows aero peek).
      hTopMost := FindTopMostWindow(fActive.Handle);
      if (hTopMost <> 0) and (hTopMost <> hActive) and IsWindowEnabled(hTopMost) then
        SetForegroundWindow(hTopMost);
    end;
  end;
end;
----------------------------------------------
-广袤璀璨的银河,永无止境的梦想(梦无止境游银河) 博客挂了……
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行85.9375毫秒 RSS