Source code of Windows XP (NT5)
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.

254 lines
6.8 KiB

  1. /*****************************************************************************
  2. *
  3. * UI.c
  4. *
  5. * Copyright (c) 1997 Microsoft Corporation. All Rights Reserved.
  6. *
  7. * Abstract:
  8. *
  9. * The thing that does UI.
  10. *
  11. *****************************************************************************/
  12. #include "msnspa.h"
  13. /*****************************************************************************
  14. *
  15. * Overview:
  16. *
  17. * UI for the app is done on the main thread. The app itself
  18. * is not in the taskbar or in the tray. The only way to get to
  19. * it is to Alt+Tab to it. When you minimize it, it vanishes again.
  20. *
  21. * FEATURE -- someday create an optional tray icon
  22. *
  23. * Details:
  24. *
  25. * The main window
  26. * is just a dialog box. The window we create is just a
  27. * subclassed static control.
  28. *
  29. * By stealing an existing control, we don't need to register
  30. * our own bogus class.
  31. *
  32. * We hide from the taskbar by having a hidden owner.
  33. *
  34. * We show up in Alt+Tab because the hidden owner is
  35. * not marked WS_EX_TOOLWINDOW.
  36. *
  37. * We vanish on minimization by hiding ourselves, parking
  38. * the minimized window "in outer space" so it doesn't bother
  39. * the user. Then re-show it so it can take part in Alt+Tab.
  40. *
  41. *****************************************************************************/
  42. /*
  43. * These are the co-ordinates of outer space. Note that we can't base
  44. * this on GetSystemMetrics(SM_C[XY]SCREEN) because the user might be
  45. * running multiple monitors, and we need to be sure we are outside all
  46. * monitors. So we pick a really absurd value for outer space.
  47. */
  48. #define XOUTERSPACE (-32000)
  49. #define YOUTERSPACE (-32000)
  50. HWND g_hwndMain;
  51. HWND g_hwndDlg;
  52. int g_cMailUsers;
  53. int g_cNewsUsers;
  54. /*****************************************************************************
  55. *
  56. * @func void | UI_UpdateCounts |
  57. *
  58. * Update the counts of things.
  59. *
  60. *****************************************************************************/
  61. void INTERNAL
  62. UI_UpdateCounts(void)
  63. {
  64. SetDlgItemInt(g_hwndDlg, IDC_MAIL, g_cMailUsers, FALSE);
  65. SetDlgItemInt(g_hwndDlg, IDC_NEWS, g_cNewsUsers, FALSE);
  66. EnableWindow(GetDlgItem(g_hwndDlg, IDOK), !(g_cMailUsers | g_cNewsUsers));
  67. }
  68. /*****************************************************************************
  69. *
  70. * @func BOOL | UI_OnSysCommand |
  71. *
  72. * Munge some commands around.
  73. *
  74. *****************************************************************************/
  75. BOOL INTERNAL
  76. UI_OnSysCommand(HWND hdlg, WPARAM wp)
  77. {
  78. switch (wp & ~0xF) {
  79. case SC_CLOSE:
  80. FORWARD_WM_COMMAND(hdlg, IDCANCEL, 0, 0, PostMessage);
  81. return TRUE;
  82. }
  83. return FALSE;
  84. }
  85. /*****************************************************************************
  86. *
  87. * @func BOOL | UI_OnCommand |
  88. *
  89. * Munge some commands around.
  90. *
  91. *****************************************************************************/
  92. BOOL INTERNAL
  93. UI_OnCommand(HWND hdlg, WPARAM wp)
  94. {
  95. ANIMATIONINFO aniOld, aniNew;
  96. switch (wp) {
  97. case IDCANCEL:
  98. /*
  99. * There is no way to minimize a hidden window.
  100. */
  101. aniOld.cbSize = sizeof(aniOld);
  102. SystemParametersInfo(SPI_GETANIMATION, sizeof(aniOld), &aniOld, 0);
  103. aniNew.cbSize = sizeof(aniNew);
  104. aniNew.iMinAnimate = 0;
  105. SystemParametersInfo(SPI_SETANIMATION, sizeof(aniNew), &aniNew, 0);
  106. ShowWindow(hdlg, SW_MINIMIZE);
  107. SystemParametersInfo(SPI_SETANIMATION, sizeof(aniOld), &aniOld, 0);
  108. SetWindowPos(hdlg, HWND_BOTTOM,
  109. XOUTERSPACE, YOUTERSPACE, 0, 0,
  110. SWP_NOACTIVATE | SWP_NOSIZE | SWP_SHOWWINDOW);
  111. return TRUE;
  112. case IDOK:
  113. FORWARD_WM_CLOSE(hdlg, PostMessage);
  114. return TRUE;
  115. }
  116. return FALSE;
  117. }
  118. /*****************************************************************************
  119. *
  120. * @func BOOL | UI_OnClose |
  121. *
  122. * Note that various weird conditions can lead to us getting
  123. * here while there are active sessions, so re-check before
  124. * leaving.
  125. *
  126. *****************************************************************************/
  127. void INTERNAL
  128. UI_OnClose(HWND hdlg)
  129. {
  130. if (IsWindowEnabled(GetDlgItem(hdlg, IDOK))) {
  131. DestroyWindow(hdlg);
  132. }
  133. }
  134. /*****************************************************************************
  135. *
  136. * @func INT_PTR | UI_DlgProc |
  137. *
  138. * Our dialog procedure.
  139. *
  140. *****************************************************************************/
  141. INT_PTR CALLBACK
  142. UI_DlgProc(HWND hdlg, UINT wm, WPARAM wp, LPARAM lp)
  143. {
  144. switch (wm) {
  145. case WM_SYSCOMMAND:
  146. return UI_OnSysCommand(hdlg, wp);
  147. case WM_COMMAND:
  148. return UI_OnCommand(hdlg, wp);
  149. case WM_NCPAINT:
  150. if (IsIconic(hdlg)) {
  151. return TRUE;
  152. }
  153. break;
  154. case WM_CLOSE:
  155. UI_OnClose(hdlg);
  156. return TRUE;
  157. case WM_DESTROY:
  158. PostQuitMessage(0);
  159. break;
  160. }
  161. return FALSE;
  162. }
  163. /*****************************************************************************
  164. *
  165. * @func HWND | UI_Init |
  166. *
  167. * Initialize the UI stuff.
  168. *
  169. * @returns
  170. *
  171. * Nonzero on success.
  172. *
  173. *****************************************************************************/
  174. HWND INTERNAL
  175. UI_Init(void)
  176. {
  177. g_hwndMain = CreateWindow(
  178. "static", /* Class Name */
  179. "", /* Title */
  180. WS_OVERLAPPEDWINDOW | WS_MINIMIZE,
  181. /* Style (note: not visible) */
  182. CW_USEDEFAULT, CW_USEDEFAULT, /* Position */
  183. CW_USEDEFAULT, CW_USEDEFAULT, /* Size */
  184. NULL, /* Parent */
  185. NULL, /* Use class menu */
  186. g_hinst, /* Instance */
  187. 0); /* No special parameters */
  188. // SubclassWindow(g_hwndMain, Main_WndProc);
  189. SendMessage(g_hwndMain, WM_SETICON, ICON_BIG,
  190. (LPARAM)LoadIcon(g_hinst, MAKEINTRESOURCE(IDI_MAIN)));
  191. /*
  192. * Create the dialog not visible because we're going to be shoving
  193. * it around.
  194. */
  195. g_hwndDlg = CreateDialog(g_hinst, MAKEINTRESOURCE(IDD_MAIN),
  196. g_hwndMain, UI_DlgProc);
  197. /*
  198. * Tell the system that the window should be parked in outer space.
  199. */
  200. SetWindowPos(g_hwndDlg, HWND_BOTTOM,
  201. XOUTERSPACE, YOUTERSPACE, 0, 0,
  202. SWP_NOACTIVATE | SWP_NOSIZE | SWP_SHOWWINDOW);
  203. return g_hwndDlg;
  204. }
  205. /*****************************************************************************
  206. *
  207. * @func void | UI_Term |
  208. *
  209. * Clean up the UI stuff.
  210. *
  211. *****************************************************************************/
  212. void INTERNAL
  213. UI_Term(void)
  214. {
  215. DestroyWindow(g_hwndMain);
  216. }