예제 #1
0
// Fetch an icon handle using a ICONDIRENTRY struct
func getIconHandle(icoData []byte, dirEntry _ICONDIRENTRY) w32.HICON {
	ret, _ := createIconFromResourceEx(
		&icoData[dirEntry.dwImageOffset],
		w32.DWORD(0),
		true,
		w32.DWORD(0x30000),
		int32(dirEntry.bWidth),
		int32(dirEntry.bHeight),
		_LR_DEFAULT_COLOR)
	return w32.HICON(ret)
}
예제 #2
0
// Adds the notification icon and starts handling the mouse
// interaction with the icon.
// Calls to this function will block until the Stop() function
// will be called from another goroutine/thread.
// Returns an error, if adding the notify icons fails.
func (t *_NotifyIcon) Start() (err error) {
	log.Println("Creating notification icon")

	tooltipUtf16, _ := syscall.UTF16FromString(t.tooltip)
	t.nid.CbSize = w32.DWORD(unsafe.Sizeof(&t.nid))
	t.nid.HWnd = t.hwnd
	t.nid.UFlags = _NIF_MESSAGE | _NIF_ICON | _NIF_TIP
	t.nid.UID = niUID
	t.nid.UCallbackMessage = niCallbackMessage
	copy(t.nid.SzTip[:], tooltipUtf16)
	err = shellNotifyIcon(_NIM_ADD, &t.nid)
	if err != nil {
		return
	}

	var msg w32.MSG
	for w32.GetMessage(&msg, t.hwnd, uint32(0), uint32(0)) != 0 {
		w32.TranslateMessage(&msg)
		w32.DispatchMessage(&msg)
	}
	return nil
}