winform panel 컨트롤 안에 응용프로그램 실행 후 작업 표시줄에 아이콘 표시 되지 않게 하기..

안녕하세요, 응용 프로그램위 작업 표시줄 아이콘 삭제 관련 질문 드립니다.

winform 프로젝트에서 form 위에 panel 컨트롤을 올리고, 이 panel 컨트롤 안에 응용프로그램이 실행 되도록 하였습니다. 이 응용 프로그램이 작업 표시줄에 표시 되지 않게 하고 싶어서 아래와 같이 해봤지만… 윈도우 7 32비트에서는 적용 되지가 않고, 윈도우 7 64비트 되는데, 윈도우 10 / 11 애서는 됩니다…

   == Win32API 클래스 ==
[DllImport("user32.dll", EntryPoint = "GetWindowLongA", SetLastError = true)]
 public static extern long GetWindowLong(IntPtr hwnd, int nIndex);

 [DllImport("user32.dll", EntryPoint = "GetWindowLongPtr", SetLastError = true)]
 public static extern IntPtr GetWindowLongPtr64(IntPtr hWnd, int nIndex);


 public static IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex)
{
      if (IntPtr.Size == 4) // 32비트
       {
            return new IntPtr(GetWindowLong(hWnd, nIndex));
       }
      else // 64비트
       {
                return GetWindowLongPtr64(hWnd, nIndex);
        }
 }

== 메인 클래스 == 
// 작업 표시줄에 표시되지 않도록 설정
long exStyle = (long)Win32API.GetWindowLongPtr(app.MainWindowHandle, Win32API.GWL_EXSTYLE).ToInt64();
               

 //Win32API.SetWindowLong(new HandleRef(this, app.MainWindowHandle), Win32API.GWL_EXSTYLE, (int)(exStyle | Win32API.WS_EX_TOOLWINDOW));
Win32API.SetWindowLong(new HandleRef(this, app.MainWindowHandle), Win32API.GWL_EXSTYLE, (int)(exStyle | Win32API.WS_EX_TOOLWINDOW | Win32API.WS_EX_APPWINDOW));

포인터 때문인듯 한데 그냥 간단하게 아래 코드로 해보시죠.

this.ShowInTaskbar = false;
this.FormBorderStyle = FormBorderStyle.FixedToolWindow;

다른 회사 프로그램이라 ㅠㅠ 알려주신 것으로는 수정을 할 수가 없어서요

그럼 Get/Set 모두 x86/x64 버전으로 분리해서 한번 사용해보시죠.
윈도우 10/11은 모두 x64 버전인가요?

[DllImport("user32.dll", EntryPoint="GetWindowLong", SetLastError=true)]
private static extern int GetWindowLong_x86(IntPtr hWnd, GWL nIndex);

[DllImport("user32.dll", EntryPoint="GetWindowLongPtr", SetLastError=true)]
private static extern IntPtr GetWindowLongPtrImpl_x64(IntPtr hWnd, GWL nIndex);

public static IntPtr GetWindowLongPtr(IntPtr hWnd, GWL nIndex)
{
    return IntPtr.Size == 4 ? 
        (IntPtr)GetWindowLong_x86(hWnd, nIndex) : 
        GetWindowLongPtrImpl_x64(hWnd, nIndex);
}

[DllImport("user32.dll", EntryPoint="SetWindowLong", SetLastError=true)]
private static extern int SetWindowLong_x86(IntPtr hWnd, GWL nIndex, int dwNewLong);

[DllImport("user32.dll", EntryPoint="SetWindowLongPtr", SetLastError=true)]
private static extern IntPtr SetWindowLongPtr_x64(IntPtr hWnd, GWL nIndex, IntPtr dwNewLong);

public static IntPtr SetWindowLongPtr(IntPtr hWnd, GWL nIndex, IntPtr dwNewLong)
{
    return IntPtr.Size == 4 ? 
        (IntPtr)SetWindowLong_x86(hWnd, nIndex, (int)dwNewLong) : 
        SetWindowLongPtr_x64(hWnd, nIndex, dwNewLong);
}
1개의 좋아요

윈도우 10 / 11 32비트와 64비트 모두요!

신기합니다 ㅠㅠ 윈7 64비트는 작업 표시줄에 아이콘이 보일때도 있고 안 보일때도 있고 그러네여…

os가 windows embedded standard 버전 인데, 이건 또 다른 win32 api 명령어 써야하는걸까요…

 int exStyle = Win32API.GetWindowLong(app.MainWindowHandle, Win32API.GWL_EXSTYLE);

                // Modify the style
                exStyle |= Win32API.WS_EX_TOOLWINDOW;
                exStyle &= ~Win32API.WS_EX_APPWINDOW;

                // Set the new style
                Win32API.SetWindowLong(app.MainWindowHandle, Win32API.GWL_EXSTYLE, exStyle);

                // Hide and show the window for the new style to take effect
                Win32API.ShowWindow(app.MainWindowHandle, Win32API.SW_HIDE);
                Win32API.ShowWindow(app.MainWindowHandle, Win32API.SW_SHOW);

위와 같은 코드로 해도, 윈도우 7 ( Windows Embedded Standard ) 에서는 안되네요