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.

201 lines
4.7 KiB

  1. #include "isignup.h"
  2. #ifndef MB_ICONERROR
  3. #define MB_ICONERROR MB_ICONHAND
  4. #endif
  5. #ifndef MB_SETFOREGROUND
  6. #define MB_SETFOREGROUND 0
  7. #endif
  8. #define MAX_STRING 256
  9. static const HWND hwndNil = NULL;
  10. BOOL WarningMsg(HWND hwnd, UINT uId)
  11. {
  12. TCHAR szMsg[MAX_STRING + 1];
  13. LoadString(
  14. ghInstance,
  15. uId,
  16. szMsg,
  17. SIZEOF_TCHAR_BUFFER(szMsg));
  18. return (MessageBox(
  19. hwnd,
  20. szMsg,
  21. cszAppName,
  22. MB_SETFOREGROUND |
  23. MB_ICONEXCLAMATION |
  24. MB_OKCANCEL) == IDOK);
  25. }
  26. void ErrorMsg(HWND hwnd, UINT uId)
  27. {
  28. TCHAR szMsg[MAX_STRING + 1];
  29. LoadString(
  30. ghInstance,
  31. uId,
  32. szMsg,
  33. SIZEOF_TCHAR_BUFFER(szMsg));
  34. MessageBox(
  35. hwnd,
  36. szMsg,
  37. cszAppName,
  38. MB_SETFOREGROUND |
  39. MB_ICONERROR |
  40. MB_OK);
  41. }
  42. void ErrorMsg1(HWND hwnd, UINT uId, LPCTSTR lpszArg)
  43. {
  44. TCHAR szTemp[MAX_STRING + 1];
  45. TCHAR szMsg[MAX_STRING + 1];
  46. LoadString(
  47. ghInstance,
  48. uId,
  49. szTemp,
  50. SIZEOF_TCHAR_BUFFER(szTemp));
  51. wsprintf(szMsg, szTemp, lpszArg);
  52. MessageBox(
  53. hwnd,
  54. szMsg,
  55. cszAppName,
  56. MB_SETFOREGROUND |
  57. MB_ICONERROR |
  58. MB_OK);
  59. }
  60. void InfoMsg(HWND hwnd, UINT uId)
  61. {
  62. TCHAR szMsg[MAX_STRING];
  63. LoadString(
  64. ghInstance,
  65. uId,
  66. szMsg,
  67. SIZEOF_TCHAR_BUFFER(szMsg));
  68. MessageBox(
  69. hwnd,
  70. szMsg,
  71. cszAppName,
  72. MB_SETFOREGROUND |
  73. MB_ICONINFORMATION |
  74. MB_OK);
  75. }
  76. int PromptR(HWND hwnd, UINT uId, UINT uType)
  77. {
  78. TCHAR szMsg[MAX_STRING + 1];
  79. TCHAR szCaption[MAX_STRING + 1];
  80. LoadString(
  81. ghInstance,
  82. uId,
  83. szMsg,
  84. SIZEOF_TCHAR_BUFFER(szMsg));
  85. LoadString(
  86. ghInstance,
  87. IDS_SETTINGCHANGE,
  88. szCaption,
  89. SIZEOF_TCHAR_BUFFER(szCaption));
  90. return MessageBox(
  91. hwnd,
  92. szMsg,
  93. szCaption,
  94. uType);
  95. }
  96. BOOL PromptRestart(HWND hwnd)
  97. {
  98. return (PromptR(
  99. hwnd,
  100. IDS_RESTART,
  101. MB_SETFOREGROUND |
  102. MB_ICONQUESTION |
  103. MB_YESNO) == IDYES);
  104. }
  105. BOOL PromptRestartNow(HWND hwnd)
  106. {
  107. return (PromptR(
  108. hwnd,
  109. IDS_RESTARTNOW,
  110. MB_SETFOREGROUND |
  111. MB_ICONINFORMATION |
  112. MB_OKCANCEL) == IDOK);
  113. }
  114. /* C E N T E R W I N D O W */
  115. /*-------------------------------------------------------------------------
  116. %%Function: CenterWindow
  117. Center a window over another window.
  118. -------------------------------------------------------------------------*/
  119. VOID CenterWindow(HWND hwndChild, HWND hwndParent)
  120. {
  121. int xNew, yNew;
  122. int cxChild, cyChild;
  123. int cxParent, cyParent;
  124. int cxScreen, cyScreen;
  125. RECT rcChild, rcParent;
  126. HDC hdc;
  127. // Get the Height and Width of the child window
  128. GetWindowRect(hwndChild, &rcChild);
  129. cxChild = rcChild.right - rcChild.left;
  130. cyChild = rcChild.bottom - rcChild.top;
  131. // Get the Height and Width of the parent window
  132. GetWindowRect(hwndParent, &rcParent);
  133. cxParent = rcParent.right - rcParent.left;
  134. cyParent = rcParent.bottom - rcParent.top;
  135. // Get the display limits
  136. hdc = GetDC(hwndChild);
  137. if (hdc == NULL) {
  138. // major problems - move window to 0,0
  139. xNew = yNew = 0;
  140. } else {
  141. cxScreen = GetDeviceCaps(hdc, HORZRES);
  142. cyScreen = GetDeviceCaps(hdc, VERTRES);
  143. ReleaseDC(hwndChild, hdc);
  144. if (hwndParent == hwndNil) {
  145. cxParent = cxScreen;
  146. cyParent = cyScreen;
  147. SetRect(&rcParent, 0, 0, cxScreen, cyScreen);
  148. }
  149. // Calculate new X position, then adjust for screen
  150. xNew = rcParent.left + ((cxParent - cxChild) / 2);
  151. if (xNew < 0) {
  152. xNew = 0;
  153. } else if ((xNew + cxChild) > cxScreen) {
  154. xNew = cxScreen - cxChild;
  155. }
  156. // Calculate new Y position, then adjust for screen
  157. yNew = rcParent.top + ((cyParent - cyChild) / 2);
  158. if (yNew < 0) {
  159. yNew = 0;
  160. } else if ((yNew + cyChild) > cyScreen) {
  161. yNew = cyScreen - cyChild;
  162. }
  163. }
  164. SetWindowPos(hwndChild, NULL, xNew, yNew, 0, 0,
  165. SWP_NOSIZE | SWP_NOZORDER);
  166. }