Esempio n. 1
0
// Creates a hidden window, required for capturing the mouse interaction with the
// notify icon. Windows will call the WndProc of this window, whenever something happens
// on the notify icon (e.g. mouse click).
func (t *_NotifyIcon) createCallbackWindow() (err error) {
	className := "KeyFwdWindowClass"

	err = registerWindowClass(className, t.iconCallback)
	if err != nil {
		return
	}

	classNamePtr, _ := syscall.UTF16PtrFromString(className)
	t.hwnd = w32.CreateWindowEx(
		uint(w32.WS_EX_LEFT|w32.WS_EX_LTRREADING|w32.WS_EX_WINDOWEDGE),
		classNamePtr,
		nil,
		uint(w32.WS_OVERLAPPED|w32.WS_MINIMIZEBOX|w32.WS_SYSMENU|w32.WS_CLIPSIBLINGS|w32.WS_CAPTION),
		w32.CW_USEDEFAULT,
		w32.CW_USEDEFAULT,
		10,
		10,
		w32.HWND_DESKTOP,
		w32.HMENU(0),
		w32.GetModuleHandle(""),
		unsafe.Pointer(uintptr(0)),
	)
	if t.hwnd == 0 {
		return syscall.GetLastError()
	}

	return nil
}
Esempio n. 2
0
// NewWindow creates a new window and assigns it to a widget.
func newWindow(w sparta.Widget) {
	var win *window
	rect := w.Property(sparta.Geometry).(image.Rectangle)
	if p := w.Property(sparta.Parent); p != nil {
		pW := p.(sparta.Widget)
		pWin := pW.Window().(*window)
		win = &window{
			w:    w,
			back: pWin.back,
			fore: pWin.fore,
			pos:  rect.Min,
		}
		count := len(pW.Property(sparta.Childs).([]sparta.Widget))
		pW.SetProperty(sparta.Childs, w)
		win.id = w32.CreateWindowEx(0, stringToUTF16(childClass), nil,
			uint(w32.WS_CHILDWINDOW|w32.WS_VISIBLE),
			rect.Min.X, rect.Min.Y, rect.Dx(), rect.Dy(),
			pWin.id, w32.HMENU(count),
			w32.HINSTANCE(w32.GetWindowLong(pWin.id, w32.GWL_HINSTANCE)), nil)
		if win.id == 0 {
			log.Printf("w32: error: %v\n", getLastError())
			os.Exit(1)
		}
	} else {
		win = &window{
			w:    w,
			back: bkGround,
			fore: frGround,
		}
		win.id = w32.CreateWindowEx(uint(w32.WS_EX_CLIENTEDGE),
			stringToUTF16(baseClass), stringToUTF16(""),
			uint(w32.WS_OVERLAPPEDWINDOW),
			150, 150, rect.Dx()+extraX, rect.Dy()+extraY,
			0, 0, instance, nil)
		if win.id == 0 {
			log.Printf("w32: error: %v\n", getLastError())
			os.Exit(1)
		}
	}
	widgetTable[win.id] = w
	w.SetWindow(win)

	w32.ShowWindow(win.id, w32.SW_SHOWDEFAULT)
	if !w32.UpdateWindow(win.id) {
		log.Printf("w32: error: %v\n", getLastError())
		os.Exit(1)
	}
}