Added Window.SetTitle(). Also oops, forgot to mark the window as created.

This commit is contained in:
Pietro Gagliardi 2014-02-12 18:14:37 -05:00
parent 0a9f408129
commit a9ff388944
6 changed files with 29 additions and 2 deletions

View File

@ -16,7 +16,10 @@ mainloop:
case <-w.Closing: case <-w.Closing:
break mainloop break mainloop
case <-b.Clicked: case <-b.Clicked:
println("clicked") err := w.SetTitle("Button Clicked")
if err != nil {
panic(err)
}
} }
} }
w.Close() w.Close()

View File

@ -25,6 +25,9 @@ func (c *cSysData) show() error {
func (c *cSysData) hide() error { func (c *cSysData) hide() error {
panic(runtime.GOOS + " sysData does not define hide()") panic(runtime.GOOS + " sysData does not define hide()")
} }
func (c *cSysData) setText(text string) error {
panic(runtime.GOOS + " sysData does not define setText()")
}
const ( const (
c_window = iota c_window = iota

View File

@ -143,3 +143,21 @@ func (s *sysData) hide() (err error) {
<-ret <-ret
return nil 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
}

View File

@ -1,6 +1,7 @@
so I don't forget: so I don't forget:
- Window.SizeToFit() or WIndow.OptimalSize() (use: `Window.SetSize(Window.OptimalSize())`) for sizing a window to the control's interest - Window.SizeToFit() or WIndow.OptimalSize() (use: `Window.SetSize(Window.OptimalSize())`) for sizing a window to the control's interest
- Control.Show()/Control.Hide() - Control.Show()/Control.Hide()
- Control.SetText()
super ultra important things: super ultra important things:
- the windows build appears to be unstable: - the windows build appears to be unstable:

View File

@ -56,7 +56,7 @@ func (w *Window) SetTitle(title string) (err error) {
defer w.lock.Unlock() defer w.lock.Unlock()
if w.created { if w.created {
panic("TODO") return w.sysData.setText(title)
} }
w.initTitle = title w.initTitle = title
return nil return nil
@ -93,6 +93,7 @@ func (w *Window) Open() (err error) {
return err return err
} }
} }
w.created = true
} }
return w.sysData.show() return w.sysData.show()
} }

View File

@ -170,6 +170,7 @@ var (
_getClientRect = user32.NewProc("GetClientRect") _getClientRect = user32.NewProc("GetClientRect")
_enumChildWindows = user32.NewProc("EnumChildWindows") _enumChildWindows = user32.NewProc("EnumChildWindows")
_setWindowPos = user32.NewProc("SetWindowPos") _setWindowPos = user32.NewProc("SetWindowPos")
_setWindowText = user32.NewProc("SetWindowTextW")
_showWindow = user32.NewProc("ShowWindow") _showWindow = user32.NewProc("ShowWindow")
) )