Migrated over the window class and window procedure stuff, set up the standard window class, and wrote the skeleton window procedure.
This commit is contained in:
parent
b727a972ad
commit
eeff0d8605
|
@ -7,10 +7,6 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
windowclass = "gouiwndclass"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
hInstance HANDLE
|
hInstance HANDLE
|
||||||
nCmdShow int
|
nCmdShow int
|
||||||
|
@ -72,6 +68,10 @@ func doWindowsInit() (err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error getting WinMain nCmdShow: %v", err)
|
return fmt.Errorf("error getting WinMain nCmdShow: %v", err)
|
||||||
}
|
}
|
||||||
|
err = registerStdWndClass()
|
||||||
|
if err != nil {
|
||||||
|
reteurn fmt.Errorf("error registering standard window class: %v", err)
|
||||||
|
}
|
||||||
// TODO others
|
// TODO others
|
||||||
return nil // all ready to go
|
return nil // all ready to go
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ type classData struct {
|
||||||
|
|
||||||
var classTypes = [nctypes]*classData{
|
var classTypes = [nctypes]*classData{
|
||||||
c_window: &classData{
|
c_window: &classData{
|
||||||
name: uintptr(unsafe.Pointer(windowclass)),
|
name: uintptr(unsafe.Pointer(stdWndClass)),
|
||||||
style: xxxx,
|
style: xxxx,
|
||||||
xstyle: xxxx,
|
xstyle: xxxx,
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
// 8 february 2014
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
// "syscall"
|
|
||||||
// "unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// TODO error handling
|
|
||||||
type WNDPROC func(hwnd HWND, uMsg uint32, wParam WPARAM, lParam LPARAM) LRESULT
|
|
||||||
|
|
||||||
var (
|
|
||||||
defWindowProc = user32.NewProc("DefWindowProcW")
|
|
||||||
)
|
|
||||||
|
|
||||||
// TODO error handling
|
|
||||||
func DefWindowProc(hwnd HWND, uMsg uint32, wParam WPARAM, lParam LPARAM) LRESULT {
|
|
||||||
r1, _, _ := defWindowProc.Call(
|
|
||||||
uintptr(hwnd),
|
|
||||||
uintptr(uMsg),
|
|
||||||
uintptr(wParam),
|
|
||||||
uintptr(lParam))
|
|
||||||
return LRESULT(r1)
|
|
||||||
}
|
|
|
@ -2,63 +2,77 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WNDCLASS struct {
|
const (
|
||||||
Style uint32
|
stdWndClass = "gouiwndclass"
|
||||||
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
|
var (
|
||||||
HInstance HANDLE // actually HINSTANCE
|
defWindowProc = user32.NewProc("DefWindowProcW")
|
||||||
HIcon HANDLE // actually HICON
|
)
|
||||||
HCursor HANDLE // actually HCURSOR
|
|
||||||
HbrBackground HBRUSH
|
func stdWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESULT {
|
||||||
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
|
// TODO get CreateWindowEx data
|
||||||
LpszClassName string
|
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
|
style uint32
|
||||||
lpfnWndProc uintptr
|
lpfnWndProc uintptr
|
||||||
cbClsExtra int
|
cbClsExtra int
|
||||||
cbWndExtra int
|
cbWndExtra int
|
||||||
hInstance HANDLE
|
hInstance _HANDLE
|
||||||
hIcon HANDLE
|
hIcon _HANDLE
|
||||||
hCursor HANDLE
|
hCursor _HANDLE
|
||||||
hbrBackground HBRUSH
|
hbrBackground _HBRUSH
|
||||||
lpszMenuName *uint16
|
lpszMenuName *uint16
|
||||||
lpszClassName *uint16
|
lpszClassName *uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WNDCLASS) toNative() *_WNDCLASSW {
|
func registerStdWndClass() (err error) {
|
||||||
menuName := (*uint16)(nil)
|
const (
|
||||||
if w.LpszMenuName != nil {
|
_IDI_APPLICATION = 32512
|
||||||
menuName = syscall.StringToUTF16Ptr(*w.LpszMenuName)
|
_IDC_ARROW = 32512
|
||||||
}
|
|
||||||
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) {
|
icon, err := user32.NewProc("LoadIconW").Call(
|
||||||
r1, _, err := registerClass.Call(uintptr(unsafe.Pointer(lpWndClass.toNative())))
|
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
|
if r1 == 0 { // failure
|
||||||
return 0, err
|
return fmt.Errorf("error registering class: %v", err)
|
||||||
}
|
}
|
||||||
return ATOM(r1), nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue