| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188 |
- //go:build windows && amd64
- // +build windows,amd64
- package grpa
- import (
- "log"
- "os"
- "path/filepath"
- "runtime"
- "syscall"
- "unicode/utf16"
- "unsafe"
- )
- // properties available in AutoItX.
- const (
- SWHide = 0
- SWMaximize = 3
- SWMinimize = 6
- SWRestore = 9
- SWShow = 5
- SWShowDefault = 10
- SWShowMaximized = 3
- SWShowMinimized = 2
- SWShowminNoActive = 7
- SWShowMa = 8
- SWShowNoActive = 4
- SWShowNormal = 1
- INTDEFAULT = -2147483647
- DefaultMouseButton = "left"
- )
- // HWND -- window handle
- type HWND uintptr
- // RECT -- http://msdn.microsoft.com/en-us/library/windows/desktop/dd162897.aspx
- type RECT struct {
- Left, Top, Right, Bottom int32
- }
- // POINT --
- type POINT struct {
- X, Y int32
- }
- var (
- dll64 *syscall.LazyDLL
- clipGet *syscall.LazyProc
- clipPut *syscall.LazyProc
- controlClick *syscall.LazyProc
- controlClickByHandle *syscall.LazyProc
- controlCommand *syscall.LazyProc
- controlCommandByHandle *syscall.LazyProc
- controlDisable *syscall.LazyProc
- controlDisableByHandle *syscall.LazyProc
- controlEnable *syscall.LazyProc
- controlEnableByHandle *syscall.LazyProc
- controlFocus *syscall.LazyProc
- controlFocusByHandle *syscall.LazyProc
- controlGetHandle *syscall.LazyProc
- controlGetHandleAsText *syscall.LazyProc
- controlGetPos *syscall.LazyProc
- controlGetPosByHandle *syscall.LazyProc
- controlGetText *syscall.LazyProc
- controlGetTextByHandle *syscall.LazyProc
- controlHide *syscall.LazyProc
- controlHideByHandle *syscall.LazyProc
- controlListView *syscall.LazyProc
- controlListViewByHandle *syscall.LazyProc
- controlMove *syscall.LazyProc
- controlMoveByHandle *syscall.LazyProc
- controlSend *syscall.LazyProc
- controlSendByHandle *syscall.LazyProc
- controlSetText *syscall.LazyProc
- controlSetTextByHandle *syscall.LazyProc
- controlShow *syscall.LazyProc
- controlShowByHandle *syscall.LazyProc
- controlTreeView *syscall.LazyProc
- controlTreeViewByHandle *syscall.LazyProc
- isAdmin *syscall.LazyProc
- mouseClick *syscall.LazyProc
- mouseClickDrag *syscall.LazyProc
- mouseDown *syscall.LazyProc
- mouseGetCursor *syscall.LazyProc
- mouseGetPos *syscall.LazyProc
- mouseMove *syscall.LazyProc
- mouseUp *syscall.LazyProc
- mouseWheel *syscall.LazyProc
- opt *syscall.LazyProc
- processClose *syscall.LazyProc
- processExists *syscall.LazyProc
- processSetPriority *syscall.LazyProc
- processWait *syscall.LazyProc
- processWaitClose *syscall.LazyProc
- run *syscall.LazyProc
- runAs *syscall.LazyProc
- runAsWait *syscall.LazyProc
- runWait *syscall.LazyProc
- send *syscall.LazyProc
- winActivate *syscall.LazyProc
- winActive *syscall.LazyProc
- winCloseByHandle *syscall.LazyProc
- winGetHandle *syscall.LazyProc
- winGetText *syscall.LazyProc
- winGetTitle *syscall.LazyProc
- winMinimizeAll *syscall.LazyProc
- winMinimizeAllundo *syscall.LazyProc
- winMove *syscall.LazyProc
- winGetState *syscall.LazyProc
- winSetState *syscall.LazyProc
- winWait *syscall.LazyProc
- )
- func init() {
- log.SetFlags(log.LstdFlags | log.Llongfile)
- // dll64, err = syscall.LoadDLL("D:\\Program Files (x86)\\AutoIt3\\AutoItX\\AutoItX3_x64.dll")
- // defer dll64.Release()
- currentPath, _ := os.Getwd()
- dll64Path := filepath.Join(currentPath, "AutoItX3_x64.dll")
- if runtime.GOARCH != "amd64" {
- dll64Path = filepath.Join(currentPath, "AutoItX3.dll")
- }
- dll64 = syscall.NewLazyDLL(dll64Path)
- // dll64 = syscall.NewLazyDLL(os.Getenv("GOPATH") + "\\src\\github.com\\shadow1163\\goautoit\\lib\\AutoItX3_x64.dll")
- clipGet = dll64.NewProc("AU3_ClipGet")
- clipPut = dll64.NewProc("AU3_ClipPut")
- controlClick = dll64.NewProc("AU3_ControlClick")
- controlClickByHandle = dll64.NewProc("AU3_ControlClickByHandle")
- controlCommand = dll64.NewProc("AU3_ControlCommand")
- controlCommandByHandle = dll64.NewProc("AU3_ControlCommandByHandle")
- controlGetHandle = dll64.NewProc("AU3_ControlGetHandle")
- controlGetHandleAsText = dll64.NewProc("AU3_ControlGetHandleAsText")
- controlGetPos = dll64.NewProc("AU3_ControlGetPos")
- controlGetPosByHandle = dll64.NewProc("AU3_ControlGetPosByHandle")
- controlGetText = dll64.NewProc("AU3_ControlGetText")
- controlGetTextByHandle = dll64.NewProc("AU3_ControlGetTextByHandle")
- controlHide = dll64.NewProc("AU3_ControlHide")
- controlHideByHandle = dll64.NewProc("AU3_ControlHideByHandle")
- controlListView = dll64.NewProc("AU3_ControlListView")
- controlListViewByHandle = dll64.NewProc("AU3_ControlListViewByHandle")
- controlMove = dll64.NewProc("AU3_ControlMove")
- controlMoveByHandle = dll64.NewProc("AU3_ControlMoveByHandle")
- controlSend = dll64.NewProc("AU3_ControlSend")
- controlSendByHandle = dll64.NewProc("AU3_ControlSendByHandle")
- controlSetText = dll64.NewProc("AU3_ControlSetText")
- controlSetTextByHandle = dll64.NewProc("AU3_ControlSetTextByHandle")
- controlShow = dll64.NewProc("AU3_ControlShow")
- controlShowByHandle = dll64.NewProc("AU3_ControlShowByHandle")
- controlTreeView = dll64.NewProc("AU3_ControlTreeView")
- controlTreeViewByHandle = dll64.NewProc("AU3_ControlTreeViewByHandle")
- isAdmin = dll64.NewProc("AU3_IsAdmin")
- mouseClick = dll64.NewProc("AU3_MouseClick")
- mouseClickDrag = dll64.NewProc("AU3_MouseClickDrag")
- mouseDown = dll64.NewProc("AU3_MouseDown")
- mouseGetCursor = dll64.NewProc("AU3_MouseGetCursor")
- mouseGetPos = dll64.NewProc("AU3_MouseGetPos")
- mouseMove = dll64.NewProc("AU3_MouseMove")
- mouseUp = dll64.NewProc("AU3_MouseUp")
- mouseWheel = dll64.NewProc("AU3_MouseWheel")
- opt = dll64.NewProc("AU3_Opt")
- processClose = dll64.NewProc("AU3_ProcessClose")
- processExists = dll64.NewProc("AU3_ProcessExists")
- processSetPriority = dll64.NewProc("AU3_ProcessSetPriority")
- processWait = dll64.NewProc("AU3_ProcessWait")
- processWaitClose = dll64.NewProc("AU3_ProcessWaitClose")
- run = dll64.NewProc("AU3_Run")
- runAs = dll64.NewProc("AU3_RunAs")
- runAsWait = dll64.NewProc("AU3_RunAsWait")
- runWait = dll64.NewProc("AU3_RunWait")
- send = dll64.NewProc("AU3_Send")
- winActivate = dll64.NewProc("AU3_WinActivate")
- winActive = dll64.NewProc("AU3_WinActive")
- winCloseByHandle = dll64.NewProc("AU3_WinCloseByHandle")
- winGetHandle = dll64.NewProc("AU3_WinGetHandle")
- winGetText = dll64.NewProc("AU3_WinGetText")
- winGetTitle = dll64.NewProc("AU3_WinGetTitle")
- winMinimizeAll = dll64.NewProc("AU3_WinMinimizeAll")
- winMinimizeAllundo = dll64.NewProc("AU3_WinMinimizeAllUndo")
- winMove = dll64.NewProc("AU3_WinMove")
- winGetState = dll64.NewProc("AU3_WinGetState")
- winSetState = dll64.NewProc("AU3_WinSetState")
- winWait = dll64.NewProc("AU3_WinWait")
- }
- // WinMinimizeAll -- all windows should be minimize
- func WinMinimizeAll() {
- winMinimizeAll.Call()
- }
- // WinMinimizeAllUndo -- undo minimize all windows
- func WinMinimizeAllUndo() {
- winMinimizeAllundo.Call()
- }
- // WinGetTitle -- get windows title
- func WinGetTitle(szTitle, szText string, bufSize int) string {
- // szTitle := "[active]"
- // szText := ""
- // bufSize := 256
- buff := make([]uint16, int(bufSize))
- ret, _, lastErr := winGetTitle.Call(strPtr(szTitle), strPtr(szText), uintptr(unsafe.Pointer(&buff[0])), intPtr(bufSize))
- log.Println(ret)
- log.Println(lastErr)
- return (goWString(buff))
- }
- // WinGetText -- get text in window
- func WinGetText(szTitle, szText string, bufSize int) string {
- buff := make([]uint16, int(bufSize))
- winGetText.Call(strPtr(szTitle), strPtr(szText), uintptr(unsafe.Pointer(&buff[0])), intPtr(bufSize))
- return (goWString(buff))
- }
- // Run -- Run a windows program
- // flag 3(max) 6(min) 9(normal) 0(hide)
- func Run(szProgram string, args ...interface{}) int {
- var szDir string
- var flag int
- var ok bool
- if len(args) == 0 {
- szDir = ""
- flag = SWShowNormal
- } else if len(args) == 1 {
- if szDir, ok = args[0].(string); !ok {
- panic("szDir must be a string")
- }
- flag = SWShowNormal
- } else if len(args) == 2 {
- if szDir, ok = args[0].(string); !ok {
- panic("szDir must be a string")
- }
- if flag, ok = args[1].(int); !ok {
- panic("flag must be a int")
- }
- } else {
- panic("Too more parameter")
- }
- pid, _, lastErr := run.Call(strPtr(szProgram), strPtr(szDir), intPtr(flag))
- // log.Println(pid)
- if int(pid) == 0 {
- log.Println(lastErr)
- }
- return int(pid)
- }
- // Send -- Send simulates input on the keyboard
- // flag: 0: normal, 1: raw
- func Send(key string, args ...interface{}) {
- var nMode int
- var ok bool
- if len(args) == 0 {
- nMode = 0
- } else if len(args) == 1 {
- if nMode, ok = args[0].(int); !ok {
- panic("nMode must be a int")
- }
- } else {
- panic("Too more parameter")
- }
- send.Call(strPtr(key), intPtr(nMode))
- }
- // WinWait -- wait window to active
- func WinWait(szTitle string, args ...interface{}) int {
- var szText string
- var nTimeout int
- var ok bool
- if len(args) == 0 {
- szText = ""
- nTimeout = 0
- } else if len(args) == 1 {
- if szText, ok = args[0].(string); !ok {
- panic("szText must be a string")
- }
- nTimeout = 0
- } else if len(args) == 2 {
- if szText, ok = args[0].(string); !ok {
- panic("szText must be a string")
- }
- if nTimeout, ok = args[1].(int); !ok {
- panic("nTimeout must be a int")
- }
- } else {
- panic("Too more parameter")
- }
- handle, _, lastErr := winWait.Call(strPtr(szTitle), strPtr(szText), intPtr(nTimeout))
- if int(handle) == 0 {
- log.Print("timeout or failure!!!")
- log.Println(lastErr)
- }
- return int(handle)
- }
- // MouseClick -- Perform a mouse click operation.
- func MouseClick(button string, args ...interface{}) int {
- var x, y, nClicks, nSpeed int
- var ok bool
- if len(args) == 0 {
- x = INTDEFAULT
- y = INTDEFAULT
- nClicks = 1
- nSpeed = 10
- } else if len(args) == 2 {
- if x, ok = args[0].(int); !ok {
- panic("x must be a int")
- }
- if y, ok = args[1].(int); !ok {
- panic("y must be a int")
- }
- nClicks = 1
- nSpeed = 10
- } else if len(args) == 3 {
- if x, ok = args[0].(int); !ok {
- panic("x must be a int")
- }
- if y, ok = args[1].(int); !ok {
- panic("y must be a int")
- }
- if nClicks, ok = args[2].(int); !ok {
- panic("nClicks must be a int")
- }
- nSpeed = 10
- } else if len(args) == 4 {
- if x, ok = args[0].(int); !ok {
- panic("x must be a int")
- }
- if y, ok = args[1].(int); !ok {
- panic("y must be a int")
- }
- if nClicks, ok = args[2].(int); !ok {
- panic("nClicks must be a int")
- }
- if nSpeed, ok = args[3].(int); !ok {
- panic("nSpeed must be a int")
- }
- } else {
- panic("Error parameters")
- }
- ret, _, lastErr := mouseClick.Call(strPtr(button), intPtr(x), intPtr(y), intPtr(nClicks), intPtr(nSpeed))
- if int(ret) != 1 {
- log.Print("failure!!!")
- log.Println(lastErr)
- }
- return int(ret)
- }
- // ControlClick -- Sends a mouse click command to a given control.
- func ControlClick(title, text, control string, args ...interface{}) int {
- var button string
- var x, y, nClicks int
- var ok bool
- if len(args) == 0 {
- button = DefaultMouseButton
- nClicks = 1
- x = INTDEFAULT
- y = INTDEFAULT
- } else if len(args) == 1 {
- if button, ok = args[0].(string); !ok {
- panic("button must be a string")
- }
- nClicks = 1
- x = INTDEFAULT
- y = INTDEFAULT
- } else if len(args) == 2 {
- if button, ok = args[0].(string); !ok {
- panic("button must be a string")
- }
- if nClicks, ok = args[1].(int); !ok {
- panic("nClicks must be a int")
- }
- x = INTDEFAULT
- y = INTDEFAULT
- } else if len(args) == 4 {
- if button, ok = args[0].(string); !ok {
- panic("button must be a string")
- }
- if nClicks, ok = args[1].(int); !ok {
- panic("nClicks must be a int")
- }
- if x, ok = args[2].(int); !ok {
- panic("x must be a int")
- }
- if y, ok = args[3].(int); !ok {
- panic("y must be a int")
- }
- } else {
- panic("Error parameters")
- }
- ret, _, lastErr := controlClick.Call(strPtr(title), strPtr(text), strPtr(control), strPtr(button), intPtr(nClicks), intPtr(x), intPtr(y))
- if int(ret) == 0 {
- log.Print("failure!!!")
- log.Println(lastErr)
- }
- return int(ret)
- }
- // ControlClickByHandle -- Sends a mouse click command to a given control.
- func ControlClickByHandle(handle, control HWND, args ...interface{}) int {
- var button string
- var x, y, nClicks int
- var ok bool
- if len(args) == 0 {
- button = DefaultMouseButton
- nClicks = 1
- x = INTDEFAULT
- y = INTDEFAULT
- } else if len(args) == 1 {
- if button, ok = args[0].(string); !ok {
- panic("button must be a string")
- }
- nClicks = 1
- x = INTDEFAULT
- y = INTDEFAULT
- } else if len(args) == 2 {
- if button, ok = args[0].(string); !ok {
- panic("button must be a string")
- }
- if nClicks, ok = args[1].(int); !ok {
- panic("nClicks must be a int")
- }
- x = INTDEFAULT
- y = INTDEFAULT
- } else if len(args) == 4 {
- if button, ok = args[0].(string); !ok {
- panic("button must be a string")
- }
- if nClicks, ok = args[1].(int); !ok {
- panic("nClicks must be a int")
- }
- if x, ok = args[2].(int); !ok {
- panic("x must be a int")
- }
- if y, ok = args[3].(int); !ok {
- panic("y must be a int")
- }
- } else {
- panic("Error parameters")
- }
- ret, _, lastErr := controlClickByHandle.Call(uintptr(handle), uintptr(control), strPtr(button), intPtr(nClicks), intPtr(x), intPtr(y))
- if int(ret) == 0 {
- log.Print("failure!!!")
- log.Println(lastErr)
- }
- return int(ret)
- }
- // ClipGet -- get a string from clip
- func ClipGet(args ...interface{}) string {
- var nBufSize int
- var ok bool
- if len(args) == 0 {
- nBufSize = 256
- } else if len(args) == 1 {
- if nBufSize, ok = args[0].(int); !ok {
- panic("nBufSize must be a int")
- }
- } else {
- panic("Error parameters")
- }
- clip := make([]uint16, int(nBufSize))
- clipGet.Call(uintptr(unsafe.Pointer(&clip[0])), intPtr(nBufSize))
- return (goWString(clip))
- }
- // ClipPut -- put a string to clip
- func ClipPut(szClip string) int {
- ret, _, lastErr := clipPut.Call(strPtr(szClip))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return int(ret)
- }
- // WinActivate ( "title" [, "text"]) int
- func WinActivate(title string, args ...interface{}) int {
- text := ""
- var ok bool
- argsLen := len(args)
- if argsLen > 1 {
- panic("argument count > 2")
- }
- if argsLen == 1 {
- if text, ok = args[0].(string); !ok {
- panic("text must be a string")
- }
- }
- ret, _, lastErr := winActivate.Call(strPtr(title), strPtr(text))
- if int(ret) == 0 {
- log.Print("failure!!!")
- log.Println(lastErr)
- }
- return int(ret)
- }
- // WinActive ( "title" [, "text"]) int
- func WinActive(title string, args ...interface{}) int {
- text := ""
- var ok bool
- argsLen := len(args)
- if argsLen > 1 {
- panic("argument count > 2")
- }
- if argsLen == 1 {
- if text, ok = args[0].(string); !ok {
- panic("text must be a string")
- }
- }
- ret, _, lastErr := winActive.Call(strPtr(title), strPtr(text))
- if int(ret) == 0 {
- log.Print("failure!!!")
- log.Println(lastErr)
- }
- return int(ret)
- }
- // WinGetHandle -- get window handle
- func WinGetHandle(title string, args ...interface{}) HWND {
- var text string
- var ok bool
- if len(args) == 0 {
- text = ""
- } else if len(args) == 1 {
- if text, ok = args[0].(string); !ok {
- panic("text must be a string")
- }
- } else {
- panic("Error parameters")
- }
- ret, _, lastErr := winGetHandle.Call(strPtr(title), strPtr(text))
- if int(ret) == 0 {
- log.Print("failure!!!")
- log.Println(lastErr)
- }
- return HWND(ret)
- }
- // WinMove ( "title", "text", x, y [, width [, height [, speed]]] ) int
- func WinMove(title, text string, x, y int, args ...interface{}) int {
- width := INTDEFAULT
- height := INTDEFAULT
- speed := 10
- var ok bool
- argsLen := len(args)
- if argsLen > 0 {
- if width, ok = args[0].(int); !ok {
- panic("width must be an integer")
- }
- if argsLen > 1 {
- if height, ok = args[1].(int); !ok {
- panic("height must be an integer")
- }
- if argsLen > 2 {
- if speed, ok = args[2].(int); !ok {
- panic("speed must be an integer")
- }
- if speed < 1 || speed > 100 {
- panic("speed must in range 1~100(slowest)")
- }
- if argsLen > 3 {
- panic("too many arguments")
- }
- }
- }
- }
- ret, _, lastErr := winMove.Call(strPtr(title), strPtr(text), intPtr(x), intPtr(y), intPtr(width),
- intPtr(height), intPtr(speed))
- if int(ret) == 0 {
- log.Print("failure!!!")
- log.Println(lastErr)
- }
- return int(ret)
- }
- // WinCloseByHandle --
- func WinCloseByHandle(hwnd HWND) int {
- ret, _, lastErr := winCloseByHandle.Call(uintptr(hwnd))
- if int(ret) == 0 {
- log.Print("failure!!!")
- log.Println(lastErr)
- }
- return int(ret)
- }
- // WinGetState ( "title" [, "text"] ) int
- func WinGetState(title string, args ...interface{}) int {
- text := ""
- var ok bool
- argsLen := len(args)
- if argsLen > 1 {
- panic("argument count > 2")
- }
- if argsLen == 1 {
- if text, ok = args[0].(string); !ok {
- panic("text must be a string")
- }
- }
- ret, _, lastErr := winGetState.Call(strPtr(title), strPtr(text))
- if int(ret) == 0 {
- log.Println("winGetState failure!!!", lastErr)
- }
- return int(ret)
- }
- // WinSetState ( "title", "text", flag) int
- func WinSetState(title, text string, flag int) int {
- ret, _, lastErr := winSetState.Call(strPtr(title), strPtr(text), intPtr(flag))
- if int(ret) == 0 {
- log.Print("WinSetState failure!!!")
- log.Println(lastErr)
- }
- return int(ret)
- }
- // ControlSend -- Sends a string of characters to a control.
- func ControlSend(title, text, control, sendText string, args ...interface{}) int {
- var nMode int
- var ok bool
- if len(args) == 0 {
- nMode = 0
- } else if len(args) == 1 {
- if nMode, ok = args[0].(int); !ok {
- panic("nMode must be a int")
- }
- } else {
- panic("Too more parameter")
- }
- ret, _, lastErr := controlSend.Call(strPtr(title), strPtr(text), strPtr(control), strPtr(sendText), intPtr(nMode))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return int(ret)
- }
- // ControlSendByHandle -- Sends a string of characters to a control.
- func ControlSendByHandle(handle, control HWND, sendText string, args ...interface{}) int {
- var nMode int
- var ok bool
- if len(args) == 0 {
- nMode = 0
- } else if len(args) == 1 {
- if nMode, ok = args[0].(int); !ok {
- panic("nMode must be a int")
- }
- } else {
- panic("Too more parameter")
- }
- ret, _, lastErr := controlSendByHandle.Call(uintptr(handle), uintptr(control), strPtr(sendText), intPtr(nMode))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return int(ret)
- }
- // ControlSetText -- Sets text of a control.
- func ControlSetText(title, text, control, newText string) int {
- ret, _, lastErr := controlSetText.Call(strPtr(title), strPtr(text), strPtr(control), strPtr(newText))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return int(ret)
- }
- // ControlSetTextByHandle -- Sets text of a control.
- func ControlSetTextByHandle(handle, control HWND, newText string) int {
- ret, _, lastErr := controlSetTextByHandle.Call(uintptr(handle), uintptr(control), strPtr(newText))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return int(ret)
- }
- // ControlCommand -- Sends a command to a control.
- func ControlCommand(title, text, control, command string, args ...interface{}) string {
- var Extra string
- var bufSize int
- var ok bool
- if len(args) == 0 {
- Extra = ""
- bufSize = 256
- } else if len(args) == 1 {
- if Extra, ok = args[0].(string); !ok {
- panic("Extra must be a string")
- }
- bufSize = 256
- } else if len(args) == 2 {
- if Extra, ok = args[0].(string); !ok {
- panic("Extra must be a string")
- }
- if bufSize, ok = args[1].(int); !ok {
- panic("bufferSize must be a int")
- }
- } else {
- panic("Error parameters")
- }
- buff := make([]uint16, int(bufSize))
- ret, _, lastErr := controlCommand.Call(strPtr(title), strPtr(text), strPtr(control), strPtr(command), strPtr(Extra), uintptr(unsafe.Pointer(&buff[0])), intPtr(bufSize))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return (goWString(buff))
- }
- // ControlCommandByHandle -- Sends a command to a control.
- func ControlCommandByHandle(handle, control HWND, command string, args ...interface{}) string {
- var Extra string
- var bufSize int
- var ok bool
- if len(args) == 0 {
- Extra = ""
- bufSize = 256
- } else if len(args) == 1 {
- if Extra, ok = args[0].(string); !ok {
- panic("Extra must be a string")
- }
- bufSize = 256
- } else if len(args) == 2 {
- if Extra, ok = args[0].(string); !ok {
- panic("Extra must be a string")
- }
- if bufSize, ok = args[1].(int); !ok {
- panic("bufferSize must be a int")
- }
- } else {
- panic("Error parameters")
- }
- buff := make([]uint16, int(bufSize))
- ret, _, lastErr := controlCommandByHandle.Call(uintptr(handle), uintptr(control), strPtr(command), strPtr(Extra), uintptr(unsafe.Pointer(&buff[0])), intPtr(bufSize))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return (goWString(buff))
- }
- // ControlListView --Sends a command to a ListView32 control.
- func ControlListView(title, text, control, command string, args ...interface{}) string {
- var Extra1, Extra2 string
- var bufSize int
- var ok bool
- if len(args) == 0 {
- Extra1 = ""
- Extra2 = ""
- bufSize = 256
- } else if len(args) == 1 {
- if Extra1, ok = args[0].(string); !ok {
- panic("Extra1 must be a string")
- }
- Extra2 = ""
- bufSize = 256
- } else if len(args) == 2 {
- if Extra1, ok = args[0].(string); !ok {
- panic("Extra1 must be a string")
- }
- if Extra2, ok = args[1].(string); !ok {
- panic("Extra2 must be a string")
- }
- bufSize = 256
- } else if len(args) == 3 {
- if Extra1, ok = args[0].(string); !ok {
- panic("Extra1 must be a string")
- }
- if Extra2, ok = args[1].(string); !ok {
- panic("Extra2 must be a string")
- }
- if bufSize, ok = args[2].(int); !ok {
- panic("bufSize must be a int")
- }
- } else {
- panic("Error parameters")
- }
- buff := make([]uint16, int(bufSize))
- ret, _, lastErr := controlListView.Call(strPtr(title), strPtr(text), strPtr(control), strPtr(command), strPtr(Extra1), strPtr(Extra2), uintptr(unsafe.Pointer(&buff[0])), intPtr(bufSize))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return (goWString(buff))
- }
- // ControlListViewByHandle --Sends a command to a ListView32 control.
- func ControlListViewByHandle(handle, control HWND, command string, args ...interface{}) string {
- var Extra1, Extra2 string
- var bufSize int
- var ok bool
- if len(args) == 0 {
- Extra1 = ""
- Extra2 = ""
- bufSize = 256
- } else if len(args) == 1 {
- if Extra1, ok = args[0].(string); !ok {
- panic("Extra1 must be a string")
- }
- Extra2 = ""
- bufSize = 256
- } else if len(args) == 2 {
- if Extra1, ok = args[0].(string); !ok {
- panic("Extra1 must be a string")
- }
- if Extra2, ok = args[1].(string); !ok {
- panic("Extra2 must be a string")
- }
- bufSize = 256
- } else if len(args) == 3 {
- if Extra1, ok = args[0].(string); !ok {
- panic("Extra1 must be a string")
- }
- if Extra2, ok = args[1].(string); !ok {
- panic("Extra2 must be a string")
- }
- if bufSize, ok = args[2].(int); !ok {
- panic("bufSize must be a int")
- }
- } else {
- panic("Error parameters")
- }
- buff := make([]uint16, int(bufSize))
- ret, _, lastErr := controlListViewByHandle.Call(uintptr(handle), uintptr(control), strPtr(command), strPtr(Extra1), strPtr(Extra2), uintptr(unsafe.Pointer(&buff[0])), intPtr(bufSize))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return (goWString(buff))
- }
- // ControlDisable -- Disables or "grays-out" a control.
- func ControlDisable(title, text, control string) int {
- ret, _, lastErr := controlDisable.Call(strPtr(title), strPtr(text), strPtr(control))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return int(ret)
- }
- // ControlDisableByHandle -- Disables or "grays-out" a control.
- func ControlDisableByHandle(handle, control HWND) int {
- ret, _, lastErr := controlDisableByHandle.Call(uintptr(handle), uintptr(control))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return int(ret)
- }
- // ControlEnable -- Enables a "grayed-out" control.
- func ControlEnable(title, text, control string) int {
- ret, _, lastErr := controlEnable.Call(strPtr(title), strPtr(text), strPtr(control))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return int(ret)
- }
- // ControlEnableByHandle -- Enables a "grayed-out" control.
- func ControlEnableByHandle(handle, control HWND) int {
- ret, _, lastErr := controlEnableByHandle.Call(uintptr(handle), uintptr(control))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return int(ret)
- }
- // ControlFocus -- Sets input focus to a given control on a window.
- func ControlFocus(title, text, control string) int {
- ret, _, lastErr := controlFocus.Call(strPtr(title), strPtr(text), strPtr(control))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return int(ret)
- }
- // ControlFocusByHandle -- Sets input focus to a given control on a window.
- func ControlFocusByHandle(handle, control HWND) int {
- ret, _, lastErr := controlFocusByHandle.Call(uintptr(handle), uintptr(control))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return int(ret)
- }
- // ControlGetHandle -- Retrieves the internal handle of a control.
- func ControlGetHandle(handle HWND, control string) HWND {
- ret, _, lastErr := controlGetHandle.Call(uintptr(handle), strPtr(control))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return HWND(ret)
- }
- // ControlGetHandleAsText -- Retrieves the internal handle of a control.
- func ControlGetHandleAsText(title, text, control string, args ...interface{}) string {
- var bufSize int
- var ok bool
- if len(args) == 0 {
- bufSize = 256
- } else if len(args) == 1 {
- if bufSize, ok = args[0].(int); !ok {
- panic("bufSize must be a int")
- }
- } else {
- panic("Error parameters")
- }
- buff := make([]uint16, int(bufSize))
- ret, _, lastErr := controlGetHandleAsText.Call(strPtr(title), strPtr(text), strPtr(control), uintptr(unsafe.Pointer(&buff[0])), intPtr(bufSize))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return (goWString(buff))
- }
- // ControlGetPos -- Retrieves the position and size of a control relative to its window.
- func ControlGetPos(title, text, control string) RECT {
- lprect := RECT{}
- ret, _, lastErr := controlGetPos.Call(strPtr(title), strPtr(text), strPtr(control), uintptr(unsafe.Pointer(&lprect)))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return lprect
- }
- // ControlGetPosByHandle -- Retrieves the position and size of a control relative to its window.
- func ControlGetPosByHandle(title, text, control string) RECT {
- lprect := RECT{}
- ret, _, lastErr := controlGetPosByHandle.Call(strPtr(title), strPtr(text), strPtr(control), uintptr(unsafe.Pointer(&lprect)))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return lprect
- }
- // ControlGetText -- Retrieves text from a control.
- func ControlGetText(title, text, control string, args ...interface{}) string {
- var bufSize int
- var ok bool
- if len(args) == 0 {
- bufSize = 256
- } else if len(args) == 1 {
- if bufSize, ok = args[0].(int); !ok {
- panic("bufSize must be a int")
- }
- } else {
- panic("Error parameters")
- }
- buff := make([]uint16, int(bufSize))
- ret, _, lastErr := controlGetText.Call(strPtr(title), strPtr(text), strPtr(control), uintptr(unsafe.Pointer(&buff[0])), intPtr(bufSize))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return (goWString(buff))
- }
- // ControlGetTextByHandle -- Retrieves text from a control.
- func ControlGetTextByHandle(handle, control HWND, args ...interface{}) string {
- var bufSize int
- var ok bool
- if len(args) == 0 {
- bufSize = 256
- } else if len(args) == 1 {
- if bufSize, ok = args[0].(int); !ok {
- panic("bufSize must be a int")
- }
- } else {
- panic("Error parameters")
- }
- buff := make([]uint16, int(bufSize))
- ret, _, lastErr := controlGetTextByHandle.Call(uintptr(handle), uintptr(control), uintptr(unsafe.Pointer(&buff[0])), intPtr(bufSize))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return (goWString(buff))
- }
- // ControlHide -- Hides a control.
- func ControlHide(title, text, control string) int {
- ret, _, lastErr := controlHide.Call(strPtr(title), strPtr(text), strPtr(control))
- if int(ret) == 1 {
- log.Println(lastErr)
- }
- return int(ret)
- }
- // ControlHideByHandle -- Hides a control.
- func ControlHideByHandle(title, text, control string) int {
- ret, _, lastErr := controlHideByHandle.Call(strPtr(title), strPtr(text), strPtr(control))
- if int(ret) == 1 {
- log.Println(lastErr)
- }
- return int(ret)
- }
- // ControlMove -- Hides a control.
- func ControlMove(title, text, control string, x, y int, args ...interface{}) int {
- var width, height int
- var ok bool
- if len(args) == 0 {
- width = -1
- height = -1
- } else if len(args) == 2 {
- if width, ok = args[0].(int); !ok {
- panic("width must be a int")
- }
- if height, ok = args[1].(int); !ok {
- panic("height must be a int")
- }
- } else {
- panic("Error parameters")
- }
- ret, _, lastErr := controlMove.Call(strPtr(title), strPtr(text), strPtr(control), intPtr(x), intPtr(y), intPtr(width), intPtr(height))
- if int(ret) == 1 {
- log.Println(lastErr)
- }
- return int(ret)
- }
- // ControlMoveByHandle -- Hides a control.
- func ControlMoveByHandle(handle, control HWND, x, y int, args ...interface{}) int {
- var width, height int
- var ok bool
- if len(args) == 0 {
- width = -1
- height = -1
- } else if len(args) == 2 {
- if width, ok = args[0].(int); !ok {
- panic("width must be a int")
- }
- if height, ok = args[1].(int); !ok {
- panic("height must be a int")
- }
- } else {
- panic("Error parameters")
- }
- ret, _, lastErr := controlMoveByHandle.Call(uintptr(handle), uintptr(control), intPtr(x), intPtr(y), intPtr(width), intPtr(height))
- if int(ret) == 1 {
- log.Println(lastErr)
- }
- return int(ret)
- }
- // ControlShow -- Shows a control that was hidden.
- func ControlShow(title, text, control string) int {
- ret, _, lastErr := controlShow.Call(strPtr(title), strPtr(text), strPtr(control))
- if int(ret) == 1 {
- log.Println(lastErr)
- }
- return int(ret)
- }
- // ControlShowByHandle -- Shows a control that was hidden.
- func ControlShowByHandle(handle, control HWND) int {
- ret, _, lastErr := controlShowByHandle.Call(uintptr(handle), uintptr(control))
- if int(ret) == 1 {
- log.Println(lastErr)
- }
- return int(ret)
- }
- // ControlTreeView -- Sends a command to a TreeView32 control.
- func ControlTreeView(title, text, control, command string, args ...interface{}) string {
- var Extra1, Extra2 string
- var bufSize int
- var ok bool
- if len(args) == 0 {
- Extra1 = ""
- Extra2 = ""
- bufSize = 256
- } else if len(args) == 1 {
- if Extra1, ok = args[0].(string); !ok {
- panic("Extra1 must be a string")
- }
- Extra2 = ""
- bufSize = 256
- } else if len(args) == 2 {
- if Extra1, ok = args[0].(string); !ok {
- panic("Extra1 must be a string")
- }
- if Extra2, ok = args[1].(string); !ok {
- panic("Extra2 must be a string")
- }
- bufSize = 256
- } else if len(args) == 3 {
- if Extra1, ok = args[0].(string); !ok {
- panic("Extra1 must be a string")
- }
- if Extra2, ok = args[1].(string); !ok {
- panic("Extra2 must be a string")
- }
- if bufSize, ok = args[2].(int); !ok {
- panic("bufSize must be a int")
- }
- } else {
- panic("Error parameters")
- }
- buff := make([]uint16, int(bufSize))
- ret, _, lastErr := controlTreeView.Call(strPtr(title), strPtr(text), strPtr(control), strPtr(command), strPtr(Extra1), strPtr(Extra2), uintptr(unsafe.Pointer(&buff[0])), intPtr(bufSize))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return (goWString(buff))
- }
- // ControlTreeViewByHandle -- Sends a command to a TreeView32 control.
- func ControlTreeViewByHandle(handle, control HWND, command string, args ...interface{}) string {
- var Extra1, Extra2 string
- var bufSize int
- var ok bool
- if len(args) == 0 {
- Extra1 = ""
- Extra2 = ""
- bufSize = 256
- } else if len(args) == 1 {
- if Extra1, ok = args[0].(string); !ok {
- panic("Extra1 must be a string")
- }
- Extra2 = ""
- bufSize = 256
- } else if len(args) == 2 {
- if Extra1, ok = args[0].(string); !ok {
- panic("Extra1 must be a string")
- }
- if Extra2, ok = args[1].(string); !ok {
- panic("Extra2 must be a string")
- }
- bufSize = 256
- } else if len(args) == 3 {
- if Extra1, ok = args[0].(string); !ok {
- panic("Extra1 must be a string")
- }
- if Extra2, ok = args[1].(string); !ok {
- panic("Extra2 must be a string")
- }
- if bufSize, ok = args[2].(int); !ok {
- panic("bufSize must be a int")
- }
- } else {
- panic("Error parameters")
- }
- buff := make([]uint16, int(bufSize))
- ret, _, lastErr := controlTreeView.Call(uintptr(handle), uintptr(control), strPtr(command), strPtr(Extra1), strPtr(Extra2), uintptr(unsafe.Pointer(&buff[0])), intPtr(bufSize))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return (goWString(buff))
- }
- // Opt -- set option
- func Opt(option, value string) int {
- ret, _, lastErr := opt.Call(strPtr(option), strPtr(value))
- if int(ret) == 0 {
- log.Println(lastErr)
- }
- return int(ret)
- }
- func findTermChr(buff []uint16) int {
- for i, char := range buff {
- if char == 0x0 {
- return i
- }
- }
- panic("not supposed to happen")
- }
- func intPtr(n int) uintptr {
- return uintptr(n)
- }
- func strPtr(s string) uintptr {
- return uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(s)))
- }
- // GoWString -- Convert a uint16 arrry C string to a Go String
- func goWString(s []uint16) string {
- pos := findTermChr(s)
- // log.Println(string(utf16.Decode(s[0:pos])))
- return (string(utf16.Decode(s[0:pos])))
- }
|