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.

340 lines
7.3 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1995 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: winproc.c
  6. * Content: DDHELP window proc
  7. * History:
  8. * Date By Reason
  9. * ==== == ======
  10. * 21-sep-95 craige initial implementation
  11. *
  12. ***************************************************************************/
  13. #include "pch.c"
  14. //#define WIN32_LEAN_AND_MEAN
  15. //#include <windows.h>
  16. #include <mmsystem.h>
  17. #include <mmreg.h>
  18. #include "dpf.h"
  19. #define SCROLLTIME 25
  20. #define WIN_WIDTH 320
  21. #define WIN_HEIGHT 200
  22. #define MAX_FONTS 10
  23. #pragma pack( 1 )
  24. typedef struct
  25. {
  26. LPSTR szStr;
  27. DWORD dwFont;
  28. COLORREF crForeground;
  29. // COLORREF crBackground;
  30. } LISTDATA, *LPLISTDATA;
  31. extern LPLISTDATA ListData[];
  32. extern HANDLE hInstApp;
  33. extern VOID (*g_pfnOnDisplayChange)(void);
  34. int iCurrItem;
  35. DWORD dwPixelsLeft;
  36. DWORD dwPixelHeight;
  37. DWORD dwPixelWidth;
  38. HFONT hFont[MAX_FONTS];
  39. /*
  40. * getStr
  41. */
  42. void getStr( int index, char *result, int *plen )
  43. {
  44. int len;
  45. LPLISTDATA pnd;
  46. int i;
  47. pnd = ListData[ index ];
  48. len = pnd->szStr[0];
  49. for( i=0;i<len;i++ )
  50. {
  51. *result++ = pnd->szStr[i+1] ^ 0x42;
  52. }
  53. *result = 0;
  54. *plen = len;
  55. } /* getStr */
  56. /*
  57. * getTextDim
  58. */
  59. void getTextDim( HDC hdc, int index, DWORD *pwidth, DWORD *pheight )
  60. {
  61. LPLISTDATA pnd;
  62. SIZE size;
  63. HFONT oldfont;
  64. char name[256];
  65. int len;
  66. pnd = ListData[ index ];
  67. if( HIWORD( (DWORD) pnd->szStr ) == 0 )
  68. {
  69. *pwidth = 0;
  70. *pheight = (DWORD) pnd->szStr;
  71. return;
  72. }
  73. oldfont = SelectObject( hdc, hFont[ ListData[ index ]->dwFont ] );
  74. getStr( index, name, &len );
  75. GetTextExtentPoint32( hdc, name, len, &size );
  76. *pwidth = size.cx;
  77. *pheight = size.cy+1;
  78. SelectObject( hdc, oldfont );
  79. } /* getTextDim */
  80. /*
  81. * MainWndProc2
  82. */
  83. long __stdcall MainWndProc2( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
  84. {
  85. PAINTSTRUCT ps;
  86. HDC hdc;
  87. RECT r;
  88. RECT cr;
  89. HFONT oldfont;
  90. int len;
  91. char name[256];
  92. static BOOL bActive;
  93. switch( message )
  94. {
  95. case WM_CREATE:
  96. SetTimer( hWnd, 1, SCROLLTIME, NULL );
  97. iCurrItem = -1;
  98. dwPixelsLeft = 0;
  99. break;
  100. case WM_TIMER:
  101. if( !bActive )
  102. {
  103. break;
  104. }
  105. hdc = GetDC( hWnd );
  106. GetClientRect( hWnd, &cr );
  107. /*
  108. * are we on a new block yet?
  109. */
  110. if( dwPixelsLeft == 0 )
  111. {
  112. iCurrItem++;
  113. if( ListData[ iCurrItem ] == NULL )
  114. {
  115. iCurrItem = 0;
  116. }
  117. getTextDim( hdc, iCurrItem, &dwPixelWidth, &dwPixelHeight );
  118. dwPixelsLeft = dwPixelHeight;
  119. }
  120. ScrollWindowEx( hWnd, 0, -1, NULL, NULL, NULL, NULL, 0 );
  121. if( HIWORD( (DWORD) ListData[iCurrItem]->szStr ) != 0 )
  122. {
  123. oldfont = SelectObject( hdc, hFont[ ListData[ iCurrItem ]->dwFont ] );
  124. SetTextColor( hdc, ListData[ iCurrItem ]->crForeground );
  125. // SetBkColor( hdc, ListData[ iCurrItem ]->crBackground );
  126. SetBkColor( hdc, RGB( 255, 255, 255 ) );
  127. getStr( iCurrItem, name, &len );
  128. r.left = 0;
  129. r.right = cr.right;
  130. r.top = cr.bottom-2;
  131. r.bottom = r.top+1;
  132. ExtTextOut( hdc,
  133. (cr.right-dwPixelWidth)/2,
  134. cr.bottom-(dwPixelHeight-dwPixelsLeft)-1,
  135. ETO_CLIPPED | ETO_OPAQUE,
  136. &r,
  137. name,
  138. len,
  139. NULL );
  140. SelectObject( hdc, oldfont );
  141. }
  142. ReleaseDC( hWnd, hdc );
  143. dwPixelsLeft--;
  144. break;
  145. case WM_PAINT:
  146. hdc = BeginPaint( hWnd, &ps );
  147. EndPaint( hWnd, &ps );
  148. hdc = GetDC( hWnd );
  149. GetClientRect( hWnd, &cr );
  150. FillRect( hdc, &cr, GetStockObject(WHITE_BRUSH) );
  151. ReleaseDC( hWnd, hdc );
  152. iCurrItem = -1;
  153. dwPixelsLeft = 0;
  154. return 1;
  155. case WM_ACTIVATE:
  156. bActive = wParam;
  157. break;
  158. case WM_DESTROY:
  159. KillTimer( hWnd, 1 );
  160. PostQuitMessage( 0 );
  161. break;
  162. case WM_DISPLAYCHANGE:
  163. DPF( 4, "WM_DISPLAYCHANGE" );
  164. if( g_pfnOnDisplayChange )
  165. (*g_pfnOnDisplayChange)();
  166. break;
  167. }
  168. return DefWindowProc(hWnd, message, wParam, lParam);
  169. } /* MainWndProc2 */
  170. /*
  171. * makeFonts
  172. */
  173. static void makeFonts( void )
  174. {
  175. hFont[0] = CreateFont(
  176. 24,
  177. 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
  178. ANSI_CHARSET,
  179. OUT_DEFAULT_PRECIS,
  180. CLIP_DEFAULT_PRECIS,
  181. NONANTIALIASED_QUALITY, // DEFAULT_QUALITY,
  182. VARIABLE_PITCH,
  183. "Arial" );
  184. hFont[1] = CreateFont(
  185. 24,
  186. 0, 0, 0, FW_NORMAL, TRUE, FALSE, FALSE,
  187. ANSI_CHARSET,
  188. OUT_DEFAULT_PRECIS,
  189. CLIP_DEFAULT_PRECIS,
  190. NONANTIALIASED_QUALITY, // DEFAULT_QUALITY,
  191. VARIABLE_PITCH,
  192. "Arial" );
  193. hFont[2] = CreateFont(
  194. 48,
  195. 0, 0, 0, FW_BOLD| FW_NORMAL, TRUE, FALSE, FALSE,
  196. ANSI_CHARSET,
  197. OUT_DEFAULT_PRECIS,
  198. CLIP_DEFAULT_PRECIS,
  199. NONANTIALIASED_QUALITY, // DEFAULT_QUALITY,
  200. VARIABLE_PITCH,
  201. "Arial" );
  202. hFont[3] = CreateFont(
  203. 18,
  204. 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
  205. ANSI_CHARSET,
  206. OUT_DEFAULT_PRECIS,
  207. CLIP_DEFAULT_PRECIS,
  208. NONANTIALIASED_QUALITY, // DEFAULT_QUALITY,
  209. VARIABLE_PITCH,
  210. "Arial" );
  211. hFont[4] = CreateFont(
  212. 36,
  213. 0, 0, 0, FW_NORMAL, TRUE, FALSE, FALSE,
  214. ANSI_CHARSET,
  215. OUT_DEFAULT_PRECIS,
  216. CLIP_DEFAULT_PRECIS,
  217. NONANTIALIASED_QUALITY, // DEFAULT_QUALITY,
  218. VARIABLE_PITCH,
  219. "Arial" );
  220. hFont[5] = CreateFont(
  221. 36,
  222. 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
  223. ANSI_CHARSET,
  224. OUT_DEFAULT_PRECIS,
  225. CLIP_DEFAULT_PRECIS,
  226. NONANTIALIASED_QUALITY, // DEFAULT_QUALITY,
  227. VARIABLE_PITCH,
  228. "Times New Roman" );
  229. } /* makeFonts */
  230. BOOL bIsActive;
  231. /*
  232. * HelperThreadProc
  233. */
  234. void HelperThreadProc( LPVOID data )
  235. {
  236. static char szClassName[] = "DDHelpWndClass2";
  237. static BOOL bInit;
  238. int i;
  239. WNDCLASS cls;
  240. MSG msg;
  241. HWND hwnd;
  242. int x;
  243. int y;
  244. /*
  245. * build class and create window
  246. */
  247. cls.lpszClassName = szClassName;
  248. cls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  249. cls.hInstance = hInstApp;
  250. cls.hIcon = NULL;
  251. cls.hCursor = NULL;
  252. cls.lpszMenuName = NULL;
  253. cls.style = 0;
  254. cls.lpfnWndProc = MainWndProc2;
  255. cls.cbWndExtra = 0;
  256. cls.cbClsExtra = 0;
  257. if( !bInit )
  258. {
  259. if( !RegisterClass( &cls ) )
  260. {
  261. DPF( 1, "RegisterClass FAILED!" );
  262. ExitThread( 0 );
  263. }
  264. bInit = TRUE;
  265. }
  266. x = GetSystemMetrics( SM_CXSCREEN );
  267. y = GetSystemMetrics( SM_CYSCREEN );
  268. hwnd = CreateWindow( szClassName,
  269. "DirectX(tm) For Microsoft\256 Windows\256",
  270. WS_OVERLAPPEDWINDOW,
  271. (x-WIN_WIDTH)/2, (y-WIN_HEIGHT)/2,
  272. WIN_WIDTH, WIN_HEIGHT,
  273. NULL, NULL, hInstApp, NULL);
  274. ShowWindow( hwnd, SW_NORMAL );
  275. UpdateWindow( hwnd );
  276. makeFonts();
  277. if( hwnd == NULL )
  278. {
  279. ExitThread( 0 );
  280. }
  281. /*
  282. * pump the messages
  283. */
  284. bIsActive = TRUE;
  285. while( GetMessage( &msg, NULL, 0, 0 ) )
  286. {
  287. TranslateMessage( &msg );
  288. DispatchMessage( &msg );
  289. }
  290. for( i=0;i<MAX_FONTS;i++ )
  291. {
  292. if( hFont[i] != NULL )
  293. {
  294. DeleteObject( hFont[i] );
  295. }
  296. }
  297. bIsActive = FALSE;
  298. ExitThread( 1 );
  299. } /* HelperThreadProc */