Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
4.9 KiB

  1. // File: taskbar.cpp
  2. #include "precomp.h"
  3. #include "resource.h"
  4. #include "confroom.h" // for CreateConfRoom
  5. #include "cmd.h"
  6. #include "conf.h"
  7. #include "taskbar.h"
  8. #include "confwnd.h"
  9. BOOL AddTaskbarIcon(HWND hwnd)
  10. {
  11. BOOL bRet = FALSE;
  12. RegEntry re(CONFERENCING_KEY, HKEY_CURRENT_USER);
  13. if (TASKBARICON_ALWAYS == re.GetNumber(REGVAL_TASKBAR_ICON, TASKBARICON_DEFAULT))
  14. {
  15. // Place a 16x16 icon in the taskbar notification area:
  16. NOTIFYICONDATA tnid;
  17. tnid.cbSize = sizeof(NOTIFYICONDATA);
  18. tnid.hWnd = hwnd;
  19. tnid.uID = ID_TASKBAR_ICON;
  20. tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
  21. tnid.uCallbackMessage = WM_TASKBAR_NOTIFY;
  22. tnid.hIcon = LoadIcon(::GetInstanceHandle(), MAKEINTRESOURCE(IDI_SM_WORLD));
  23. ::LoadString(::GetInstanceHandle(), IDS_MEDIAPHONE_TITLE,
  24. tnid.szTip, CCHMAX(tnid.szTip));
  25. if (FALSE == (bRet = Shell_NotifyIcon(NIM_ADD, &tnid)))
  26. {
  27. // We could just be re-adding the icon...
  28. if(GetLastError() != 0)
  29. {
  30. // ISSUE: How do we want to handle this error?
  31. ERROR_OUT(("Could not add notify icon!"));
  32. }
  33. }
  34. else
  35. {
  36. ::RefreshTaskbarIcon(::GetHiddenWindow());
  37. }
  38. if (NULL != tnid.hIcon)
  39. {
  40. DestroyIcon(tnid.hIcon);
  41. }
  42. }
  43. return bRet;
  44. }
  45. BOOL RefreshTaskbarIcon(HWND hwnd)
  46. {
  47. BOOL bRet = FALSE;
  48. RegEntry re(CONFERENCING_KEY, HKEY_CURRENT_USER);
  49. if (TASKBARICON_ALWAYS == re.GetNumber(REGVAL_TASKBAR_ICON, TASKBARICON_DEFAULT))
  50. {
  51. UINT uIconId = FDoNotDisturb() ? IDI_DO_NOT_DISTURB : IDI_SM_WORLD;
  52. NOTIFYICONDATA tnid;
  53. tnid.cbSize = sizeof(NOTIFYICONDATA);
  54. tnid.hWnd = hwnd;
  55. tnid.uID = ID_TASKBAR_ICON;
  56. tnid.uFlags = NIF_ICON;
  57. tnid.hIcon = LoadIcon(::GetInstanceHandle(), MAKEINTRESOURCE(uIconId));
  58. if (FALSE == (bRet = Shell_NotifyIcon(NIM_MODIFY, &tnid)))
  59. {
  60. // ISSUE: How do we want to handle this error?
  61. ERROR_OUT(("Could not change notify icon!"));
  62. }
  63. if (NULL != tnid.hIcon)
  64. {
  65. DestroyIcon(tnid.hIcon);
  66. }
  67. }
  68. return bRet;
  69. }
  70. BOOL RemoveTaskbarIcon(HWND hwnd)
  71. {
  72. NOTIFYICONDATA tnid;
  73. tnid.cbSize = sizeof(NOTIFYICONDATA);
  74. tnid.hWnd = hwnd;
  75. tnid.uID = ID_TASKBAR_ICON;
  76. return Shell_NotifyIcon(NIM_DELETE, &tnid);
  77. }
  78. BOOL OnRightClickTaskbar()
  79. {
  80. TRACE_OUT(("OnRightClickTaskbar called"));
  81. POINT ptClick;
  82. if (FALSE == ::GetCursorPos(&ptClick))
  83. {
  84. ptClick.x = ptClick.y = 0;
  85. }
  86. // Get the menu for the popup from the resource file.
  87. HMENU hMenu = ::LoadMenu(GetInstanceHandle(), MAKEINTRESOURCE(IDR_TASKBAR_POPUP));
  88. if (NULL == hMenu)
  89. {
  90. return FALSE;
  91. }
  92. // Get the first menu in it which we will use for the call to
  93. // TrackPopup(). This could also have been created on the fly using
  94. // CreatePopupMenu and then we could have used InsertMenu() or
  95. // AppendMenu.
  96. HMENU hMenuTrackPopup = ::GetSubMenu(hMenu, 0);
  97. // Bold the Open menuitem.
  98. //
  99. MENUITEMINFO iInfo;
  100. iInfo.cbSize = sizeof(iInfo);
  101. iInfo.fMask = MIIM_STATE;
  102. if(::GetMenuItemInfo(hMenu, IDM_TBPOPUP_OPEN, FALSE, &iInfo))
  103. {
  104. iInfo.fState |= MFS_DEFAULT;
  105. ::SetMenuItemInfo(hMenu, IDM_TBPOPUP_OPEN, FALSE , &iInfo);
  106. }
  107. if (0 != _Module.GetLockCount())
  108. {
  109. // Can't stop while an SDK app in charge...
  110. if(::GetMenuItemInfo(hMenu, IDM_TBPOPUP_STOP, FALSE, &iInfo))
  111. {
  112. iInfo.fState |= MFS_GRAYED | MFS_DISABLED;
  113. ::SetMenuItemInfo(hMenu, IDM_TBPOPUP_STOP, FALSE , &iInfo);
  114. }
  115. }
  116. // Draw and track the "floating" popup
  117. // According to the font view code, there is a bug in USER which causes
  118. // TrackPopupMenu to work incorrectly when the window doesn't have the
  119. // focus. The work-around is to temporarily create a hidden window and
  120. // make it the foreground and focus window.
  121. HWND hwndDummy = ::CreateWindow(_TEXT("STATIC"), NULL, 0,
  122. ptClick.x,
  123. ptClick.y,
  124. 1, 1, HWND_DESKTOP,
  125. NULL, _Module.GetModuleInstance(), NULL);
  126. if (NULL != hwndDummy)
  127. {
  128. HWND hwndPrev = ::GetForegroundWindow(); // to restore
  129. TPMPARAMS tpmp;
  130. tpmp.cbSize = sizeof(tpmp);
  131. tpmp.rcExclude.right = 1 + (tpmp.rcExclude.left = ptClick.x);
  132. tpmp.rcExclude.bottom = 1 + (tpmp.rcExclude.top = ptClick.y);
  133. ::SetForegroundWindow(hwndDummy);
  134. ::SetFocus(hwndDummy);
  135. int iRet = ::TrackPopupMenuEx( hMenuTrackPopup,
  136. TPM_RETURNCMD | TPM_HORIZONTAL | TPM_RIGHTALIGN |
  137. TPM_RIGHTBUTTON | TPM_LEFTBUTTON,
  138. ptClick.x,
  139. ptClick.y,
  140. hwndDummy,
  141. &tpmp);
  142. // Restore the previous foreground window (before destroying hwndDummy).
  143. if (hwndPrev)
  144. {
  145. ::SetForegroundWindow(hwndPrev);
  146. }
  147. ::DestroyWindow(hwndDummy);
  148. switch (iRet)
  149. {
  150. case IDM_TBPOPUP_OPEN:
  151. {
  152. ::CreateConfRoomWindow();
  153. break;
  154. }
  155. case IDM_TBPOPUP_STOP:
  156. {
  157. ::CmdShutdown();
  158. break;
  159. }
  160. }
  161. }
  162. // We are finished with the menu now, so destroy it
  163. ::DestroyMenu(hMenuTrackPopup);
  164. ::DestroyMenu(hMenu);
  165. return TRUE;
  166. }