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.

300 lines
7.2 KiB

  1. /****************************************************************************
  2. Copyright (c) Microsoft Corporation 1997
  3. All rights reserved
  4. ***************************************************************************/
  5. #include "pch.h"
  6. #include "utils.h"
  7. DEFINE_MODULE("RIPREP")
  8. #define SMALL_BUFFER_SIZE 1024
  9. //
  10. // Centers a dialog.
  11. //
  12. void
  13. CenterDialog(
  14. HWND hwndDlg )
  15. {
  16. RECT rc;
  17. RECT rcScreen;
  18. int x, y;
  19. int cxDlg, cyDlg;
  20. int cxScreen;
  21. int cyScreen;
  22. SystemParametersInfo( SPI_GETWORKAREA, 0, &rcScreen, 0 );
  23. cxScreen = rcScreen.right - rcScreen.left;
  24. cyScreen = rcScreen.bottom - rcScreen.top;
  25. GetWindowRect( hwndDlg, &rc );
  26. cxDlg = rc.right - rc.left;
  27. cyDlg = rc.bottom - rc.top;
  28. y = rcScreen.top + ( ( cyScreen - cyDlg ) / 2 );
  29. x = rcScreen.left + ( ( cxScreen - cxDlg ) / 2 );
  30. SetWindowPos( hwndDlg, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE );
  31. }
  32. //
  33. // Eats all mouse and keyboard messages.
  34. //
  35. void
  36. ClearMessageQueue( void )
  37. {
  38. MSG msg;
  39. while ( PeekMessage( (LPMSG)&msg, NULL, WM_KEYFIRST, WM_MOUSELAST,
  40. PM_NOYIELD | PM_REMOVE ) );
  41. }
  42. //
  43. // Create a message box from resource strings.
  44. //
  45. INT
  46. MessageBoxFromStrings(
  47. HWND hParent,
  48. UINT idsCaption,
  49. UINT idsText,
  50. UINT uType )
  51. {
  52. TCHAR szText[ SMALL_BUFFER_SIZE ];
  53. TCHAR szCaption[ SMALL_BUFFER_SIZE ];
  54. DWORD dw;
  55. dw = LoadString( g_hinstance, idsCaption, szCaption, ARRAYSIZE( szCaption ));
  56. Assert( dw );
  57. dw = LoadString( g_hinstance, idsText, szText, ARRAYSIZE( szText ));
  58. Assert( dw );
  59. return MessageBox( hParent, szText, szCaption, uType );
  60. }
  61. //
  62. // Creates a error message box
  63. //
  64. INT
  65. MessageBoxFromError(
  66. HWND hParent,
  67. LPTSTR pszTitle,
  68. DWORD dwErr,
  69. LPTSTR pszAdditionalText,
  70. UINT uType )
  71. {
  72. WCHAR szText[ SMALL_BUFFER_SIZE ];
  73. LPTSTR lpMsgBuf;
  74. LPTSTR lpMsgBuf2;
  75. int retval;
  76. if ( dwErr == ERROR_SUCCESS ) {
  77. AssertMsg( dwErr, "Why was MessageBoxFromError() called when the dwErr == ERROR_SUCCES?" );
  78. return IDOK;
  79. }
  80. if ( !pszTitle ) {
  81. DWORD dw;
  82. dw = LoadString( g_hinstance, IDS_ERROR, szText, ARRAYSIZE( szText ));
  83. Assert( dw );
  84. pszTitle = szText;
  85. }
  86. if (FormatMessage(
  87. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
  88. NULL,
  89. dwErr,
  90. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  91. (LPTSTR) &lpMsgBuf2,
  92. 0,
  93. NULL )) {
  94. //
  95. // If additional text was given, allocate a buffer large enough for both
  96. // strings. If the allocation fails, just show the error text.
  97. //
  98. if ( pszAdditionalText != NULL ) {
  99. DWORD len = (wcslen(lpMsgBuf2) + wcslen(pszAdditionalText) + 1) * sizeof(WCHAR);
  100. lpMsgBuf = (LPTSTR)LocalAlloc( LPTR, len );
  101. if ( lpMsgBuf != NULL ) {
  102. wcscpy( lpMsgBuf, lpMsgBuf2 );
  103. wcscat( lpMsgBuf, pszAdditionalText );
  104. } else {
  105. lpMsgBuf = lpMsgBuf2;
  106. }
  107. } else {
  108. lpMsgBuf = lpMsgBuf2;
  109. }
  110. retval = MessageBox( hParent, lpMsgBuf, pszTitle, uType | MB_TASKMODAL | MB_ICONERROR );
  111. SetFocus( hParent );
  112. if (lpMsgBuf != NULL) {
  113. LocalFree( lpMsgBuf );
  114. }
  115. if ( lpMsgBuf2 != lpMsgBuf ) {
  116. LocalFree( lpMsgBuf2 );
  117. }
  118. return retval;
  119. } else {
  120. Assert(FALSE);
  121. return 0;
  122. }
  123. }
  124. VOID
  125. SetDialogFont(
  126. IN HWND hdlg,
  127. IN UINT ControlId,
  128. IN MyDlgFont WhichFont
  129. )
  130. {
  131. static HFONT BigBoldFont = NULL;
  132. static HFONT BoldFont = NULL;
  133. static HFONT NormalFont = NULL;
  134. HFONT Font;
  135. LOGFONT LogFont;
  136. int FontSize;
  137. HDC hdc;
  138. switch(WhichFont) {
  139. case DlgFontTitle:
  140. if(!BigBoldFont) {
  141. if ( Font =
  142. (HFONT) SendDlgItemMessage( hdlg, ControlId, WM_GETFONT, 0, 0) )
  143. {
  144. if ( GetObject( Font, sizeof(LOGFONT), &LogFont) )
  145. {
  146. DWORD dw;
  147. dw = LoadString( g_hinstance,
  148. IDS_LARGEFONTNAME,
  149. LogFont.lfFaceName,
  150. LF_FACESIZE);
  151. Assert( dw );
  152. // LogFont.lfWeight = 700;
  153. FontSize = 14;
  154. if ( hdc = GetDC(hdlg) )
  155. {
  156. LogFont.lfHeight =
  157. 0 - (GetDeviceCaps(hdc,LOGPIXELSY) * FontSize / 72);
  158. BigBoldFont = CreateFontIndirect(&LogFont);
  159. ReleaseDC(hdlg,hdc);
  160. }
  161. }
  162. }
  163. }
  164. Font = BigBoldFont;
  165. break;
  166. case DlgFontBold:
  167. if ( !BoldFont )
  168. {
  169. if ( Font =
  170. (HFONT) SendDlgItemMessage( hdlg, ControlId, WM_GETFONT, 0, 0 ))
  171. {
  172. if ( GetObject( Font, sizeof(LOGFONT), &LogFont ) )
  173. {
  174. LogFont.lfWeight = FW_BOLD;
  175. if ( hdc = GetDC( hdlg ) )
  176. {
  177. BoldFont = CreateFontIndirect( &LogFont );
  178. ReleaseDC( hdlg, hdc );
  179. }
  180. }
  181. }
  182. }
  183. Font = BoldFont;
  184. break;
  185. default:
  186. //
  187. // Nothing to do here.
  188. //
  189. Font = NULL;
  190. break;
  191. }
  192. if( Font )
  193. {
  194. SendDlgItemMessage( hdlg, ControlId, WM_SETFONT, (WPARAM) Font, 0 );
  195. }
  196. }
  197. //
  198. // Adjusts and draws a bitmap transparently in the RECT prc.
  199. //
  200. void
  201. DrawBitmap(
  202. HANDLE hBitmap,
  203. LPDRAWITEMSTRUCT lpdis,
  204. LPRECT prc )
  205. {
  206. TraceFunc( "DrawBitmap( ... )\n" );
  207. BITMAP bm;
  208. HDC hDCBitmap;
  209. int dy;
  210. if (GetObject( hBitmap, sizeof(bm), &bm ) &&
  211. (hDCBitmap = CreateCompatibleDC( NULL ))) {
  212. SelectObject( hDCBitmap, hBitmap );
  213. // center the image
  214. dy = 4 + prc->bottom - bm.bmHeight;
  215. StretchBlt( lpdis->hDC, prc->left, prc->top + dy, prc->right, prc->bottom,
  216. hDCBitmap, 0, 0, bm.bmWidth, bm.bmHeight, SRCAND );
  217. DeleteDC( hDCBitmap );
  218. }
  219. TraceFuncExit( );
  220. }
  221. //
  222. // Verifies that the user wanted to cancel setup.
  223. //
  224. BOOL
  225. VerifyCancel( HWND hParent )
  226. {
  227. TraceFunc( "VerifyCancel( ... )\n" );
  228. INT iReturn;
  229. BOOL fAbort = FALSE;
  230. iReturn = MessageBoxFromStrings( hParent,
  231. IDS_CANCELCAPTION,
  232. IDS_CANCELTEXT,
  233. MB_YESNO | MB_ICONQUESTION );
  234. if ( iReturn == IDYES ) {
  235. fAbort = TRUE;
  236. }
  237. SetWindowLongPtr( hParent, DWLP_MSGRESULT, ( fAbort ? 0 : -1 ));
  238. RETURN(!fAbort);
  239. }