wpfbutton按钮禁用_WPF如何禁用最小化按钮 | 学步园

使用默认的样式设置,只能设置禁用最大化,无法设置禁用最小化。最终还是发现,需要用到api函数。只是不知道在win7下面工作情况如何。

I've stolen some code I found on the MSDN forums and made an extension method on the Window class, like this:

internalstaticclassWindowExtensions{[DllImport("user32.dll")]internalexternstaticintSetWindowLong(IntPtrhwnd,intindex,intvalue);[DllImport("user32.dll")]internalexternstaticintGetWindowLong(IntPtrhwnd,intindex);internalstaticvoidHideMinimizeAndMaximizeButtons(thisWindowwindow){constintGWL_STYLE=-16;IntPtrhwnd=newSystem.Windows.Interop.WindowInteropHelper(window).Handle;longvalue=GetWindowLong(hwnd,GWL_STYLE);SetWindowLong(hwnd,GWL_STYLE,(int)(value&-131073&-65537));}}

The only other thing to remember is that for some reason this doesn't work from a window's constructor. I got around that by chucking this into the constructor:

this.SourceInitialized+=(x,y)=>{this.HideMinimizeAndMaximizeButtons();};

Hope this helps!

移除关闭按钮

// Disable close button

privateconstintMF_BYPOSITION=0x400

;

[

DllImport("User32"

)]

privatestaticexternintRemoveMenu(IntPtrhMenu,intnPosition,intwFlags

);

[

DllImport("User32"

)]

privatestaticexternIntPtrGetSystemMenu(IntPtrhWnd,boolbRevert

);

[

DllImport("User32"

)]

privatestaticexternintGetMenuItemCount(IntPtrhWnd

);

internalstaticvoidRemoveCloseButton(Windowwindow

)

{

IntPtrhMenu=GetSystemMenu(newWindowInteropHelper(window).Handle,false

);

intmenuItemCount=GetMenuItemCount(hMenu

);

RemoveMenu(hMenu,menuItemCount-1,MF_BYPOSITION

);

禁用最小化或最大化按钮

// Disable minimize and maximize buttons

[

DllImport("user32.dll"

)]

internalexternstaticintSetWindowLong(IntPtrhwnd,intindex,intvalue

);

[

DllImport("user32.dll"

)]

internalexternstaticintGetWindowLong(IntPtrhwnd,intindex

);

internalstaticvoidDisableMinimizeButton(thisWindowwindow

)

{

constintGWL_STYLE= -16

;

IntPtrhwnd=newSystem.Windows.Interop.WindowInteropHelper(window).Handle

;

longvalue=GetWindowLong(hwnd,GWL_STYLE

);

SetWindowLong(hwnd,GWL_STYLE, (int)(value& -131073

));

}

internalstaticvoidDisableMaximizeButton(thisWindowwindow

)

{

constintGWL_STYLE= -16

;

IntPtrhwnd=newSystem.Windows.Interop.WindowInteropHelper(window).Handle

;

longvalue=GetWindowLong(hwnd,GWL_STYLE

);

SetWindowLong(hwnd,GWL_STYLE, (int)(value& -65537

));

internalstaticvoidDisableMinimizeAndMaximizeButtons(thisWindowwindow)

{

constintGWL_STYLE= -16;

IntPtrhwnd=newSystem.Windows.Interop.WindowInteropHelper(window).Handle;

longvalue=GetWindowLong(hwnd,GWL_STYLE);

SetWindowLong(hwnd,GWL_STYLE, (int)(value& -65537& -131073));

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值