From c6a8a4d2f799756fa83a9e556d363decd896e8f2 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 11 Feb 2014 17:39:41 -0500 Subject: (see previous commit; part 2) --- init_windows.go | 1 - stdwndclass_windows.go | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ wndclass_windows.go | 78 -------------------------------------------------- 3 files changed, 78 insertions(+), 79 deletions(-) create mode 100644 stdwndclass_windows.go delete mode 100644 wndclass_windows.go diff --git a/init_windows.go b/init_windows.go index cc1cb5d..8e39e2b 100644 --- a/init_windows.go +++ b/init_windows.go @@ -11,7 +11,6 @@ var ( hInstance HANDLE nCmdShow int // TODO font - // TODO common window class ) // TODO is this trick documented in MSDN? 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 +} diff --git a/wndclass_windows.go b/wndclass_windows.go deleted file mode 100644 index e6796e5..0000000 --- a/wndclass_windows.go +++ /dev/null @@ -1,78 +0,0 @@ -// 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 -} -- cgit v1.2.3