Created
January 3, 2024 23:17
-
-
Save chabad360/c5d1d10813ab1ac283c6b5a0250cc95a to your computer and use it in GitHub Desktop.
Windigo Implementation of [UpDown Control](https://learn.microsoft.com/en-us/windows/win32/controls/up-down-control-reference)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/rodrigocfd/windigo/ui" | |
"github.com/rodrigocfd/windigo/ui/wm" | |
"github.com/rodrigocfd/windigo/win" | |
"github.com/rodrigocfd/windigo/win/co" | |
) | |
type UpDown interface { | |
ui.AnyControl | |
SetRange(min, max int) | |
SetBuddy(buddy ui.AnyControl) | |
} | |
type upDown struct { | |
hWnd win.HWND | |
parent ui.AnyParent | |
ctrlId int | |
} | |
const ( | |
UDS_WRAP = 0x00000001 | |
UDS_SETBUDDYINT = 0x00000002 | |
UDS_ALIGNRIGHT = 0x00000004 | |
UDS_ALIGNLEFT = 0x00000008 | |
UDS_AUTOBUDDY = 0x00000010 | |
UDS_ARROWKEYS = 0x00000020 | |
UDS_HORZ = 0x00000040 | |
UDS_NOTHOUSANDS = 0x00000080 | |
UDS_HOTTRACK = 0x00000100 | |
UDM_SETRANGE = co.WM_USER + 101 | |
UDM_GETRANGE = co.WM_USER + 102 | |
UDM_SETPOS = co.WM_USER + 103 | |
UDM_GETPOS = co.WM_USER + 104 | |
UDM_SETBUDDY = co.WM_USER + 105 | |
UDM_GETBUDDY = co.WM_USER + 106 | |
UDM_SETACCEL = co.WM_USER + 107 | |
UDM_GETACCEL = co.WM_USER + 108 | |
UDM_SETBASE = co.WM_USER + 109 | |
UDM_GETBASE = co.WM_USER + 110 | |
UDM_SETRANGE32 = co.WM_USER + 111 | |
UDM_GETRANGE32 = co.WM_USER + 112 | |
UDM_SETUNICODEFORMAT = co.CCM_SETUNICODEFORMAT | |
UDM_GETUNICODEFORMAT = co.CCM_GETUNICODEFORMAT | |
UDM_SETPOS32 = co.WM_USER + 113 | |
UDM_GETPOS32 = co.WM_USER + 114 | |
) | |
func NewUpDown(parent ui.AnyParent) UpDown { | |
var icx win.INITCOMMONCONTROLSEX | |
icx.SetDwSize() | |
icx.DwICC = co.ICC_UPDOWN_CLASS | |
win.InitCommonControlsEx(&icx) | |
ud := &upDown{ | |
parent: parent, | |
ctrlId: 80_000, | |
} | |
parent.On().WmCreate(func(p wm.Create) int { | |
ud.hWnd = win.CreateWindowEx(co.WS_EX_LEFT|co.WS_EX_LTRREADING, | |
win.ClassNameStr("msctls_updown32"), | |
win.StrOptNone(), | |
co.WS_CHILDWINDOW|co.WS_VISIBLE|UDS_AUTOBUDDY|UDS_SETBUDDYINT|UDS_ALIGNRIGHT|UDS_ARROWKEYS|UDS_HOTTRACK, | |
0, 0, 0, 0, | |
parent.Hwnd(), win.HMENU(80_000), parent.Hwnd().Hinstance(), 0) | |
return 0 | |
}) | |
return ud | |
} | |
func (me *upDown) Hwnd() win.HWND { | |
return me.hWnd | |
} | |
func (me *upDown) CtrlId() int { | |
return me.ctrlId | |
} | |
func (me *upDown) Parent() ui.AnyParent { | |
return me.parent | |
} | |
func (me *upDown) SetRange(min, max int) { | |
me.hWnd.SendMessage(UDM_SETRANGE, 0, win.MAKELPARAM(uint16(max), uint16(min))) | |
} | |
func (me *upDown) SetBuddy(buddy ui.AnyControl) { | |
me.hWnd.SendMessage(UDM_SETBUDDY, win.WPARAM(buddy.Hwnd()), 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment