summaryrefslogtreecommitdiff
path: root/stdwndclass_windows.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-02-11 17:39:41 -0500
committerPietro Gagliardi <[email protected]>2014-02-11 17:39:41 -0500
commitc6a8a4d2f799756fa83a9e556d363decd896e8f2 (patch)
tree6dfa938d0cf30d8a4c1b4174288d122cb4ae781a /stdwndclass_windows.go
parenteeff0d860593710a9c4a9749f599266892f276f8 (diff)
(see previous commit; part 2)
Diffstat (limited to 'stdwndclass_windows.go')
-rw-r--r--stdwndclass_windows.go78
1 files changed, 78 insertions, 0 deletions
diff --git a/stdwndclass_windows.go b/stdwndclass_windows.go
new file mode 100644
index 0000000..e6796e5
--- /dev/null
+++ b/stdwndclass_windows.go
@@ -0,0 +1,78 @@
+// 8 february 2014
+package main
+
+import (
+ "fmt"
+ "syscall"
+ "unsafe"
+)
+
+const (
+ stdWndClass = "gouiwndclass"
+)
+
+var (
+ defWindowProc = user32.NewProc("DefWindowProcW")
+)
+
+func stdWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESULT {
+ // TODO get CreateWindowEx data
+ switch uMsg {
+ default:
+ r1, _, _ := defWindowProc.Call(
+ uintptr(hwnd),
+ uintptr(uMsg),
+ uintptr(wParam),
+ uintptr(lParam))
+ return LRESULT(r1)
+ }
+ panic(fmt.Sprintf("stdWndProc message %d did not return: internal bug in ui library", uMsg))
+}
+
+type _WNDCLASS struct {
+ style uint32
+ lpfnWndProc uintptr
+ cbClsExtra int
+ cbWndExtra int
+ hInstance _HANDLE
+ hIcon _HANDLE
+ hCursor _HANDLE
+ hbrBackground _HBRUSH
+ lpszMenuName *uint16
+ lpszClassName *uint16
+}
+
+func registerStdWndClass() (err error) {
+ const (
+ _IDI_APPLICATION = 32512
+ _IDC_ARROW = 32512
+ )
+
+ icon, err := user32.NewProc("LoadIconW").Call(
+ uintptr(_NULL),
+ uintptr(_IDI_APPLICATION))
+ if err != nil {
+ return fmt.Errorf("error getting window icon: %v", err)
+ }
+ cursor, err := user32.NewProc("LoadCursorW").Call(
+ uintptr(_NULL),
+ uintptr(_IDC_ARROW))
+ if err != nil {
+ return fmt.Errorf("error getting window cursor: %v", err)
+ }
+
+ wc := &_WNDCLASS{
+ lpszClassName: syscall.StringToUTF16Ptr(stdWndClass),
+ lpfnWndProc: syscall.NewCallback(stdWndProc),
+ hInstance: hInstance,
+ hIcon: icon,
+ hCursor: cursor,
+ hbrBackground: _HBRUSH(_COLOR_BTNFACE + 1),
+ }
+
+ r1, _, err := user32.NewProc("RegisterClassW").Call(uintptr(unsafe.Pointer(wc)))
+ if r1 == 0 { // failure
+ return fmt.Errorf("error registering class: %v", err)
+ }
+ return nil
+}