zoukankan      html  css  js  c++  java
  • C# 使用Win32 API将1个EXE程序嵌入另1个程序中

    已经干到天快亮了,就不废话直接贴点儿代码吧

            private const int WS_THICKFRAME = 262144;
            private const int WS_BORDER = 8388608;
    
            /// <summary>
            /// 查找窗口
            ///第一个参数是窗口的标题,第二个参数可直接用 null
            ///通过窗口的标题查找对应的窗口
            /// </summary>
            [DllImport("user32.dll")]
            public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    
            //设置窗口的父窗体
            [DllImport("user32.dll", SetLastError = true)]
            private static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent); //该api用于嵌入到窗口中运行
    
            //获取窗口样式
            [DllImport("user32.dll")]
            public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
    
            //设置窗口样式
            [DllImport("user32.dll")]
            public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
    
            //设置窗口位置
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public static extern int MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool BRePaint);
    
         //设置过后就不再重复设置
         bool isSeted = false;
    
            //传入子窗体的句柄(可以使用FindWindow获取)
            public void SetWindowParent(IntPtr wnd)
            {
                if (!isSeted)
                {
                    //子窗口句柄,父窗口句柄(我这里用的Winform里的panel控件的句柄,这样就会将我的子窗口嵌入到panel里面)
                    SetParent(wnd, unityPanel.Handle);
    
                    Int32 wndStyle = GetWindowLong(wnd, -16);
                    wndStyle &= ~WS_BORDER;
                    wndStyle &= ~WS_THICKFRAME;
                    SetWindowLong(wnd, -16, wndStyle);
                    MoveWindow(wnd, 0, 0, unityPanel.Width, unityPanel.Height, true);
    
                    isSeted = true;
                }
            }    
  • 相关阅读:
    VuGen错误处理函数
    LR的日志
    创建性能测试脚本时如何选择HTML模式和URL模式
    Java变量
    查找&排序
    selenium执行JS
    Python中 is 和 == 的区别
    Python中 and or的计算规则
    selenium使用location定位元素坐标偏差
    错误:Could not find an available JavaScript runtime
  • 原文地址:https://www.cnblogs.com/mr-yoatl/p/7594750.html
Copyright © 2011-2022 走看看