1

I would like to use the code here to suspend screen refresh of a rich text box in code I am writing using F#. I don't know how to use SendMessage (or WM_SETREDRAW or EM_GETEVENTMASK for that matter). How can I declare and use the relevant functions from F#?

The code:

private void StopRepaint()
{
    // Stop redrawing:
    SendMessage(this.Handle, WM_SETREDRAW, 0, IntPtr.Zero);
    // Stop sending of events:
    eventMask = SendMessage(this.Handle, EM_GETEVENTMASK, 0, IntPtr.Zero);
}
Community
  • 1
  • 1
Muhammad Alkarouri
  • 23,884
  • 19
  • 66
  • 101

1 Answers1

2

Msdn documents how to declare external functions in F#.

Your function would look something like:

open System
open System.Runtime.InteropServices

module InteropWithNative =
    [<DllImport(@"User32")>]
    extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam)
Robert
  • 6,407
  • 2
  • 34
  • 41
  • 1
    Was enough of a hint for me to figure out the rest. Thanks! – Muhammad Alkarouri Dec 26 '11 at 14:20
  • `Msg` should be `int` or `uint32`, not `IntPtr` -- as you have it, there will be a stack imbalance on x64 platforms. (Also, it's more idiomatic to use `nativeint` than `IntPtr` in F#, but that has no technical bearing here.) – ildjarn Dec 26 '11 at 21:03
  • Fixed the Msg parameter type. I think it's fine to use either IntPtr or nativeint, I don't see one as being more idiomatic than the other. – Robert Dec 27 '11 at 08:46
  • @Robert : Well, one is a type alias that is always in scope (unless shadowed), while the other requires an `open`; one would agree that using `int` and `string` in C# are idiomatic over using `Int32` and `String` for the same reason, no? In any case, like I said, that has no technical bearing, so +1 for your edit. :-] – ildjarn Dec 27 '11 at 20:49