Aero Glass extension in F # (PInvoke)

I am working on a F # console application. In the properties, I set the output type of the application to the Windows application to hide the console. I also created a form to run in its place. I currently have a simple form with no controls. To make the form, I added links to System.Windows.Formsand System.Drawingand opened them with System.Runtime.InteropServices.

The part that I don’t know how to do is expanding the balloon. There are many factors in C # to do this. For example, here is the API call and the MARGINS structure:

[StructLayout(LayoutKind.Sequential)]
public struct MARGINS
{
    public int cxLeftWidth;
    public int cxRightWidth;
    public int cyTopHeight;
    public int cyBottomHeight;
}
[DllImport("dwmapi.dll")]
pubic static extend int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);

API call from the Form_Load event:

MARGINS margins = new MARGINS();
margins.cxLeftWidth = 0;
margins.cxRightWidth = 100;
margins.cyTopHeight = 0;
margins.cyBottomHeight = 0;
int result = DwmExtendFrameIntoClientArea(this.Handle, ref margins);

This is what I still have in F #:

API structure and MARGINS structure:

[<StructLayout(LayoutKind.Sequential)>]
type MARGINS =
    struct
        val cxLeftWidth : int
        val cxRightWidth : int
        val cyTopHeight : int
        val cyBottomHeigh t: int
        new(left, right, top, bottom) = { cxLeftWidth = left; cxRightWidth = right; cyTopHeight = top; cyBottomHeigh = bottom } (*Is there any other way to do this?*)
    end
[<DllImport("dwmapi.dll")>]
extend int DwmExtendFrameIntoClientArea(IntPtr hWnd, (*I need help here*))

API call from the Form_Load event:

let margins = new MARGINS(0, 100, 0, 0); (*Is there any other way to do this?*)
let result : int = DwmExtendFrameIntoClientArea(this.Handle, (*I need help here*))

, ref, F #. , #, , , int F #, , , . , , , , .

+3
1

extern (AKA P/Invoke ) F # C-like ( , extern, extend):

[<DllImport("dwmapi.dll")>]
extern int DwmExtendFrameIntoClientArea(nativeint hWnd, MARGINS& pMarInset)

:

let mutable margin = ...
let result = DwmExtendFrameIntoClientArea(this.Handle, &margin)

, , MARGINS, #. val , ( , , , ). , , mutable val :

[<Struct; StructLayout(LayoutKind.Sequential)>]
type MARGINS =  
  val mutable cxLeftWidth : int        
  val mutable cxRightWidth : int        
  val mutable cyTopHeight : int        
  val mutable cyBottomHeight: int

( Struct struct ... end, ). , #, F # :

let mutable margin = MARGINS(cxRightWidth = 100)
+5

Source: https://habr.com/ru/post/1786253/


All Articles