2010-08-11 6 views
2

특히 버튼을 제거하는 것뿐만 아니라 최대화를 완전히 비활성화하는 것입니다. 이것은 제목 표시 줄을 두 번 클릭하거나 제목 표시 줄을 Windows 7의 화면 맨 위로 끌어 오면 작동하지 않는다는 것을 의미합니다. 나는 여전히 창을 꽤 큰 크기로 만들고 싶다.WPF에서 창 최대화를 방지 할 수 있습니까?

+1

그래서 그것의 크기를 조정할 수있다? 그게 내가 수동으로 그것을 화면의 전체 크기로 끌고, 기본적으로 최대화 할 수 있다는 뜻이 아니겠습니까? 창을 최대화 할 수없는 이유는 무엇입니까? 귀하의 창문에 대해 무엇이 중요합니까? 전체 화면으로 늘릴 수는 있지만 단순히 버튼을 사용하지 않고 언제나 똑같이 사용했습니다. –

+3

왜 사람들은 StackOverflow에서이 작업을 일관되게합니까? 질문에 답하기보다는 질문이 왜 필요한지 질문하기 시작합니다. 이것은 도움이되지 않습니다. 소프트웨어의 요구 사항으로 받아 들여 방법을 알고 있거나 혼자있는 경우 대답하십시오. 이 경우 고객은 수천 유로를 지불하기를 원하기 때문입니다. –

답변

2

CanMinimize 필드를 살펴보십시오.

+0

그건 내가 원하는 것을하지 않습니다. 최대화를 비활성화하고 크기를 조정할 수 있습니다. CanMinimize는 크기 조정을 방지합니다. –

+0

... 사람들의 철자가 틀리지 않을 때 바꾸는 것은 무례합니다. 우리는 당신이 알고있는 모든 미국인이 아닙니다;) –

+1

미안 합니다만, 가치가있는 "Maximize"는 MSDN 문서와 일치합니다 :) –

1

시스템 메뉴에서 최대화를 제거하면 충분합니다. Win7 "도킹"을 위해 작동하는지 모르겠다면 알려주십시오. http://www.codeguru.com/csharp/csharp/cs_misc/userinterface/article.php/c9327/

그것은하지만 당신은 창 핸들을하기 만하기 때문에, 윈폼을 가정

다음은 윈도우의 시스템 메뉴를 수정하기위한 헬퍼 클래스와 기사입니다. WPF에서는 WindowInteropHelper를 사용하여이 작업을 수행 할 수 있습니다.

업데이트 된이 코드는 불가지론 UI 프레임 워크

using System; 
using System.ComponentModel; 
using System.Runtime.InteropServices; 

[Flags] 
public enum SystemMenuFlags 
{ 
    Unchecked = 0x0000, 
    String = 0x0000, 
    Disabled = 0x0002, 
    Grayed = 0x0001, 
    Checked = 0x0008, 
    Popup = 0x0010, 
    BarBreak = 0x0020, 
    Break = 0x0040, 
    ByPosition = 0x0400, 
    ByCommand = 0x0000, 
    Separator = 0x0800, 
} 

public enum SystemMenuCommand 
{ 
    Size = 0xF000, 
    Move = 0xF010, 
    Minimize = 0xF020, 
    Maximize = 0xF030, 
    Close = 0xF060, 
    Restore = 0xF120, 
} 

public class SystemMenu 
{ 
    private IntPtr _menuHandle = IntPtr.Zero; 
    public IntPtr MenuHandle { get { return _menuHandle; } } 
    private readonly IntPtr _windowHandle; 
    public IntPtr WindowHandle { get { return _windowHandle; } } 


    public SystemMenu(IntPtr windowHandle) 
    { 
     if (windowHandle == IntPtr.Zero) 
      throw new InvalidOperationException("The handle must point to a real window. Create only after your window object has created a real window."); 
     _windowHandle = windowHandle; 
     IntPtr menuHandle = GetSystemMenu(windowHandle, 0); 
     if (menuHandle == IntPtr.Zero) 
      throw new InvalidOperationException("The specified window does not have a system menu."); 
     _menuHandle = menuHandle; 
    } 

    private SystemMenu(IntPtr windowHandle, IntPtr menuHandle) 
    { 
     _windowHandle = windowHandle; 
     _menuHandle = menuHandle; 
    } 

    public static SystemMenu FromHandle(IntPtr windowHandle) 
    { 
     if (windowHandle == IntPtr.Zero) 
      throw new InvalidOperationException("The handle must point to a real window. Call FromHandle only after your window object has created a real window."); 
     IntPtr menuHandle = GetSystemMenu(windowHandle, 0); 
     if (menuHandle == IntPtr.Zero) 
      return null; 
     return new SystemMenu(windowHandle, menuHandle); 
    } 

    public int Count 
    { 
     get 
     { 
      int count = GetMenuItemCount(MenuHandle); 
      if (count < 0) 
       throw new Win32Exception(Marshal.GetLastWin32Error()); 
      return count; 
     } 
    } 

    private int GetItemPosition(SystemMenuCommand command) 
    { 
     int count = Count; 
     for (int position = 0; position < count; position++) 
     { 
      int id = GetMenuItemID(MenuHandle, position); 
      if ((SystemMenuCommand)id == command) 
       return position; 
     } 

     return -1; 
    } 

    public void InsertItem(int position, int id, string text) 
    { 
     if (String.IsNullOrEmpty(text)) 
      throw new ArgumentNullException("text"); 
     if (!IsValidMenuIdValue(id)) 
      throw new ArgumentOutOfRangeException("id", "Valid range for menu id is [0 .. 0xF000]"); 
     if (InsertMenu(MenuHandle, position, (Int32)(SystemMenuFlags.ByPosition | SystemMenuFlags.String), id, text) == 0) 
      throw new Win32Exception(Marshal.GetLastWin32Error()); 
    } 

    public void InsertSeparator(int position) 
    { 
     if (InsertMenu(MenuHandle, position, (Int32)(SystemMenuFlags.ByPosition | SystemMenuFlags.Separator), 0, String.Empty) == 0) 
      throw new Win32Exception(Marshal.GetLastWin32Error()); 
    } 

    public void InsertItemBefore(SystemMenuCommand command, int id, string text) 
    { 
     if (String.IsNullOrEmpty(text)) 
      throw new ArgumentNullException("text"); 
     if (!IsValidMenuIdValue(id)) 
      throw new ArgumentOutOfRangeException("id", "Valid range for menu id is [0 .. 0xF000]"); 
     if (InsertMenu(MenuHandle, (int)command, (Int32)(SystemMenuFlags.ByCommand | SystemMenuFlags.String), id, text) == 0) 
      throw new Win32Exception(Marshal.GetLastWin32Error()); 
    } 

    public void InsertSeparatorBefore(SystemMenuCommand command) 
    { 
     if (InsertMenu(MenuHandle, (int)command, (Int32)(SystemMenuFlags.ByCommand | SystemMenuFlags.Separator), 0, String.Empty) == 0) 
      throw new Win32Exception(Marshal.GetLastWin32Error()); 
    } 

    public void InsertItemAfter(SystemMenuCommand command, int id, string text) 
    { 
     if (String.IsNullOrEmpty(text)) 
      throw new ArgumentNullException("text"); 
     if (!IsValidMenuIdValue(id)) 
      throw new ArgumentOutOfRangeException("id", "Valid range for menu id is [0 .. 0xF000]"); 
     int position = GetItemPosition(command); 
     InsertItem(position + 1, id, text); 
    } 

    public void InsertSeparatorAfter(SystemMenuCommand command) 
    { 
     int position = GetItemPosition(command); 
     InsertSeparator(position + 1); 
    } 

    public void AppendSeparator() 
    { 
     if (AppendMenu(MenuHandle, (int)SystemMenuFlags.Separator, 0, String.Empty) == 0) 
      throw new Win32Exception(Marshal.GetLastWin32Error()); 
    } 

    public void AppendItem(int id, string text) 
    { 
     if (String.IsNullOrEmpty(text)) 
      throw new ArgumentNullException("text"); 
     if (!IsValidMenuIdValue(id)) 
      throw new ArgumentOutOfRangeException("id", "Valid range for menu id is [0 .. 0xF000]"); 
     if (AppendMenu(MenuHandle, (int)SystemMenuFlags.String, id, text) == 0) 
      throw new Win32Exception(Marshal.GetLastWin32Error()); 
    } 

    public void RemoveItem(int position) 
    { 
     if (RemoveMenu(MenuHandle, position, (int)SystemMenuFlags.ByPosition) == 0) 
      throw new Win32Exception(Marshal.GetLastWin32Error()); 
    } 

    public void RemoveItem(SystemMenuCommand command) 
    { 
     if (RemoveMenu(MenuHandle, (int)command, (int)SystemMenuFlags.ByCommand) == 0) 
      throw new Win32Exception(Marshal.GetLastWin32Error()); 
    } 

    public void Reset() 
    { 
     GetSystemMenu(WindowHandle, 1); 
     _menuHandle = GetSystemMenu(WindowHandle, 0); 
    } 

    public static bool IsValidMenuIdValue(int id) 
    { 
     return id > 0 && id < 0xF000; 
    } 

    #region p/Invoke 

    [DllImport("User32")] 
    extern static IntPtr GetSystemMenu(IntPtr hWnd, int bRevert); 
    [DllImport("User32", CharSet = CharSet.Auto, SetLastError = true)] 
    extern static int AppendMenu(IntPtr hMenu, int uFlags, int uIDNewItem, string lpNewItem); 
    [DllImport("User32", CharSet = CharSet.Auto, SetLastError = true)] 
    extern static int InsertMenu(IntPtr hMenu, int uPosition, int uFlags, int uIDNewItem, string lpNewItem); 
    [DllImport("User32", SetLastError = true)] 
    extern static int RemoveMenu(IntPtr hMenu, int uPosition, int uFlags); 
    [DllImport("User32", SetLastError = true)] 
    extern static int GetMenuItemCount(IntPtr hMenu); 
    [DllImport("User32")] 
    extern static int GetMenuItemID(IntPtr hMenu, int nPos); 

    #endregion 
} 
관련 문제