diff options
| author | Pietro Gagliardi <[email protected]> | 2014-02-11 13:06:12 -0500 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-02-11 13:06:12 -0500 |
| commit | 42229820d2a47594f68d92356f8e8a86133a29f5 (patch) | |
| tree | 3cd5deef283b4540bae2f75c049a5e69d4e9db20 /wndclass_windows.go | |
| parent | a488e3ab36de1d6a329110fbaae44cd5747c854b (diff) | |
Added _windows.go extensions to all the files in preparation for the library writing.
Diffstat (limited to 'wndclass_windows.go')
| -rw-r--r-- | wndclass_windows.go | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/wndclass_windows.go b/wndclass_windows.go new file mode 100644 index 0000000..38ff4ae --- /dev/null +++ b/wndclass_windows.go @@ -0,0 +1,64 @@ +// 8 february 2014 +package main + +import ( + "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 +} + +type _WNDCLASSW struct { + style uint32 + lpfnWndProc uintptr + cbClsExtra int + cbWndExtra int + 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) + } + 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), + } +} + +var ( + registerClass = user32.NewProc("RegisterClassW") +) + +func RegisterClass(lpWndClass *WNDCLASS) (class ATOM, err error) { + r1, _, err := registerClass.Call(uintptr(unsafe.Pointer(lpWndClass.toNative()))) + if r1 == 0 { // failure + return 0, err + } + return ATOM(r1), nil +} |
