zoukankan      html  css  js  c++  java
  • c#: 以模态窗口显示于其它进程窗体之前

    产品之工具箱,需要工具以模态窗体,显示于主界面之上。记下代码点,以做备忘。

    1、IWin32Window

        internal class Win32Window : IWin32Window
        {
            public Win32Window(IntPtr handle)
            {
                this.Handle = handle;
            }
    
            public IntPtr Handle
            {
                get;
                private set;
            }
        }

    2、窗体显示处理

        static class Program
        {
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main(string[] args)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                var mainForm = new MainForm();
                int h;
    //这里,当再加入窗体是否有效判断
    if (args.Length == 0 || !int.TryParse(args[0], out h)) Application.Run(mainForm); else { var w = new Win32Window((IntPtr)h); mainForm.ShowDialog(w); } } }

    3、同样功能,Delphi实现:

    i. 窗体重截CaramParams:

    procedure TfrmMain.CreateParams;
    begin
      inherited CreateParams(Params);
      Params.WndParent := PHwnd;
    end;

    ii. 修正工程文件:

    begin
      if ParamCount <> 0 then
        PHwnd := StrToInt(ParamStr(1));
    
      Application.Initialize;
      Application.MainFormOnTaskbar := True;
      MainForm := TForm1.Create(Application);
      EnableWindow(PHwnd, False);
      MainForm.ShowModal;
      EnableWindow(PHwnd, True);
    end.

    同类方案参考资料,但不完美:

    c# - Show any Process like Modal Window - Stack Overflow

  • 相关阅读:
    Mysql配置文件模板
    shell命令记录
    SuSE Linux Enterprise Server
    安装jdk1.8
    云南-第一个应用节点-ssh登录-卡顿的问题
    Python重新安装pip
    Centos6.5修改镜像为国内的阿里云源
    supervisord.conf
    Pandas连接Mysql数据库
    Vim速查命令简版
  • 原文地址:https://www.cnblogs.com/crwy/p/8950357.html
Copyright © 2011-2022 走看看