diff options
| author | Pietro Gagliardi <[email protected]> | 2014-02-08 23:51:11 -0500 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-02-08 23:51:11 -0500 |
| commit | ecc00bd1f5cb5d97387f762455c6c51afd0f2fae (patch) | |
| tree | c8fdb445944dcb5d231c7d57a12b747708ed6f57 /wndclass.go | |
| parent | 35e8a028f5d5f9654d7fa34ebadf26cfef845759 (diff) | |
Added a lot of the stuff needed to create a simple window. Not done yet...
Diffstat (limited to 'wndclass.go')
| -rw-r--r-- | wndclass.go | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/wndclass.go b/wndclass.go new file mode 100644 index 0000000..7296369 --- /dev/null +++ b/wndclass.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 WNDPROC + 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: 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 +} |
