안녕하세요… c# winform 프로젝트에서 panel 컨트롤 안에 응용 프로그램이 실행 되도록 하고 있습니다.
어떤 프로그램은 적용이 잘 되는데, 어떤 프로그램은 안되는데요.
안되는 이유가 뭔지 알고 싶습니다… 아래는 제가 작성한 코드입니다.
WinMergeU 프로그램은 정상적으로 되고,
bmrelay.exe(배달의 민족 PC 접수 프로그램) 이 프로그램은 되지 않습니다…
[DllImport("user32.dll", SetLastError = true)]
private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
[DllImport("user32.dll", SetLastError = true)]
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);
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
private const int GWL_STYLE = -16;
private const int WS_CHILD = 0x40000000;
private const int WS_BORDER = 0x00800000;
private const int WS_DLGFRAME = 0x00400000;
private const int WS_CAPTION = WS_BORDER | WS_DLGFRAME;
private const int SW_HIDE = 0;
private const int SW_SHOW = 5;
private const int SWP_NOSIZE = 0x0001;
public Form1()
{
InitializeComponent();
}
Process process = null;
private void button1_Click(object sender, EventArgs e)
{
if (process == null)
{
process = new Process();
OperatingSystem os = Environment.OSVersion;
string bit_type = Environment.Is64BitOperatingSystem ? "64" : "32";
string path = string.Empty;
path = "C:\\Program Files (x86)\\WinMerge\\WinMergeU.exe";
//path = "C:\\BaeminRelay\\bmrelay.exe";
process.StartInfo.FileName = path;
//process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
process.Start();
// 대기 시간 추가
process.WaitForInputIdle();
IntPtr ptr = IntPtr.Zero;
while ((ptr = process.MainWindowHandle) == IntPtr.Zero) ;
// Set the window style to WS_CHILD (None)
int style = GetWindowLong(process.MainWindowHandle, GWL_STYLE);
style = style & ~WS_CAPTION; // Remove caption style
SetWindowLong(process.MainWindowHandle, GWL_STYLE, style);
SetParent(process.MainWindowHandle, panel1.Handle);
// Move the window and prevent resizing
MoveWindow(process.MainWindowHandle, 0, 0, panel1.Width, panel1.Height, true);
SetWindowLong(process.MainWindowHandle, GWL_STYLE, style | SWP_NOSIZE);
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (process != null)
{
try
{
process.Kill();
}
catch (Exception ex)
{
//MessageBox.Show($"Error while killing process: {ex.Message}");
}
}
}