mbw

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

README

mbw

Using the Windows API to pop up a message box, with four methods available: simple message, simple error/warning message, and custom message box. This feature is only supported on Windows.

Other languages: 简体中文, (Currently unable to translate more)

How to Use

go get -u github.com/skys-mission/gout/go/gui/win/mbw

Code Examples

Pop up a message box

package main

import (
	"fmt"

	"github.com/skys-mission/gout/go/gui/win/mbw"
)

func main() {
	if err := mbw.PopMsg("title", "hello mbw!"); err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
}

Output Example

mbw_pm_eg1.webp

Note that the "OK" button text is provided by the system, not by this library, and will change with the system language.

Pop up an error message box

package main

import (
	"fmt"

	"github.com/skys-mission/gout/go/gui/win/mbw"
)

func main() {
	if err := mbw.PopErrMsg("mbw error!"); err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
}

Output Example

mbw_pem_eg1.webp

Note that the "OK" button text is provided by the system, not by this library, and will change with the system language.

Pop up a warning message box

package main

import (
	"fmt"

	"github.com/skys-mission/gout/go/gui/win/mbw"
)

func main() {
	if err := mbw.PopWarningMsg("mbw warning"); err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
}

Output Example

mbw_pwm_eg1.webp

Note that the "OK" button text is provided by the system, not by this library, and will change with the system language.

Pop up a custom message box

package main

import (
	"fmt"

	"github.com/skys-mission/gout/go/gui/win/mbw"
)

func main() {
	cb, err := mbw.PopCustomMsg(
		"title",
		"message",
		mbw.MB_ABORTRETRYIGNORE,
		0)
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
	switch cb {
	case mbw.ID_RETRY:
		fmt.Println("retry button clicked")
	case mbw.ID_ABORT:
		fmt.Println("abort button clicked")
	default:
		fmt.Printf("%v clicked\n", cb)
	}
}

Output Example

mbw_pcm_eg1.webp

retry button clicked
Process finished with the exit code 0

The text on the buttons is provided by the system and will change with the system language.

Documentation

Index

Constants

View Source
const (
	MB_OK                   = 0x00000000         // OK button only
	MB_OKCANCEL             = 0x00000001         // OK and Cancel buttons
	MB_ABORTRETRYIGNORE     = 0x00000002         // Abort, Retry, and Ignore buttons
	MB_YESNOCANCEL          = 0x00000003         // Yes, No, and Cancel buttons
	MB_YESNO                = 0x00000004         // Yes and No buttons
	MB_RETRYCANCEL          = 0x00000005         // Retry and Cancel buttons
	MB_CANCELTRYCONTINUE    = 0x00000006         // Cancel, Try Again, Continue buttons
	MB_ICONHAND             = 0x00000010         // Stop sign icon (Error)
	MB_ICONQUESTION         = 0x00000020         // Question mark icon (Query)
	MB_ICONEXCLAMATION      = 0x00000030         // Exclamation mark icon (Warning)
	MB_ICONASTERISK         = 0x00000040         // Asterisk icon (Information)
	MB_USERICON             = 0x00000080         // User-defined icon
	MB_ICONWARNING          = MB_ICONEXCLAMATION //Alias for the warning icon
	MB_ICONERROR            = MB_ICONHAND        //Alias for the error icon
	MB_ICONINFORMATION      = MB_ICONASTERISK    //Alias for the information icon
	MB_ICONSTOP             = MB_ICONHAND        //Alias for the stop icon
	MB_DEFBUTTON1           = 0x00000000         // First button is the default
	MB_DEFBUTTON2           = 0x00000100         // Second button is the default
	MB_DEFBUTTON3           = 0x00000200         // Third button is the default
	MB_DEFBUTTON4           = 0x00000300         // Fourth button is the default
	MB_APPLMODAL            = 0x00000000         // Application modal message box
	MB_SYSTEMMODAL          = 0x00001000         // System modal message box
	MB_TASKMODAL            = 0x00002000         // Task modal message box
	MB_HELP                 = 0x00004000         // Help button is included
	MB_SETFOREGROUND        = 0x00010000         // Bring the window to the foreground
	MB_DEFAULT_DESKTOP_ONLY = 0x00020000         // Only show on the default desktop
	MB_TOPMOST              = 0x00040000         // Message box is topmost
	MB_RIGHT                = 0x00080000         // Text is right-justified
	MB_RTLREADING           = 0x00100000         // Text is displayed with right-to-left reading order
	MB_SERVICE_NOTIFICATION = 0x00200000         // Service notification message box
)

MessageBox format constants

View Source
const (
	ID_OK     = 1 // OK button identifier
	ID_CANCEL = 2 // Cancel button identifier
	ID_ABORT  = 3 // Abort button identifier
	ID_RETRY  = 4 // Retry button identifier
	ID_IGNORE = 5 // Ignore button identifier
	ID_YES    = 6 // Yes button identifier
	ID_NO     = 7 // No button identifier
)

MessageBox button callback constants

Variables

This section is empty.

Functions

func PopCustomMsg

func PopCustomMsg(title, message string, format uintptr, hwnd uintptr) (cb uintptr, err error)

PopCustomMsg function is used to display a custom message box on the Windows platform.

Parameters: title: The title of the message box. message: The message content of the message box. format: The flag bits for the message box. hwnd: The parent window handle, 0 indicates no parent window.

Return values: cb: The button number clicked by the user. err: Error information, nil if the operation is successful.

func PopErrMsg

func PopErrMsg(message string) (err error)

PopErrMsg function is used to display an error message box on the Windows platform.

Parameters: message string - The message content to be displayed in the error message box.

Return value: err error - The error of the function call, nil for success, otherwise the reason for the error.

func PopMsg

func PopMsg(title, message string) (err error)

PopMsg function is used to display a message box on the Windows platform title: The title of the message box message: The message content of the message box The return value is of type error, indicating whether the function call was successful, nil for success, otherwise the reason for the error

func PopWarningMsg

func PopWarningMsg(message string) (err error)

PopWarningMsg displays a Windows message box.

Parameters: message string - The content of the message to be displayed.

Returns: err error - Returns an error if the function call fails, otherwise nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL