2014-02-08 22:51:11 -06:00
|
|
|
// 8 february 2014
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-02-11 16:38:38 -06:00
|
|
|
"fmt"
|
2014-02-08 22:51:11 -06:00
|
|
|
"syscall"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2014-02-11 18:52:39 -06:00
|
|
|
var (
|
2014-02-11 16:38:38 -06:00
|
|
|
stdWndClass = "gouiwndclass"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
defWindowProc = user32.NewProc("DefWindowProcW")
|
|
|
|
)
|
|
|
|
|
|
|
|
func stdWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESULT {
|
2014-02-11 19:14:19 -06:00
|
|
|
// sysData := getSysData(hwnd)
|
2014-02-11 16:38:38 -06:00
|
|
|
switch uMsg {
|
2014-02-11 17:22:39 -06:00
|
|
|
case _WM_COMMAND:
|
|
|
|
id := wParam.LOWORD()
|
|
|
|
// ... member events
|
|
|
|
_ = id
|
|
|
|
return 0
|
|
|
|
case _WM_GETMINMAXINFO:
|
|
|
|
mm := lParam.MINMAXINFO()
|
|
|
|
// ... minimum size
|
|
|
|
_ = mm
|
|
|
|
return 0
|
|
|
|
case _WM_SIZE:
|
|
|
|
// TODO
|
|
|
|
return 0
|
|
|
|
case _WM_CLOSE:
|
2014-02-11 19:14:19 -06:00
|
|
|
/* if sysData.closing != nil {
|
2014-02-11 17:57:03 -06:00
|
|
|
sysData.closing <- struct{}{}
|
2014-02-11 17:22:39 -06:00
|
|
|
}
|
2014-02-11 19:14:19 -06:00
|
|
|
*/ return 0
|
2014-02-11 16:38:38 -06:00
|
|
|
default:
|
|
|
|
r1, _, _ := defWindowProc.Call(
|
|
|
|
uintptr(hwnd),
|
|
|
|
uintptr(uMsg),
|
|
|
|
uintptr(wParam),
|
|
|
|
uintptr(lParam))
|
2014-02-11 18:18:03 -06:00
|
|
|
return _LRESULT(r1)
|
2014-02-11 16:38:38 -06:00
|
|
|
}
|
|
|
|
panic(fmt.Sprintf("stdWndProc message %d did not return: internal bug in ui library", uMsg))
|
2014-02-08 22:51:11 -06:00
|
|
|
}
|
|
|
|
|
2014-02-11 16:38:38 -06:00
|
|
|
type _WNDCLASS struct {
|
2014-02-08 22:51:11 -06:00
|
|
|
style uint32
|
2014-02-09 13:59:37 -06:00
|
|
|
lpfnWndProc uintptr
|
2014-02-08 22:51:11 -06:00
|
|
|
cbClsExtra int
|
|
|
|
cbWndExtra int
|
2014-02-11 16:38:38 -06:00
|
|
|
hInstance _HANDLE
|
|
|
|
hIcon _HANDLE
|
|
|
|
hCursor _HANDLE
|
|
|
|
hbrBackground _HBRUSH
|
2014-02-08 22:51:11 -06:00
|
|
|
lpszMenuName *uint16
|
2014-02-11 18:52:39 -06:00
|
|
|
lpszClassName uintptr
|
2014-02-08 22:51:11 -06:00
|
|
|
}
|
|
|
|
|
2014-02-11 16:38:38 -06:00
|
|
|
func registerStdWndClass() (err error) {
|
|
|
|
const (
|
|
|
|
_IDI_APPLICATION = 32512
|
|
|
|
_IDC_ARROW = 32512
|
|
|
|
)
|
|
|
|
|
2014-02-11 18:18:03 -06:00
|
|
|
r1, _, err := user32.NewProc("LoadIconW").Call(
|
2014-02-11 16:38:38 -06:00
|
|
|
uintptr(_NULL),
|
|
|
|
uintptr(_IDI_APPLICATION))
|
2014-02-11 18:27:58 -06:00
|
|
|
if r1 == 0 { // failure
|
2014-02-11 16:38:38 -06:00
|
|
|
return fmt.Errorf("error getting window icon: %v", err)
|
2014-02-08 22:51:11 -06:00
|
|
|
}
|
2014-02-11 18:18:03 -06:00
|
|
|
icon := _HANDLE(r1)
|
|
|
|
|
|
|
|
r1, _, err = user32.NewProc("LoadCursorW").Call(
|
2014-02-11 16:38:38 -06:00
|
|
|
uintptr(_NULL),
|
|
|
|
uintptr(_IDC_ARROW))
|
2014-02-11 18:27:58 -06:00
|
|
|
if r1 == 0 { // failure
|
2014-02-11 16:38:38 -06:00
|
|
|
return fmt.Errorf("error getting window cursor: %v", err)
|
2014-02-08 22:51:11 -06:00
|
|
|
}
|
2014-02-11 18:18:03 -06:00
|
|
|
cursor := _HANDLE(r1)
|
2014-02-08 22:51:11 -06:00
|
|
|
|
2014-02-11 16:38:38 -06:00
|
|
|
wc := &_WNDCLASS{
|
2014-02-11 18:52:39 -06:00
|
|
|
lpszClassName: uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(stdWndClass))),
|
2014-02-11 16:38:38 -06:00
|
|
|
lpfnWndProc: syscall.NewCallback(stdWndProc),
|
|
|
|
hInstance: hInstance,
|
|
|
|
hIcon: icon,
|
|
|
|
hCursor: cursor,
|
|
|
|
hbrBackground: _HBRUSH(_COLOR_BTNFACE + 1),
|
|
|
|
}
|
2014-02-08 22:51:11 -06:00
|
|
|
|
2014-02-11 18:18:03 -06:00
|
|
|
r1, _, err = user32.NewProc("RegisterClassW").Call(uintptr(unsafe.Pointer(wc)))
|
2014-02-08 22:51:11 -06:00
|
|
|
if r1 == 0 { // failure
|
2014-02-11 16:38:38 -06:00
|
|
|
return fmt.Errorf("error registering class: %v", err)
|
2014-02-08 22:51:11 -06:00
|
|
|
}
|
2014-02-11 16:38:38 -06:00
|
|
|
return nil
|
2014-02-08 22:51:11 -06:00
|
|
|
}
|