zoukankan      html  css  js  c++  java
  • 在窗体中嵌入 应用程序

    //在窗体中嵌入应用程序
    //show
       Process process = null;
            IntPtr appWin;
            private string exeName = "";
    
            [DllImport("user32.dll", SetLastError = true)]
            private static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
    
    
            [DllImport("user32.dll", SetLastError = true)]
            private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
    private void button1_Click(object sender, EventArgs e)
            {
                this.exeName = IniHelper.IniData.VideoUrl.pathvalue;
                try
                {
                    // Start the process
                    process = System.Diagnostics.Process.Start(this.exeName);
                    // Wait for process to be created and enter idle condition
                    process.WaitForInputIdle();
    
                    // Get the main handle
                    appWin = process.MainWindowHandle;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, "Error");
                }
                // Put it into this form
                SetParent(appWin, this.Handle);
                // Remove border and whatnot
                // SetWindowLong(appWin, GWL_STYLE, WS_VISIBLE);
                // Move the window to overlay it on this window
                MoveWindow(appWin, 0, 0, this.Width, this.Height, true);
            }
            private void Form2_FormClosed(object sender, FormClosedEventArgs e)
            {
                try
                {
                    process.Kill();
                }
                catch { }
            }
            private void Form2_Resize(object sender, EventArgs e)
            {
                if (this.appWin != IntPtr.Zero)
                {
                    MoveWindow(appWin, 0, 0, this.Width, this.Height, true);
                }
                //base.OnResize(e);
            }
      
  • 相关阅读:
    直接拿来用 九个超实用的PHP代码片段(二)
    微信开发值得推荐的开源项目
    PHP文件下载原理
    简化PHP开发的10个工具
    CI Weekly #1 | 这份周刊,带你了解 CI/CD 、DevOps、自动化测试
    fir.im Weekly
    fir.im Weekly
    fir.im Weekly
    用 flow.ci 让 Hexo 持续部署
    fir.im Weekly
  • 原文地址:https://www.cnblogs.com/z45281625/p/10935356.html
Copyright © 2011-2022 走看看