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;
                }
            }    
  • 相关阅读:
    C++——模板、数组类
    JSP教程(四)—— JSP内置对象(上)
    JSP教程(三)—— 基本语法
    JSP教程(二)—— JavaWeb简介
    JSP教程(一)—— JavaWeb开发环境
    关于余弦定理的一些见解
    文本相似度比较(网页版)
    关于SimHash算法的实现及测试V4.0
    关于SimHash算法的实现及测试V3.0
    关于SimHash算法的实现及测试V2.0
  • 原文地址:https://www.cnblogs.com/mr-yoatl/p/7594750.html
Copyright © 2011-2022 走看看