summaryrefslogtreecommitdiff
path: root/wndclass_windows.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-02-11 17:38:38 -0500
committerPietro Gagliardi <[email protected]>2014-02-11 17:38:38 -0500
commiteeff0d860593710a9c4a9749f599266892f276f8 (patch)
treebf64ac26993008cd4c1febae5eac55b601dd5e73 /wndclass_windows.go
parentb727a972adbc90c3cdfbff2c462a583aefd48474 (diff)
Migrated over the window class and window procedure stuff, set up the standard window class, and wrote the skeleton window procedure.
Diffstat (limited to 'wndclass_windows.go')
-rw-r--r--wndclass_windows.go92
1 files changed, 53 insertions, 39 deletions
diff --git a/wndclass_windows.go b/wndclass_windows.go
index 38ff4ae..e6796e5 100644
--- a/wndclass_windows.go
+++ b/wndclass_windows.go
@@ -2,63 +2,77 @@
package main
import (
+ "fmt"
"syscall"
"unsafe"
)
-type WNDCLASS struct {
- Style uint32
- LpfnWndProc WNDPROC
- CbClsExtra int // TODO exact Go type for C int? MSDN says C int
- CbWndExtra int // TODO exact Go type for C int? MSDN says C int
- HInstance HANDLE // actually HINSTANCE
- HIcon HANDLE // actually HICON
- HCursor HANDLE // actually HCURSOR
- HbrBackground HBRUSH
- LpszMenuName *string // TODO this should probably just be a regular string with "" indicating no name but MSDN doesn't say if that's legal or not
- LpszClassName string
+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 _WNDCLASSW struct {
+type _WNDCLASS struct {
style uint32
lpfnWndProc uintptr
cbClsExtra int
cbWndExtra int
- hInstance HANDLE
- hIcon HANDLE
- hCursor HANDLE
- hbrBackground HBRUSH
+ hInstance _HANDLE
+ hIcon _HANDLE
+ hCursor _HANDLE
+ hbrBackground _HBRUSH
lpszMenuName *uint16
lpszClassName *uint16
}
-func (w *WNDCLASS) toNative() *_WNDCLASSW {
- menuName := (*uint16)(nil)
- if w.LpszMenuName != nil {
- menuName = syscall.StringToUTF16Ptr(*w.LpszMenuName)
+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)
}
- return &_WNDCLASSW{
- style: w.Style,
- lpfnWndProc: syscall.NewCallback(w.LpfnWndProc),
- cbClsExtra: w.CbClsExtra,
- cbWndExtra: w.CbWndExtra,
- hInstance: w.HInstance,
- hIcon: w.HIcon,
- hCursor: w.HCursor,
- hbrBackground: w.HbrBackground,
- lpszMenuName: menuName,
- lpszClassName: syscall.StringToUTF16Ptr(w.LpszClassName),
+ cursor, err := user32.NewProc("LoadCursorW").Call(
+ uintptr(_NULL),
+ uintptr(_IDC_ARROW))
+ if err != nil {
+ return fmt.Errorf("error getting window cursor: %v", err)
}
-}
-var (
- registerClass = user32.NewProc("RegisterClassW")
-)
+ wc := &_WNDCLASS{
+ lpszClassName: syscall.StringToUTF16Ptr(stdWndClass),
+ lpfnWndProc: syscall.NewCallback(stdWndProc),
+ hInstance: hInstance,
+ hIcon: icon,
+ hCursor: cursor,
+ hbrBackground: _HBRUSH(_COLOR_BTNFACE + 1),
+ }
-func RegisterClass(lpWndClass *WNDCLASS) (class ATOM, err error) {
- r1, _, err := registerClass.Call(uintptr(unsafe.Pointer(lpWndClass.toNative())))
+ r1, _, err := user32.NewProc("RegisterClassW").Call(uintptr(unsafe.Pointer(wc)))
if r1 == 0 { // failure
- return 0, err
+ return fmt.Errorf("error registering class: %v", err)
}
- return ATOM(r1), nil
+ return nil
}