Пример #1
0
BOOL mintrayr_CreateIcon(void *handle, mouseevent_callback_t callback)
{
  HWND hwnd = (HWND)handle;
  if (!hwnd) {
    return FALSE;
  }

  SetupWnd(hwnd);

  NOTIFYICONDATAW *iconData = new NOTIFYICONDATAW;
  // Init the icon data according to MSDN
  iconData->cbSize = sizeof(NOTIFYICONDATAW);

  // Copy the title
  if (GetWindowText(hwnd, iconData->szTip, 127)) {
    iconData->szTip[128] = '\0'; // Better be safe than sorry :p
  }
  else{
    iconData->szTip[0] = '\0';
  }

  // Get the window icon
  HICON icon = reinterpret_cast<HICON>(::SendMessageW(hwnd, WM_GETICON, ICON_SMALL, 0));
  if (icon == 0) {
    // Alternative method. Get from the window class
    icon = reinterpret_cast<HICON>(::GetClassLongPtrW(hwnd, GCLP_HICONSM));
  }
  // Alternative method: get the first icon from the main module (executable image of the process)
  if (icon == 0) {
    icon = ::LoadIcon(GetModuleHandleW(0), MAKEINTRESOURCE(0));
  }
  // Alternative method. Use OS default icon
  if (icon == 0) {
    icon = ::LoadIcon(0, IDI_APPLICATION);
  }
  iconData->hIcon = icon;

  // Set the rest of the members
  iconData->hWnd = hwnd;
  iconData->uCallbackMessage = WM_TRAYMESSAGE;
  iconData->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  iconData->uVersion = 5;

  // Install the icon
  ::Shell_NotifyIconW(NIM_ADD, iconData);
  ::Shell_NotifyIconW(NIM_SETVERSION, iconData);

  SetupWnd(hwnd);
  ::SetPropW(hwnd, kIconData, reinterpret_cast<HANDLE>(iconData));
  ::SetPropW(hwnd, kIconMouseEventProc, reinterpret_cast<HANDLE>(callback));
  ::SetPropW(hwnd, kIcon, reinterpret_cast<HANDLE>(0x1));

  return TRUE;
}
NS_IMETHODIMP Icon::Init(nsIDOMWindow *aWindow, const nsString& aTitle)
{
  nsresult rv;
  nsCOMPtr<nsIBaseWindow> baseWindow;
  rv = GetBaseWindow(aWindow, getter_AddRefs(baseWindow));
  NS_ENSURE_SUCCESS(rv, rv);

  nativeWindow native = 0;
  rv = baseWindow->GetParentNativeWindow(&native);
  NS_ENSURE_SUCCESS(rv, rv);

  mWnd = reinterpret_cast<HWND>(native);
  SetupWnd(mWnd, aWindow);

  // Hook window
  ::SetPropW(mWnd, kIcon, reinterpret_cast<HANDLE>(0x1));

  // Init the icon data according to MSDN
  ZeroMemory(&mIconData, sizeof(mIconData));
  mIconData.cbSize = sizeof(mIconData);

  // Copy the title
  lstrcpynW(mIconData.szTip, aTitle.get(), 127);
  mIconData.szTip[128] = '\0'; // Better be safe than sorry :p

  // Get the window icon
  HICON icon = reinterpret_cast<HICON>(::SendMessageW(mWnd, WM_GETICON, ICON_SMALL, 0));
  if (icon == 0) {
    // Alternative method. Get from the window class
    icon = reinterpret_cast<HICON>(::GetClassLongPtrW(mWnd, GCLP_HICONSM));
  }
  // Alternative method: get the first icon from the main module (executable image of the process)
  if (icon == 0) {
    icon = ::LoadIcon(GetModuleHandleW(0), MAKEINTRESOURCE(0));
  }
  // Alternative method. Use OS default icon
  if (icon == 0) {
    icon = ::LoadIcon(0, IDI_APPLICATION);
  }
  mIconData.hIcon = icon;

  // Set the rest of the members
  mIconData.hWnd = mWnd;
  mIconData.uCallbackMessage = WM_TRAYMESSAGE;
  mIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  mIconData.uVersion = 5;

  // Install the icon
  ::Shell_NotifyIconW(NIM_ADD, &mIconData);
  ::Shell_NotifyIconW(NIM_SETVERSION, &mIconData);

  ::SetPropW(mWnd, kIcon, reinterpret_cast<HANDLE>(0x1));
  ::SetPropW(mWnd, kPlatformIcon, reinterpret_cast<HANDLE>(this));

  return NS_OK;
}
Пример #3
0
BOOL mintrayr_WatchWindow(void *handle, minimize_callback_t callback)
{
  HWND hwnd = (HWND)handle;
  if (!hwnd) {
    return FALSE;
  }

  SetupWnd(hwnd);
  ::SetPropW(hwnd, kWatchMinimizeProc, reinterpret_cast<HANDLE>(callback));
  ::SetPropW(hwnd, kWatch, reinterpret_cast<HANDLE>(0x1));

  return TRUE;
}
Пример #4
0
BOOL mintrayr_DestroyIcon(void *handle)
{
  HWND hwnd = (HWND)handle;
  if (!hwnd) {
    return FALSE;
  }

  mintrayr_RestoreWindow(handle);

  SetupWnd(hwnd);
  ::RemovePropW(hwnd, kIcon);

  NOTIFYICONDATAW *iconData = reinterpret_cast<NOTIFYICONDATAW *>(::GetPropW(hwnd, kIconData));
  if (iconData) {
    ::Shell_NotifyIconW(NIM_DELETE, iconData);
    delete iconData;
  }
  ::RemovePropW(hwnd, kIconData);

  ::RemovePropW(hwnd, kIconMouseEventProc);

  return TRUE;
}