0% found this document useful (0 votes)
14 views2 pages

Codeexemoi

This document provides a solution for embedding an external .exe application inside a Panel in a C# WinForms application while hiding its title bar, tool buttons, and window decorations. It details the use of Windows API functions to modify the window style by removing specific attributes such as WS_CAPTION, WS_BORDER, and WS_DLGFRAME. The expected outcome is that the external application runs seamlessly within the Panel, appearing as a native component of the WinForms UI.

Uploaded by

Chien Co
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Codeexemoi

This document provides a solution for embedding an external .exe application inside a Panel in a C# WinForms application while hiding its title bar, tool buttons, and window decorations. It details the use of Windows API functions to modify the window style by removing specific attributes such as WS_CAPTION, WS_BORDER, and WS_DLGFRAME. The expected outcome is that the external application runs seamlessly within the Panel, appearing as a native component of the WinForms UI.

Uploaded by

Chien Co
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

f you want to hide the title bar, tool buttons, and window decorations of an .

exe
running inside a Panel in a C# WinForms application, you can use the Windows API
(user32.dll) to modify the window style.

---

Solution: Remove Title Bar & Borders

You need to remove window decorations by modifying the GWL_STYLE attribute of the
window using the SetWindowLong function.

---

Updated Code to Hide Toolbars and Borders

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace EmbedExeWinForms
{
public partial class MainForm : Form
{
// Import necessary Windows API functions
[DllImport("user32.dll")]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr
hWndNewParent);

[DllImport("user32.dll", SetLastError = true)]


private static extern int GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int
dwNewLong);

private const int GWL_STYLE = -16; // Window Style


private const int WS_BORDER = 0x00800000;
private const int WS_DLGFRAME = 0x00400000;
private const int WS_CAPTION = 0x00C00000; // Includes title bar and
borders

public MainForm()
{
InitializeComponent();
RunExternalAppInsidePanel();
}

private void RunExternalAppInsidePanel()


{
Process process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = @"C:\Path\To\YourApp.exe", // Replace with your EXE
file path
WindowStyle = ProcessWindowStyle.Normal
}
};

process.Start();
process.WaitForInputIdle();

if (process.MainWindowHandle != IntPtr.Zero)
{
// Embed the EXE window into the panel
SetParent(process.MainWindowHandle, this.panelContainer.Handle);

// Remove the title bar and borders


int style = GetWindowLong(process.MainWindowHandle, GWL_STYLE);
SetWindowLong(process.MainWindowHandle, GWL_STYLE, style &
~WS_CAPTION & ~WS_BORDER & ~WS_DLGFRAME);
}
}
}
}

---

How This Works

1. SetParent → Embeds the external .exe inside a WinForms Panel.

2. GetWindowLong / SetWindowLong → Modifies the window style to remove the title


bar, toolbar, and borders.

3. Removes WS_CAPTION, WS_BORDER, and WS_DLGFRAME to ensure the embedded window has
no decorations.

---

Expected Outcome

The external application runs inside your Panel without a title bar, menu, or
borders.

The application behaves like a native part of your WinForms UI.

Let me know if you need more tweaks!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy