我发布了这个问题,我希望找出答案。我的问题是:如何在F#中使代码功能如下:
首先,将这些声明添加到Window类中:
private const int GWL_STYLE = -16;
private const int WS_SYSMENU = 0x80000;
[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);
然后将此代码放入Window的Loaded事件:
var hwnd = new WindowInteropHelper(this).Handle;
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
答案 0 :(得分:0)
tom.maruska 到F#的翻译代码如下所示:
type HideCloseButtonOnWindow() =
inherit Behavior<Window>()
let GWL_STYLE = -16;
let WS_SYSMENU = 0x80000;
[<DllImport("user32.dll", SetLastError = true)>]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[<DllImport("user32.dll")>]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
override x.OnAttached() =
base.OnAttached()
x.AssociatedObject.Loaded.AddHandler(fun s e -> x.OnLoaded(s,e))
override x.OnDetaching() =
x.AssociatedObject.Loaded.RemoveHandler(fun s e -> x.OnLoaded(s,e))
base.OnDetaching()
member x.OnLoaded(sender:obj, e:RoutedEventArgs) =
let hwnd = (new WindowInteropHelper(x.AssociatedObject)).Handle
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) &&& ~~~WS_SYSMENU)
|> ignore
你应该打开:
open System.Windows.Interactivity
open System.Runtime.InteropServices
open System.Windows.Interop