summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-02-12 18:14:37 -0500
committerPietro Gagliardi <[email protected]>2014-02-12 18:14:37 -0500
commita9ff38894408e0a34da4742fc2b1aea0bb5ef60b (patch)
tree2c4e58eb079cdd59537216943fc97fdd4fbd7a2d
parent0a9f40812950ad00239e93141a37183666d5f3eb (diff)
Added Window.SetTitle(). Also oops, forgot to mark the window as created.
-rw-r--r--main.go5
-rw-r--r--sysdata.go3
-rw-r--r--sysdata_windows.go18
-rw-r--r--todo.md1
-rw-r--r--window.go3
-rw-r--r--windows_windows.go1
6 files changed, 29 insertions, 2 deletions
diff --git a/main.go b/main.go
index 09fae17..273a13a 100644
--- a/main.go
+++ b/main.go
@@ -16,7 +16,10 @@ mainloop:
case <-w.Closing:
break mainloop
case <-b.Clicked:
- println("clicked")
+ err := w.SetTitle("Button Clicked")
+ if err != nil {
+ panic(err)
+ }
}
}
w.Close()
diff --git a/sysdata.go b/sysdata.go
index 41319b1..339d73e 100644
--- a/sysdata.go
+++ b/sysdata.go
@@ -25,6 +25,9 @@ func (c *cSysData) show() error {
func (c *cSysData) hide() error {
panic(runtime.GOOS + " sysData does not define hide()")
}
+func (c *cSysData) setText(text string) error {
+ panic(runtime.GOOS + " sysData does not define setText()")
+}
const (
c_window = iota
diff --git a/sysdata_windows.go b/sysdata_windows.go
index 586b320..9be3007 100644
--- a/sysdata_windows.go
+++ b/sysdata_windows.go
@@ -143,3 +143,21 @@ func (s *sysData) hide() (err error) {
<-ret
return nil
}
+
+func (s *sysData) setText(text string) error {
+ ret := make(chan uiret)
+ defer close(ret)
+ uitask <- &uimsg{
+ call: _setWindowText,
+ p: []uintptr{
+ uintptr(s.hwnd),
+ uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(text))),
+ },
+ ret: ret,
+ }
+ r := <-ret
+ if r.ret == 0 { // failure
+ return r.err
+ }
+ return nil
+}
diff --git a/todo.md b/todo.md
index 12a96c0..6accdde 100644
--- a/todo.md
+++ b/todo.md
@@ -1,6 +1,7 @@
so I don't forget:
- Window.SizeToFit() or WIndow.OptimalSize() (use: `Window.SetSize(Window.OptimalSize())`) for sizing a window to the control's interest
- Control.Show()/Control.Hide()
+- Control.SetText()
super ultra important things:
- the windows build appears to be unstable:
diff --git a/window.go b/window.go
index 780414b..cdb346b 100644
--- a/window.go
+++ b/window.go
@@ -56,7 +56,7 @@ func (w *Window) SetTitle(title string) (err error) {
defer w.lock.Unlock()
if w.created {
- panic("TODO")
+ return w.sysData.setText(title)
}
w.initTitle = title
return nil
@@ -93,6 +93,7 @@ func (w *Window) Open() (err error) {
return err
}
}
+ w.created = true
}
return w.sysData.show()
}
diff --git a/windows_windows.go b/windows_windows.go
index a8eb169..16f451d 100644
--- a/windows_windows.go
+++ b/windows_windows.go
@@ -170,6 +170,7 @@ var (
_getClientRect = user32.NewProc("GetClientRect")
_enumChildWindows = user32.NewProc("EnumChildWindows")
_setWindowPos = user32.NewProc("SetWindowPos")
+ _setWindowText = user32.NewProc("SetWindowTextW")
_showWindow = user32.NewProc("ShowWindow")
)