github.com/ckxng/wakeup@v0.0.0-20190105202853-90356a5f5a15/src/wingui/gui.go (about) 1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build windows 6 7 package wingui 8 9 import ( 10 "fmt" 11 "os" 12 "syscall" 13 "unsafe" 14 ) 15 16 // some help functions 17 18 func abortf(format string, a ...interface{}) { 19 fmt.Fprintf(os.Stdout, format, a...) 20 os.Exit(1) 21 } 22 23 func AbortErrNo(funcname string, err error) { 24 errno, _ := err.(syscall.Errno) 25 abortf("%s failed: %d %s\n", funcname, uint32(errno), err) 26 } 27 28 // global vars 29 30 var ( 31 mh syscall.Handle 32 bh syscall.Handle 33 ) 34 35 func CreateWindow(title string, wndproc uintptr) (hwnd syscall.Handle) { 36 var e error 37 38 // GetModuleHandle 39 mh, e = GetModuleHandle(nil) 40 if e != nil { 41 AbortErrNo("GetModuleHandle", e) 42 } 43 44 // Get icon we're going to use. 45 myicon, e := LoadIcon(0, IDI_APPLICATION) 46 if e != nil { 47 AbortErrNo("LoadIcon", e) 48 } 49 50 // Get cursor we're going to use. 51 mycursor, e := LoadCursor(0, IDC_ARROW) 52 if e != nil { 53 AbortErrNo("LoadCursor", e) 54 } 55 56 // RegisterClassEx 57 wcname := syscall.StringToUTF16Ptr("myWindowClass") 58 var wc Wndclassex 59 wc.Size = uint32(unsafe.Sizeof(wc)) 60 wc.WndProc = wndproc 61 wc.Instance = mh 62 wc.Icon = myicon 63 wc.Cursor = mycursor 64 wc.Background = COLOR_BTNFACE + 1 65 wc.MenuName = nil 66 wc.ClassName = wcname 67 wc.IconSm = myicon 68 if _, e := RegisterClassEx(&wc); e != nil { 69 AbortErrNo("RegisterClassEx", e) 70 } 71 72 // CreateWindowEx 73 wh, e := CreateWindowEx( 74 0, 75 wcname, 76 syscall.StringToUTF16Ptr(title), 77 WS_OVERLAPPEDWINDOW, 78 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 79 0, 0, mh, 0) 80 if e != nil { 81 AbortErrNo("CreateWindowEx", e) 82 } 83 //fmt.Printf("main window handle is %x\n", wh) 84 85 // ShowWindow 86 ShowWindow(wh, SW_SHOWDEFAULT) 87 88 // UpdateWindow 89 if e := UpdateWindow(wh); e != nil { 90 AbortErrNo("UpdateWindow", e) 91 } 92 93 hwnd = wh 94 95 return 96 97 /* 98 // Process all windows messages until WM_QUIT. 99 var m Msg 100 for { 101 r, e := GetMessage(&m, 0, 0, 0) 102 if e != nil { 103 AbortErrNo("GetMessage", e) 104 } 105 if r == 0 { 106 // WM_QUIT received -> get out 107 break 108 } 109 TranslateMessage(&m) 110 DispatchMessage(&m) 111 } 112 return int(m.Wparam) 113 */ 114 } 115 116 117 /* 118 func main() { 119 rc := rungui() 120 os.Exit(rc) 121 } 122 */