windows

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

具体请参考:https://learn.microsoft.com/zh-cn/windows/win32/

Index

Constants

View Source
const (
	// 窗口
	IDC_ARROW     = 32512 // 正常选择光标
	COLOR_WINDOW  = 5
	CW_USEDEFAULT = 0x80000000 // 窗口x、y、w、h

	// 从本地加载图片
	IMAGE_ICON      = 1
	LR_LOADFROMFILE = 0x00000010
	LR_DEFAULTSIZE  = 0x00000040

	// 托盘
	NIM_ADD     = 0x00000000
	NIM_MODIFY  = 0x00000001
	NIF_ICON    = 0x00000002
	NIF_MESSAGE = 0x00000001
	NIF_TIP     = 0x00000004
	NIF_INFO    = 0x00000010
	NIIF_INFO   = 0x00000001
	NIF_STATE   = 0x00000008

	// 消息
	WM_COMMAND         = 0x0111
	WM_LBUTTONUP       = 0x0202
	WM_RBUTTONUP       = 0x0205
	WM_USER            = 0x0400
	WM_TRAY_NOTIFYICON = WM_USER + 1 // 自定义托盘消息
	WM_CLOSE           = 0x0010
	WM_CREATE          = 0x0001
	WM_SYSCOMMAND      = 0x0112 // 当用户选择最大化按钮、最小化按钮、还原按钮或关闭按钮时,窗口会收到此消息
	WM_DESTROY         = 0x0002 // 在窗口被销毁时发送

	// 菜单
	TPM_RETURNCMD  = 0x0100
	TPM_NONOTIFY   = 0x0080
	TPM_LEFTBUTTON = 0x0000
	MF_SEPARATOR   = 0x00000800
	MF_STRING      = 0x00000000
	MF_CHECKED     = 0x00000008
	MF_UNCHECKED   = 0x00000000
	MF_BYCOMMAND   = 0x000
	MF_POPUP       = 0x00000010

	// 窗口
	WS_OVERLAPPED       = 0x00000000
	WS_CAPTION          = 0x00C00000 // WS_BORDER | WS_DLGFRAME
	WS_SYSMENU          = 0x00080000
	WS_THICKFRAME       = 0x00040000
	WS_MINIMIZEBOX      = 0x00020000
	WS_MAXIMIZEBOX      = 0x00010000
	WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX)
	CS_HREDRAW          = 0x0002
	CS_VREDRAW          = 0x0001
)

常量标识

Variables

View Source
var (
	GetModuleHandle = kernel32.MustFindProc("GetModuleHandleW")

	LoadIcon            = user32.MustFindProc("LoadIconW")
	LoadCursor          = user32.MustFindProc("LoadCursorW")
	RegisterClassEx     = user32.MustFindProc("RegisterClassExW")
	CreateWindowEx      = user32.MustFindProc("CreateWindowExW")
	ShowWindow          = user32.MustFindProc("ShowWindow")
	UpdateWindow        = user32.MustFindProc("UpdateWindow")
	GetMessage          = user32.MustFindProc("GetMessageW")
	TranslateMessage    = user32.MustFindProc("TranslateMessage")
	DispatchMessage     = user32.MustFindProc("DispatchMessageW")
	PostQuitMessage     = user32.MustFindProc("PostQuitMessage")
	DestroyWindow       = user32.MustFindProc("DestroyWindow")
	DefWindowProc       = user32.MustFindProc("DefWindowProcW")
	LoadImage           = user32.MustFindProc("LoadImageW")
	CreatePopupMenu     = user32.MustFindProc("CreatePopupMenu")
	AppendMenu          = user32.MustFindProc("AppendMenuW")
	GetCursorPos        = user32.MustFindProc("GetCursorPos")
	TrackPopupMenu      = user32.MustFindProc("TrackPopupMenu")
	SetForegroundWindow = user32.MustFindProc("SetForegroundWindow")
	UnregisterClass     = user32.MustFindProc("UnregisterClassW")
	CheckMenuItem       = user32.MustFindProc("CheckMenuItem")
	SetProcessDPIAware  = user32.MustFindProc("SetProcessDPIAware")

	ShellNotifyIcon                         = shell32.MustFindProc("Shell_NotifyIconW")
	SetCurrentProcessExplicitAppUserModelID = shell32.MustFindProc("SetCurrentProcessExplicitAppUserModelID")
)

Functions

func HIWORD

func HIWORD(l uint64) uint32

HIWORD

func LOWORD

func LOWORD(l uint64) uint32

LOWORD

func LoadIconFromFile

func LoadIconFromFile(iconPath string) (syscall.Handle, error)

加载本地 .ico

func RegisterAUMID added in v1.1.0

func RegisterAUMID(aumid, displayName, iconURI string) error

注册AUMID

func SetAUMID added in v1.1.0

func SetAUMID(aumid string) error

绑定AUMID 最低受支持的客户端: Windows 7 [仅限桌面应用] 最低受支持的服务器: Windows Server 2008 R2 [仅限桌面应用]

func SetUTF16String

func SetUTF16String(dst interface{}, src string)

字符串处理

func TipFromStr

func TipFromStr(s string) [128]uint16

托盘提示语

func UnregisterAUMID added in v1.1.0

func UnregisterAUMID(aumid string) error

删除已注册的AUMID

Types

type MSG

type MSG struct {
	Hwnd    syscall.Handle
	Message uint32
	WParam  uintptr
	LParam  uintptr
	Time    uint32
	Pt      POINT
}

MSG 结构体

type Menu struct {
	Handle    uintptr
	Callbacks map[uint32]func()
}

func NewMenu

func NewMenu() *Menu
func (m *Menu) AddCheckMenu(id uint32, label string, check bool, callback func())

添加复选菜单项

func (m *Menu) AddItem(id uint32, label string, callback func())

添加菜单项

func (m *Menu) AddSeparator()

分隔符

func (m *Menu) AddSubMenu(label string, subMenu *Menu)

添加子菜单

func (m *Menu) ToggleCheck(id int) bool

检查并切换复选菜单状态,返回新的状态

type NOTIFYICONDATAW

type NOTIFYICONDATAW struct {
	CbSize           uint32
	HWnd             syscall.Handle
	UID              uint32
	UFlags           uint32
	UCallbackMessage uint32
	HIcon            syscall.Handle
	SzTip            [128]uint16
	DwState          uint32
	DwStateMask      uint32
	SzInfo           [256]uint16
	UVersion         uint32
	SzInfoTitle      [64]uint16
	DwInfoFlags      uint32
	GuidItem         syscall.GUID
	HBalloonIcon     syscall.Handle
}

NOTIFYICONDATAW 结构体 UTimeout 和 UVersion 属于联合体,只能使用其中一个 UTimeout 仅在 Windows 2000 和 Windows XP 中有效,故不使用

type POINT

type POINT struct {
	X, Y int32
}

鼠标坐标

type WNDCLASSEX

type WNDCLASSEX struct {
	Size       uint32
	Style      uint32
	WndProc    uintptr
	ClsExtra   int32
	WndExtra   int32
	Instance   syscall.Handle
	Icon       syscall.Handle
	Cursor     syscall.Handle
	Background syscall.Handle
	MenuName   *uint16
	ClassName  *uint16
	IconSm     syscall.Handle
}

WNDCLASSEX 结构体

Jump to

Keyboard shortcuts

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