summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-02-10 04:59:39 -0500
committerPietro Gagliardi <[email protected]>2014-02-10 04:59:39 -0500
commit6662e09c3064e6c24fb0bc12eca9b7ea716cb328 (patch)
tree9a282e555355d88e6f0f40b90e3f4f7687480393
parentef5739229eaae5f5f8c2346d1d6a789f2b79855d (diff)
Added a button to the test main window, including click handling.
-rw-r--r--common.go11
-rw-r--r--main.go27
-rw-r--r--menus.go12
-rw-r--r--windows.go2
4 files changed, 49 insertions, 3 deletions
diff --git a/common.go b/common.go
index f4c769e..1996f37 100644
--- a/common.go
+++ b/common.go
@@ -13,6 +13,7 @@ var (
type HANDLE uintptr
type HWND HANDLE
type HBRUSH HANDLE
+type HMENU HANDLE
const (
NULL = 0
@@ -25,6 +26,16 @@ type WPARAM uintptr
type LPARAM uintptr
type LRESULT uintptr
+func (w WPARAM) LOWORD() uint16 {
+ // according to windef.h
+ return uint16(w & 0xFFFF)
+}
+
+func (w WPARAM) HIWORD() uint16 {
+ // according to windef.h
+ return uint16((w >> 16) & 0xFFFF)
+}
+
// microsoft's header files do this
func MAKEINTRESOURCE(what uint16) uintptr {
return uintptr(what)
diff --git a/main.go b/main.go
index fe38d47..dd82c13 100644
--- a/main.go
+++ b/main.go
@@ -19,8 +19,21 @@ func fatalf(format string, args ...interface{}) {
panic(fmt.Sprintf("error trying to warn user of internal error: %v\ninternal error:\n%s", err, s))
}
-func wndProc(hwnd HWND, msg uint32, wparam WPARAM, lparam LPARAM) LRESULT {
+const (
+ IDC_BUTTON = 100
+)
+
+func wndProc(hwnd HWND, msg uint32, wParam WPARAM, lParam LPARAM) LRESULT {
switch msg {
+ case WM_COMMAND:
+ if wParam.LOWORD() == IDC_BUTTON {
+ if wParam.HIWORD() == BN_CLICKED {
+ MessageBox(hwnd, "clicked", "", MB_OK)
+ } else if wParam.HIWORD() == BN_DOUBLECLICKED {
+ MessageBox(hwnd, "double clicked", "", MB_OK)
+ }
+ }
+ return 0
case WM_CLOSE:
err := DestroyWindow(hwnd)
if err != nil {
@@ -34,7 +47,7 @@ func wndProc(hwnd HWND, msg uint32, wparam WPARAM, lparam LPARAM) LRESULT {
}
return 0
default:
- return DefWindowProc(hwnd, msg, wparam, lparam)
+ return DefWindowProc(hwnd, msg, wParam, lParam)
}
fatalf("major bug: forgot a return on wndProc for message %d", msg)
panic("unreachable")
@@ -86,6 +99,16 @@ func main() {
fatalf("error creating window: %v", err)
}
+ _, err = CreateWindowEx(
+ 0,
+ "BUTTON", "Click Me",
+ BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP,
+ 20, 20, 100, 100,
+ hwnd, HMENU(IDC_BUTTON), hInstance, NULL)
+ if err != nil {
+ fatalf("error creating button: %v", err)
+ }
+
_, err = ShowWindow(hwnd, nCmdShow)
if err != nil {
fatalf("error showing window: %v", err)
diff --git a/menus.go b/menus.go
new file mode 100644
index 0000000..4f6c059
--- /dev/null
+++ b/menus.go
@@ -0,0 +1,12 @@
+// 10 february 2014
+package main
+
+import (
+// "syscall"
+// "unsafe"
+)
+
+// Menu notifications.
+const (
+ WM_COMMAND = 0x0111
+)
diff --git a/windows.go b/windows.go
index 21e09b9..6f0f4c1 100644
--- a/windows.go
+++ b/windows.go
@@ -138,7 +138,7 @@ var (
)
// TODO use lpParam
-func CreateWindowEx(dwExStyle uint32, lpClassName string, lpWindowName string, dwStyle uint32, x int, y int, nWidth int, nHeight int, hwndParent HWND, hMenu HANDLE, hInstance HANDLE, lpParam interface{}) (hwnd HWND, err error) {
+func CreateWindowEx(dwExStyle uint32, lpClassName string, lpWindowName string, dwStyle uint32, x int, y int, nWidth int, nHeight int, hwndParent HWND, hMenu HMENU, hInstance HANDLE, lpParam interface{}) (hwnd HWND, err error) {
r1, _, err := createWindowEx.Call(
uintptr(dwExStyle),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpClassName))),