win32_messagebox

    Download zip
    Author
    Version
    0.1.2
    License
    MIT
    Last updated
    5 months ago
    Downloads
    77

    #moonbit win32_messagebox

    A simple Win32 message box for MoonBit.

    moonbit message box

    message_box

    fn message_box(hWnd : Int, lpText : Bytes, lpCaption : Bytes, uType : Int) -> Int

    FFI binding to Windows MessageBoxW API function.

    This function displays a modal dialog box that contains a system icon, a set of buttons, and a brief application-specific message. The user can interact with the dialog by clicking one of the buttons.

    This is a direct FFI binding to the Windows MessageBoxW function, which uses UTF-16 (wide character) strings for full Unicode support.

    Parameters

    • hWnd: Handle to the owner window of the message box. Use 0 for no owner
    • lpText: The message text to display (must be UTF-16 encoded)
    • lpCaption: The dialog box title (must be UTF-16 encoded)
    • uType: The contents and behavior of the dialog box (combination of flags)

    Common uType Values

    Button types:
    • 0x00000000 (MB_OK): OK button only
    • 0x00000001 (MB_OKCANCEL): OK and Cancel buttons
    • 0x00000004 (MB_YESNO): Yes and No buttons
    • 0x00000003 (MB_YESNOCANCEL): Yes, No, and Cancel buttons

    Icon types:
    • 0x00000010 (MB_ICONERROR): Error icon
    • 0x00000020 (MB_ICONQUESTION): Question icon
    • 0x00000030 (MB_ICONWARNING): Warning icon
    • 0x00000040 (MB_ICONINFORMATION): Information icon

    Returns

    An integer indicating which button the user clicked:
    • 1 (IDOK): OK button
    • 2 (IDCANCEL): Cancel button
    • 6 (IDYES): Yes button
    • 7 (IDNO): No button
    • 0: Function failed

    Example

    let result = message_box(0,
    @ffi.to_wstr("Save changes before closing?"),
    @ffi.to_wstr("Unsaved Changes"),
    0x00000023) // MB_ICONQUESTION | MB_YESNOCANCEL

    match result {
    1 => println("User clicked OK")
    2 => println("User clicked Cancel")
    6 => println("User clicked Yes")
    7 => println("User clicked No")
    0 => println("Message box failed")
    _ => println("Unexpected result")
    }

    Note

    • This function is Windows-specific and will not work on other platforms
    • String parameters must be converted to UTF-16 using @ffi.to_wstr()
    • The message box is modal and blocks execution until user interaction
    • Use 0 for hWnd to create a system modal dialog

    Source Files