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.

2014 lines
55 KiB

  1. /*
  2. ** CUTILS.C
  3. **
  4. ** Common utilities for common controls
  5. **
  6. */
  7. #include "ctlspriv.h"
  8. #include "advpub.h" // For REGINSTALL
  9. #include <ntverp.h>
  10. #include "ccver.h" // App compat version hacks
  11. #ifndef SSW_EX_IGNORESETTINGS
  12. #define SSW_EX_IGNORESETTINGS 0x00040000 // ignore system settings to turn on/off smooth scroll
  13. #endif
  14. //
  15. // Globals - REVIEW_32
  16. //
  17. BOOL g_fAnimate;
  18. BOOL g_fSmoothScroll;
  19. int g_cxEdge;
  20. int g_cyEdge;
  21. int g_cxBorder;
  22. int g_cyBorder;
  23. int g_cxScreen;
  24. int g_cyScreen;
  25. int g_cxFrame;
  26. int g_cyFrame;
  27. int g_cxVScroll;
  28. int g_cyHScroll;
  29. int g_cxIcon, g_cyIcon;
  30. int g_cxSmIcon, g_cySmIcon;
  31. int g_cxIconSpacing, g_cyIconSpacing;
  32. int g_cxIconMargin, g_cyIconMargin;
  33. int g_cyLabelSpace;
  34. int g_cxLabelMargin;
  35. int g_cxDoubleClk;
  36. int g_cyDoubleClk;
  37. int g_cxScrollbar;
  38. int g_cyScrollbar;
  39. int g_fDragFullWindows;
  40. COLORREF g_clrWindow;
  41. COLORREF g_clrWindowText;
  42. COLORREF g_clrWindowFrame;
  43. COLORREF g_clrGrayText;
  44. COLORREF g_clrBtnText;
  45. COLORREF g_clrBtnFace;
  46. COLORREF g_clrBtnShadow;
  47. COLORREF g_clrBtnHighlight;
  48. COLORREF g_clrHighlight;
  49. COLORREF g_clrHighlightText;
  50. COLORREF g_clrInfoText;
  51. COLORREF g_clrInfoBk;
  52. COLORREF g_clr3DDkShadow;
  53. COLORREF g_clr3DLight;
  54. HBRUSH g_hbrGrayText;
  55. HBRUSH g_hbrWindow;
  56. HBRUSH g_hbrWindowText;
  57. HBRUSH g_hbrWindowFrame;
  58. HBRUSH g_hbrBtnFace;
  59. HBRUSH g_hbrBtnHighlight;
  60. HBRUSH g_hbrBtnShadow;
  61. HBRUSH g_hbrHighlight;
  62. DWORD g_dwHoverSelectTimeout;
  63. HFONT g_hfontSystem;
  64. #define CCS_ALIGN (CCS_TOP | CCS_NOMOVEY | CCS_BOTTOM)
  65. int TrueMapWindowPoints(HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT cPoints);
  66. // Note that the default alignment is CCS_BOTTOM
  67. //
  68. void FAR PASCAL NewSize(HWND hWnd, int nThickness, LONG style, int left, int top, int width, int height)
  69. {
  70. // Resize the window unless the user said not to
  71. //
  72. if (!(style & CCS_NORESIZE))
  73. {
  74. RECT rc, rcWindow, rcBorder;
  75. // Remember size that was passed in and don't bother calling SetWindowPos if we're not
  76. // actually going to change the window size
  77. int leftSave = left;
  78. int topSave = top;
  79. int widthSave = width;
  80. int heightSave = height;
  81. // Calculate the borders around the client area of the status bar
  82. GetWindowRect(hWnd, &rcWindow);
  83. rcWindow.right -= rcWindow.left; // -> dx
  84. rcWindow.bottom -= rcWindow.top; // -> dy
  85. GetClientRect(hWnd, &rc);
  86. //
  87. // If the window is mirrored, mirror the anchor point
  88. // since it will be passed to SWP which accepts screen
  89. // ccordinates. This mainly fixes the display of status bar
  90. // and others. [samera]
  91. //
  92. if (IS_WINDOW_RTL_MIRRORED(hWnd))
  93. {
  94. TrueMapWindowPoints(hWnd, NULL, (LPPOINT)&rc.left, 1);
  95. }
  96. else
  97. {
  98. ClientToScreen(hWnd, (LPPOINT)&rc);
  99. }
  100. rcBorder.left = rc.left - rcWindow.left;
  101. rcBorder.top = rc.top - rcWindow.top ;
  102. rcBorder.right = rcWindow.right - rc.right - rcBorder.left;
  103. rcBorder.bottom = rcWindow.bottom - rc.bottom - rcBorder.top ;
  104. if (style & CCS_VERT)
  105. nThickness += rcBorder.left + rcBorder.right;
  106. else
  107. nThickness += rcBorder.top + rcBorder.bottom;
  108. // Check whether to align to the parent window
  109. //
  110. if (style & CCS_NOPARENTALIGN)
  111. {
  112. // Check out whether this bar is top aligned or bottom aligned
  113. //
  114. switch (style & CCS_ALIGN)
  115. {
  116. case CCS_TOP:
  117. case CCS_NOMOVEY:
  118. break;
  119. default: // CCS_BOTTOM
  120. if(style & CCS_VERT)
  121. left = left + width - nThickness;
  122. else
  123. top = top + height - nThickness;
  124. }
  125. }
  126. else
  127. {
  128. // It is assumed there is a parent by default
  129. //
  130. GetClientRect(GetParent(hWnd), &rc);
  131. // Don't forget to account for the borders
  132. //
  133. if(style & CCS_VERT)
  134. {
  135. top = -rcBorder.right;
  136. height = rc.bottom + rcBorder.top + rcBorder.bottom;
  137. }
  138. else
  139. {
  140. left = -rcBorder.left;
  141. width = rc.right + rcBorder.left + rcBorder.right;
  142. }
  143. if ((style & CCS_ALIGN) == CCS_TOP)
  144. {
  145. if(style & CCS_VERT)
  146. left = -rcBorder.left;
  147. else
  148. top = -rcBorder.top;
  149. }
  150. else if ((style & CCS_ALIGN) != CCS_NOMOVEY)
  151. {
  152. if (style & CCS_VERT)
  153. left = rc.right - nThickness + rcBorder.right;
  154. else
  155. top = rc.bottom - nThickness + rcBorder.bottom;
  156. }
  157. }
  158. if (!(style & CCS_NOMOVEY) && !(style & CCS_NODIVIDER))
  159. {
  160. if (style & CCS_VERT)
  161. left += g_cxEdge;
  162. else
  163. top += g_cyEdge; // double pixel edge thing
  164. }
  165. if(style & CCS_VERT)
  166. width = nThickness;
  167. else
  168. height = nThickness;
  169. SetWindowPos(hWnd, NULL, left, top, width, height, SWP_NOZORDER);
  170. }
  171. }
  172. BOOL FAR PASCAL MGetTextExtent(HDC hdc, LPCTSTR lpstr, int cnt, int FAR * pcx, int FAR * pcy)
  173. {
  174. BOOL fSuccess;
  175. SIZE size = {0,0};
  176. if (cnt == -1)
  177. cnt = lstrlen(lpstr);
  178. fSuccess=GetTextExtentPoint(hdc, lpstr, cnt, &size);
  179. if (pcx)
  180. *pcx=size.cx;
  181. if (pcy)
  182. *pcy=size.cy;
  183. return fSuccess;
  184. }
  185. // these are the default colors used to map the dib colors
  186. // to the current system colors
  187. #define RGB_BUTTONTEXT (RGB(000,000,000)) // black
  188. #define RGB_BUTTONSHADOW (RGB(128,128,128)) // dark grey
  189. #define RGB_BUTTONFACE (RGB(192,192,192)) // bright grey
  190. #define RGB_BUTTONHILIGHT (RGB(255,255,255)) // white
  191. #define RGB_BACKGROUNDSEL (RGB(000,000,255)) // blue
  192. #define RGB_BACKGROUND (RGB(255,000,255)) // magenta
  193. #define FlipColor(rgb) (RGB(GetBValue(rgb), GetGValue(rgb), GetRValue(rgb)))
  194. #define MAX_COLOR_MAPS 16
  195. // This is almost the same as LoadImage(..., LR_MAP3DCOLORS) except that
  196. //
  197. // - The app can specify a custom color map,
  198. // - The default color map maps colors beyond the 3D colors,
  199. //
  200. HBITMAP WINAPI CreateMappedBitmap(HINSTANCE hInstance, INT_PTR idBitmap,
  201. UINT wFlags, LPCOLORMAP lpColorMap, int iNumMaps)
  202. {
  203. HDC hdc, hdcMem = NULL;
  204. HANDLE h;
  205. COLOR_STRUCT FAR *p;
  206. COLOR_STRUCT FAR *lpTable;
  207. LPBYTE lpBits;
  208. HANDLE hRes;
  209. LPBITMAPINFOHEADER lpBitmapInfo;
  210. HBITMAP hbm = NULL, hbmOld;
  211. int numcolors, i;
  212. int wid, hgt;
  213. LPBITMAPINFOHEADER lpMungeInfo;
  214. int offBits;
  215. COLOR_STRUCT rgbMaskTable[16];
  216. COLOR_STRUCT rgbBackground;
  217. static const COLORMAP SysColorMap[] = {
  218. {RGB_BUTTONTEXT, COLOR_BTNTEXT}, // black
  219. {RGB_BUTTONSHADOW, COLOR_BTNSHADOW}, // dark grey
  220. {RGB_BUTTONFACE, COLOR_BTNFACE}, // bright grey
  221. {RGB_BUTTONHILIGHT, COLOR_BTNHIGHLIGHT},// white
  222. {RGB_BACKGROUNDSEL, COLOR_HIGHLIGHT}, // blue
  223. {RGB_BACKGROUND, COLOR_WINDOW} // magenta
  224. };
  225. #define NUM_DEFAULT_MAPS (sizeof(SysColorMap)/sizeof(COLORMAP))
  226. COLORMAP DefaultColorMap[NUM_DEFAULT_MAPS];
  227. COLORMAP DIBColorMap[MAX_COLOR_MAPS];
  228. h = FindResource(hInstance, MAKEINTRESOURCE(idBitmap), RT_BITMAP);
  229. if (!h)
  230. return NULL;
  231. hRes = LoadResource(hInstance, h);
  232. /* Lock the bitmap and get a pointer to the color table. */
  233. lpBitmapInfo = (LPBITMAPINFOHEADER)LockResource(hRes);
  234. if (!lpBitmapInfo)
  235. return NULL;
  236. // munge on a copy of the color table instead of the original
  237. // (prevent possibility of "reload" with messed table
  238. offBits = (int)lpBitmapInfo->biSize + ((1 << (lpBitmapInfo->biBitCount)) * sizeof(RGBQUAD));
  239. lpMungeInfo = GlobalAlloc(GPTR, offBits);
  240. if (!lpMungeInfo)
  241. goto Exit1;
  242. hmemcpy(lpMungeInfo, lpBitmapInfo, offBits);
  243. /* Get system colors for the default color map */
  244. if (!lpColorMap) {
  245. lpColorMap = DefaultColorMap;
  246. iNumMaps = NUM_DEFAULT_MAPS;
  247. for (i=0; i < iNumMaps; i++) {
  248. lpColorMap[i].from = SysColorMap[i].from;
  249. lpColorMap[i].to = GetSysColor((int)SysColorMap[i].to);
  250. }
  251. }
  252. /* Transform RGB color map to a BGR DIB format color map */
  253. if (iNumMaps > MAX_COLOR_MAPS)
  254. iNumMaps = MAX_COLOR_MAPS;
  255. /*
  256. 1) their definition of COLORMAP is based on COLORREFs but a
  257. DIB color map is RGBQUAD
  258. 2) FlipColor as per definition above does not flip at all
  259. since it goes from COLORREF to COLORREF
  260. so we are better doing nothing, this the(Jose)
  261. */
  262. for (i=0; i < iNumMaps; i++) {
  263. DIBColorMap[i].to = FlipColor(lpColorMap[i].to);
  264. DIBColorMap[i].from = FlipColor(lpColorMap[i].from);
  265. }
  266. // use the table in the munging buffer
  267. lpTable = p = (COLOR_STRUCT FAR *)(((LPBYTE)lpMungeInfo) + lpMungeInfo->biSize);
  268. /* Replace button-face and button-shadow colors with the current values
  269. */
  270. numcolors = 16;
  271. // if we are creating a mask, build a color table with white
  272. // marking the transparent section (where it used to be background)
  273. // and black marking the opaque section (everything else). this
  274. // table is used below to build the mask using the original DIB bits.
  275. if (wFlags & CMB_MASKED) {
  276. rgbBackground = FlipColor(RGB_BACKGROUND);
  277. for (i = 0; i < 16; i++) {
  278. if (p[i] == rgbBackground)
  279. rgbMaskTable[i] = 0xFFFFFF; // transparent section
  280. else
  281. rgbMaskTable[i] = 0x000000; // opaque section
  282. }
  283. }
  284. while (numcolors-- > 0) {
  285. for (i = 0; i < iNumMaps; i++) {
  286. if ((*p & 0x00FFFFFF) == DIBColorMap[i].from) {
  287. *p = DIBColorMap[i].to;
  288. break;
  289. }
  290. }
  291. p++;
  292. }
  293. /* First skip over the header structure */
  294. lpBits = (LPBYTE)(lpBitmapInfo) + offBits;
  295. /* Create a color bitmap compatible with the display device */
  296. i = wid = (int)lpBitmapInfo->biWidth;
  297. hgt = (int)lpBitmapInfo->biHeight;
  298. hdc = GetDC(NULL);
  299. hdcMem = CreateCompatibleDC(hdc);
  300. if (!hdcMem)
  301. goto cleanup;
  302. // if creating a mask, the bitmap needs to be twice as wide.
  303. if (wFlags & CMB_MASKED)
  304. i = wid*2;
  305. // discardable bitmaps aren't much use anymore...
  306. //
  307. // if (wFlags & CMB_DISCARDABLE)
  308. // hbm = CreateDiscardableBitmap(hdc, i, hgt);
  309. // else
  310. if (wFlags & CMB_DIBSECTION)
  311. {
  312. // Have to edit the header slightly, since CreateDIBSection supports
  313. // only BI_RGB and BI_BITFIELDS. This is the same whackery that USER
  314. // does in LoadImage.
  315. LPVOID pvDummy;
  316. DWORD dwCompression = lpMungeInfo->biCompression;
  317. if (dwCompression != BI_BITFIELDS)
  318. lpMungeInfo->biCompression = BI_RGB;
  319. hbm = CreateDIBSection(hdc, (LPBITMAPINFO)lpMungeInfo, DIB_RGB_COLORS,
  320. &pvDummy, NULL, 0);
  321. lpMungeInfo->biCompression = dwCompression;
  322. }
  323. // If CMB_DIBSECTION failed, then create a DDB instead. Not perfect,
  324. // but better than creating nothing. We also get here if the caller
  325. // didn't ask for a DIB section.
  326. if (hbm == NULL)
  327. hbm = CreateCompatibleBitmap(hdc, i, hgt);
  328. if (hbm) {
  329. hbmOld = SelectObject(hdcMem, hbm);
  330. // set the main image
  331. StretchDIBits(hdcMem, 0, 0, wid, hgt, 0, 0, wid, hgt, lpBits,
  332. (LPBITMAPINFO)lpMungeInfo, DIB_RGB_COLORS, SRCCOPY);
  333. // if building a mask, replace the DIB's color table with the
  334. // mask's black/white table and set the bits. in order to
  335. // complete the masked effect, the actual image needs to be
  336. // modified so that it has the color black in all sections
  337. // that are to be transparent.
  338. if (wFlags & CMB_MASKED) {
  339. hmemcpy(lpTable, (DWORD FAR *)rgbMaskTable, 16 * sizeof(RGBQUAD));
  340. StretchDIBits(hdcMem, wid, 0, wid, hgt, 0, 0, wid, hgt, lpBits,
  341. (LPBITMAPINFO)lpMungeInfo, DIB_RGB_COLORS, SRCCOPY);
  342. BitBlt(hdcMem, 0, 0, wid, hgt, hdcMem, wid, 0, 0x00220326); // DSna
  343. }
  344. SelectObject(hdcMem, hbmOld);
  345. }
  346. cleanup:
  347. if (hdcMem)
  348. DeleteObject(hdcMem);
  349. ReleaseDC(NULL, hdc);
  350. GlobalFree(lpMungeInfo);
  351. Exit1:
  352. UnlockResource(hRes);
  353. FreeResource(hRes);
  354. return hbm;
  355. }
  356. // moved from shelldll\dragdrop.c
  357. // should caller pass in message that indicates termination
  358. // (WM_LBUTTONUP, WM_RBUTTONUP)?
  359. //
  360. // in:
  361. // hwnd to do check on
  362. // x, y in client coordinates
  363. //
  364. // returns:
  365. // TRUE the user began to drag (moved mouse outside double click rect)
  366. // FALSE mouse came up inside click rect
  367. //
  368. // BUGBUG, should support VK_ESCAPE to cancel
  369. BOOL PASCAL CheckForDragBegin(HWND hwnd, int x, int y)
  370. {
  371. RECT rc;
  372. int dxClickRect = GetSystemMetrics(SM_CXDRAG);
  373. int dyClickRect = GetSystemMetrics(SM_CYDRAG);
  374. if (dxClickRect < 4)
  375. {
  376. dxClickRect = dyClickRect = 4;
  377. }
  378. // See if the user moves a certain number of pixels in any direction
  379. SetRect(&rc, x - dxClickRect, y - dyClickRect, x + dxClickRect, y + dyClickRect);
  380. MapWindowRect(hwnd, HWND_DESKTOP, &rc); // client -> screen
  381. //
  382. // SUBTLE! We use PeekMessage+WaitMessage instead of GetMessage,
  383. // because WaitMessage will return when there is an incoming
  384. // SendMessage, whereas GetMessage does not. This is important,
  385. // because the incoming message might've been WM_CAPTURECHANGED.
  386. //
  387. SetCapture(hwnd);
  388. do {
  389. MSG32 msg32;
  390. if (PeekMessage32(&msg32, NULL, 0, 0, PM_REMOVE, TRUE))
  391. {
  392. // See if the application wants to process the message...
  393. if (CallMsgFilter32(&msg32, MSGF_COMMCTRL_BEGINDRAG, TRUE) != 0)
  394. continue;
  395. switch (msg32.message) {
  396. case WM_LBUTTONUP:
  397. case WM_RBUTTONUP:
  398. case WM_LBUTTONDOWN:
  399. case WM_RBUTTONDOWN:
  400. ReleaseCapture();
  401. return FALSE;
  402. case WM_MOUSEMOVE:
  403. if (IsWindow(hwnd) && !PtInRect(&rc, msg32.pt)) {
  404. ReleaseCapture();
  405. return TRUE;
  406. }
  407. break;
  408. default:
  409. TranslateMessage32(&msg32, TRUE);
  410. DispatchMessage32(&msg32, TRUE);
  411. break;
  412. }
  413. }
  414. else WaitMessage();
  415. // WM_CANCELMODE messages will unset the capture, in that
  416. // case I want to exit this loop
  417. } while (IsWindow(hwnd) && GetCapture() == hwnd);
  418. return FALSE;
  419. }
  420. /* Regular StrToInt; stops at first non-digit. */
  421. int WINAPI StrToInt(LPCTSTR lpSrc) // atoi()
  422. {
  423. #define ISDIGIT(c) ((c) >= TEXT('0') && (c) <= TEXT('9'))
  424. int n = 0;
  425. BOOL bNeg = FALSE;
  426. if (*lpSrc == TEXT('-')) {
  427. bNeg = TRUE;
  428. lpSrc++;
  429. }
  430. while (ISDIGIT(*lpSrc)) {
  431. n *= 10;
  432. n += *lpSrc - TEXT('0');
  433. lpSrc++;
  434. }
  435. return bNeg ? -n : n;
  436. }
  437. //
  438. // Wrappers for StrToInt
  439. //
  440. int WINAPI StrToIntA(LPCSTR lpSrc) // atoi()
  441. {
  442. LPWSTR lpString;
  443. INT iResult;
  444. lpString = ProduceWFromA (CP_ACP, lpSrc);
  445. if (!lpString) {
  446. return 0;
  447. }
  448. iResult = StrToIntW(lpString);
  449. FreeProducedString (lpString);
  450. return iResult;
  451. }
  452. //
  453. // From zmouse.h in the Magellan SDK
  454. //
  455. #define MSH_MOUSEWHEEL TEXT("MSWHEEL_ROLLMSG")
  456. // Class name for Magellan/Z MSWHEEL window
  457. // use FindWindow to get hwnd to MSWHEEL
  458. #define MOUSEZ_CLASSNAME TEXT("MouseZ") // wheel window class
  459. #define MOUSEZ_TITLE TEXT("Magellan MSWHEEL") // wheel window title
  460. #define MSH_WHEELMODULE_CLASS (MOUSEZ_CLASSNAME)
  461. #define MSH_WHEELMODULE_TITLE (MOUSEZ_TITLE)
  462. #define MSH_SCROLL_LINES TEXT("MSH_SCROLL_LINES_MSG")
  463. #define DI_GETDRAGIMAGE TEXT("ShellGetDragImage") // Copied from Shlobj.w
  464. UINT g_msgMSWheel;
  465. UINT g_ucScrollLines = 3; /* default */
  466. int gcWheelDelta;
  467. UINT g_uDragImages;
  468. void FAR PASCAL InitGlobalMetrics(WPARAM wParam)
  469. {
  470. static BOOL fInitMouseWheel;
  471. static HWND hwndMSWheel;
  472. static UINT msgMSWheelGetScrollLines;
  473. if (!fInitMouseWheel)
  474. {
  475. fInitMouseWheel = TRUE;
  476. if (g_bRunOnNT || g_bRunOnMemphis)
  477. g_msgMSWheel = WM_MOUSEWHEEL;
  478. else
  479. {
  480. g_msgMSWheel = RegisterWindowMessage(MSH_MOUSEWHEEL);
  481. msgMSWheelGetScrollLines = RegisterWindowMessage(MSH_SCROLL_LINES);
  482. hwndMSWheel = FindWindow(MSH_WHEELMODULE_CLASS, MSH_WHEELMODULE_TITLE);
  483. }
  484. }
  485. g_uDragImages = RegisterWindowMessage(DI_GETDRAGIMAGE);
  486. if (g_bRunOnNT || g_bRunOnMemphis)
  487. {
  488. SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &g_ucScrollLines, 0);
  489. }
  490. else if (hwndMSWheel && msgMSWheelGetScrollLines)
  491. {
  492. g_ucScrollLines =
  493. (UINT)SendMessage(hwndMSWheel, msgMSWheelGetScrollLines, 0, 0);
  494. }
  495. // bug fix HACK: these are NOT members of USER's NONCLIENTMETRICS struct
  496. g_cxIcon = GetSystemMetrics(SM_CXICON);
  497. g_cyIcon = GetSystemMetrics(SM_CYICON);
  498. g_cxSmIcon = GetSystemMetrics(SM_CXSMICON);
  499. g_cySmIcon = GetSystemMetrics(SM_CYSMICON);
  500. g_cxIconSpacing = GetSystemMetrics( SM_CXICONSPACING );
  501. g_cyIconSpacing = GetSystemMetrics( SM_CYICONSPACING );
  502. // Full window drag stays off if running remotely
  503. if (!g_bRemoteSession &&
  504. (wParam == 0 || wParam == SPI_SETDRAGFULLWINDOWS)) {
  505. SystemParametersInfo(SPI_GETDRAGFULLWINDOWS, sizeof(g_fDragFullWindows), &g_fDragFullWindows, 0);
  506. }
  507. // Smooth scrolling stays off if running remotely
  508. if (!g_bRemoteSession) {
  509. HKEY hkey;
  510. g_fSmoothScroll = TRUE;
  511. if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop"), 0, KEY_READ, &hkey) == ERROR_SUCCESS) {
  512. DWORD dwSize = sizeof(g_fSmoothScroll);
  513. RegQueryValueEx(hkey, TEXT("SmoothScroll"), 0, NULL, (LPBYTE)&g_fSmoothScroll, &dwSize);
  514. RegCloseKey(hkey);
  515. }
  516. }
  517. if (g_bRemoteSession)
  518. {
  519. // Nobody should've turned these on
  520. ASSERT(g_fDragFullWindows == FALSE);
  521. ASSERT(g_fSmoothScroll == FALSE);
  522. }
  523. // BUGBUG: some of these are also not members of NONCLIENTMETRICS
  524. if ((wParam == 0) || (wParam == SPI_SETNONCLIENTMETRICS))
  525. {
  526. NONCLIENTMETRICS ncm;
  527. // REVIEW, make sure all these vars are used somewhere.
  528. g_cxEdge = GetSystemMetrics(SM_CXEDGE);
  529. g_cyEdge = GetSystemMetrics(SM_CYEDGE);
  530. g_cxBorder = GetSystemMetrics(SM_CXBORDER);
  531. g_cyBorder = GetSystemMetrics(SM_CYBORDER);
  532. g_cxScreen = GetSystemMetrics(SM_CXSCREEN);
  533. g_cyScreen = GetSystemMetrics(SM_CYSCREEN);
  534. g_cxFrame = GetSystemMetrics(SM_CXFRAME);
  535. g_cyFrame = GetSystemMetrics(SM_CYFRAME);
  536. ncm.cbSize = sizeof(ncm);
  537. SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0);
  538. g_cxVScroll = g_cxScrollbar = (int)ncm.iScrollWidth;
  539. g_cyHScroll = g_cyScrollbar = (int)ncm.iScrollHeight;
  540. // this is true for 4.0 modules only
  541. // for 3.x modules user lies and adds one to these values
  542. // ASSERT(g_cxVScroll == GetSystemMetrics(SM_CXVSCROLL));
  543. // ASSERT(g_cyHScroll == GetSystemMetrics(SM_CYHSCROLL));
  544. g_cxIconMargin = g_cxBorder * 8;
  545. g_cyIconMargin = g_cyEdge;
  546. g_cyLabelSpace = g_cyIconMargin + (g_cyEdge);
  547. g_cxLabelMargin = g_cxEdge;
  548. g_cxDoubleClk = GetSystemMetrics(SM_CXDOUBLECLK);
  549. g_cyDoubleClk = GetSystemMetrics(SM_CYDOUBLECLK);
  550. }
  551. //NT 4.0 has this SPI_GETMOUSEHOVERTIME
  552. SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &g_dwHoverSelectTimeout, 0);
  553. }
  554. void FAR PASCAL InitGlobalColors()
  555. {
  556. g_clrWindow = GetSysColor(COLOR_WINDOW);
  557. g_clrWindowText = GetSysColor(COLOR_WINDOWTEXT);
  558. g_clrWindowFrame = GetSysColor(COLOR_WINDOWFRAME);
  559. g_clrGrayText = GetSysColor(COLOR_GRAYTEXT);
  560. g_clrBtnText = GetSysColor(COLOR_BTNTEXT);
  561. g_clrBtnFace = GetSysColor(COLOR_BTNFACE);
  562. g_clrBtnShadow = GetSysColor(COLOR_BTNSHADOW);
  563. g_clrBtnHighlight = GetSysColor(COLOR_BTNHIGHLIGHT);
  564. g_clrHighlight = GetSysColor(COLOR_HIGHLIGHT);
  565. g_clrHighlightText = GetSysColor(COLOR_HIGHLIGHTTEXT);
  566. g_clrInfoText = GetSysColor(COLOR_INFOTEXT);
  567. g_clrInfoBk = GetSysColor(COLOR_INFOBK);
  568. g_clr3DDkShadow = GetSysColor(COLOR_3DDKSHADOW);
  569. g_clr3DLight = GetSysColor(COLOR_3DLIGHT);
  570. g_hbrGrayText = GetSysColorBrush(COLOR_GRAYTEXT);
  571. g_hbrWindow = GetSysColorBrush(COLOR_WINDOW);
  572. g_hbrWindowText = GetSysColorBrush(COLOR_WINDOWTEXT);
  573. g_hbrWindowFrame = GetSysColorBrush(COLOR_WINDOWFRAME);
  574. g_hbrBtnFace = GetSysColorBrush(COLOR_BTNFACE);
  575. g_hbrBtnHighlight = GetSysColorBrush(COLOR_BTNHIGHLIGHT);
  576. g_hbrBtnShadow = GetSysColorBrush(COLOR_BTNSHADOW);
  577. g_hbrHighlight = GetSysColorBrush(COLOR_HIGHLIGHT);
  578. g_hfontSystem = GetStockObject(SYSTEM_FONT);
  579. }
  580. void FAR PASCAL RelayToToolTips(HWND hwndToolTips, HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
  581. {
  582. if(hwndToolTips) {
  583. MSG msg;
  584. msg.lParam = lParam;
  585. msg.wParam = wParam;
  586. msg.message = wMsg;
  587. msg.hwnd = hWnd;
  588. SendMessage(hwndToolTips, TTM_RELAYEVENT, 0, (LPARAM)(LPMSG)&msg);
  589. }
  590. }
  591. #define DT_SEARCHTIMEOUT 1000L // 1 seconds
  592. __inline BOOL IsISearchTimedOut(PISEARCHINFO pis)
  593. {
  594. return GetMessageTime() - pis->timeLast > DT_SEARCHTIMEOUT &&
  595. !IsFlagSet(g_dwPrototype, PTF_NOISEARCHTO);
  596. }
  597. int FAR PASCAL GetIncrementSearchString(PISEARCHINFO pis, LPTSTR lpsz)
  598. {
  599. if (IsISearchTimedOut(pis))
  600. {
  601. pis->iIncrSearchFailed = 0;
  602. pis->ichCharBuf = 0;
  603. }
  604. if (pis->ichCharBuf && lpsz)
  605. {
  606. // REVIEW: trusts that the lParam points to a buffer of sufficient
  607. // size to support the string and null terminator.
  608. StringCchCopy(lpsz, pis->ichCharBuf+1, pis->pszCharBuf);
  609. }
  610. return pis->ichCharBuf;
  611. }
  612. #if defined(FE_IME)
  613. // Now only Korean version is interested in incremental search with composition string.
  614. BOOL FAR PASCAL IncrementSearchImeCompStr(PISEARCHINFO pis, BOOL fCompStr, LPTSTR lpszCompStr, LPTSTR FAR *lplpstr)
  615. {
  616. BOOL fRestart = FALSE;
  617. if (!pis->fReplaceCompChar && IsISearchTimedOut(pis))
  618. {
  619. pis->iIncrSearchFailed = 0;
  620. pis->ichCharBuf = 0;
  621. }
  622. if (pis->ichCharBuf == 0)
  623. {
  624. fRestart = TRUE;
  625. pis->fReplaceCompChar = FALSE;
  626. }
  627. pis->timeLast = GetMessageTime();
  628. // Is there room for new character plus zero terminator?
  629. //
  630. if (!pis->fReplaceCompChar && pis->ichCharBuf + 1 + 1 > pis->cbCharBuf)
  631. {
  632. LPTSTR psz = ReAlloc(pis->pszCharBuf, sizeof(TCHAR)*(pis->cbCharBuf + 16));
  633. if (!psz)
  634. return fRestart;
  635. pis->cbCharBuf += 16;
  636. pis->pszCharBuf = psz;
  637. }
  638. if (pis->fReplaceCompChar)
  639. {
  640. if (lpszCompStr[0])
  641. {
  642. pis->pszCharBuf[pis->ichCharBuf-1] = lpszCompStr[0];
  643. pis->pszCharBuf[pis->ichCharBuf] = 0;
  644. }
  645. else
  646. {
  647. pis->ichCharBuf--;
  648. pis->pszCharBuf[pis->ichCharBuf] = 0;
  649. }
  650. }
  651. else
  652. {
  653. pis->pszCharBuf[pis->ichCharBuf++] = lpszCompStr[0];
  654. pis->pszCharBuf[pis->ichCharBuf] = 0;
  655. }
  656. pis->fReplaceCompChar = (fCompStr && lpszCompStr[0]);
  657. if (pis->ichCharBuf == 1 && pis->fReplaceCompChar)
  658. fRestart = TRUE;
  659. *lplpstr = pis->pszCharBuf;
  660. return fRestart;
  661. }
  662. #endif FE_IME
  663. /*
  664. * Thunk for LVM_GETISEARCHSTRINGA
  665. */
  666. int FAR PASCAL GetIncrementSearchStringA(PISEARCHINFO pis, UINT uiCodePage, LPSTR lpsz)
  667. {
  668. if (IsISearchTimedOut(pis))
  669. {
  670. pis->iIncrSearchFailed = 0;
  671. pis->ichCharBuf = 0;
  672. }
  673. if (pis->ichCharBuf && lpsz) {
  674. ConvertWToAN( uiCodePage, lpsz, pis->ichCharBuf, pis->pszCharBuf, pis->ichCharBuf );
  675. lpsz[pis->ichCharBuf] = '\0';
  676. }
  677. return pis->ichCharBuf;
  678. }
  679. // Beep only on the first failure.
  680. void FAR PASCAL IncrementSearchBeep(PISEARCHINFO pis)
  681. {
  682. if (!pis->iIncrSearchFailed)
  683. {
  684. pis->iIncrSearchFailed = TRUE;
  685. MessageBeep(0);
  686. }
  687. }
  688. //
  689. // IncrementSearchString - Add or clear the search string
  690. //
  691. // ch == 0: Reset the search string. Return value meaningless.
  692. //
  693. // ch != 0: Append the character to the search string, starting
  694. // a new search string if we timed out the last one.
  695. // lplpstr receives the string so far.
  696. // Return value is TRUE if a new search string was
  697. // created, or FALSE if we appended to an existing one.
  698. //
  699. BOOL FAR PASCAL IncrementSearchString(PISEARCHINFO pis, UINT ch, LPTSTR FAR *lplpstr)
  700. {
  701. BOOL fRestart = FALSE;
  702. if (!ch) {
  703. pis->ichCharBuf =0;
  704. pis->iIncrSearchFailed = 0;
  705. return FALSE;
  706. }
  707. if (IsISearchTimedOut(pis))
  708. {
  709. pis->iIncrSearchFailed = 0;
  710. pis->ichCharBuf = 0;
  711. }
  712. if (pis->ichCharBuf == 0)
  713. fRestart = TRUE;
  714. pis->timeLast = GetMessageTime();
  715. // Is there room for new character plus zero terminator?
  716. //
  717. if (pis->ichCharBuf + 1 + 1 > pis->cbCharBuf)
  718. {
  719. LPTSTR psz = ReAlloc(pis->pszCharBuf, ((pis->cbCharBuf + 16) * sizeof(TCHAR)));
  720. if (!psz)
  721. return fRestart;
  722. pis->cbCharBuf += 16;
  723. pis->pszCharBuf = psz;
  724. }
  725. pis->pszCharBuf[pis->ichCharBuf++] = (TCHAR)ch;
  726. pis->pszCharBuf[pis->ichCharBuf] = 0;
  727. *lplpstr = pis->pszCharBuf;
  728. return fRestart;
  729. }
  730. // strips out the accelerators. they CAN be the same buffers.
  731. void PASCAL StripAccelerators(LPTSTR lpszFrom, LPTSTR lpszTo, BOOL fAmpOnly)
  732. {
  733. BOOL fRet = FALSE;
  734. while ( *lpszTo = *lpszFrom ) {
  735. if (!fAmpOnly && (g_fDBCSInputEnabled))
  736. {
  737. if (*lpszFrom == TEXT('(') && *(lpszFrom+1)==CH_PREFIX)
  738. {
  739. int i;
  740. LPTSTR psz = lpszFrom+2;
  741. for(i=0; i<2 && *psz;i++, psz=FastCharNext(psz))
  742. ;
  743. if (*psz == '\0') {
  744. *lpszTo = 0;
  745. break;
  746. }
  747. else if (i == 2 && *psz == TEXT(')'))
  748. {
  749. lpszTo--;
  750. lpszFrom = psz+1;
  751. continue;
  752. }
  753. }
  754. }
  755. if (*lpszFrom == TEXT('\t')) {
  756. *lpszTo = TEXT('\0');
  757. break;
  758. }
  759. if ( (*lpszFrom++ != CH_PREFIX) || (*lpszFrom == CH_PREFIX) ) {
  760. lpszTo++;
  761. }
  762. }
  763. }
  764. void ScrollShrinkRect(int x, int y, LPRECT lprc)
  765. {
  766. if (lprc) {
  767. if (x > 0) {
  768. lprc->left += x;
  769. } else {
  770. lprc->right += x;
  771. }
  772. if (y > 0) {
  773. lprc->top += y;
  774. } else {
  775. lprc->bottom += y;
  776. }
  777. }
  778. }
  779. // common control info helpers
  780. void FAR PASCAL CIInitialize(LPCONTROLINFO lpci, HWND hwnd, LPCREATESTRUCT lpcs)
  781. {
  782. lpci->hwnd = hwnd;
  783. lpci->hwndParent = lpcs->hwndParent;
  784. lpci->style = lpcs->style;
  785. lpci->uiCodePage = CP_ACP;
  786. lpci->dwExStyle = lpcs->dwExStyle;
  787. lpci->bUnicode = lpci->hwndParent &&
  788. SendMessage (lpci->hwndParent, WM_NOTIFYFORMAT,
  789. (WPARAM)lpci->hwnd, NF_QUERY) == NFR_UNICODE;
  790. if (lpci->hwndParent)
  791. {
  792. LRESULT lRes = SendMessage(lpci->hwndParent, WM_QUERYUISTATE, 0, 0);
  793. lpci->wUIState = LOWORD(lRes);
  794. }
  795. }
  796. LRESULT FAR PASCAL CIHandleNotifyFormat(LPCONTROLINFO lpci, LPARAM lParam)
  797. {
  798. if (lParam == NF_QUERY) {
  799. return NFR_UNICODE;
  800. } else if (lParam == NF_REQUERY) {
  801. LRESULT uiResult;
  802. uiResult = SendMessage (lpci->hwndParent, WM_NOTIFYFORMAT,
  803. (WPARAM)lpci->hwnd, NF_QUERY);
  804. lpci->bUnicode = BOOLIFY(uiResult == NFR_UNICODE);
  805. return uiResult;
  806. }
  807. return 0;
  808. }
  809. UINT CCSwapKeys(WPARAM wParam, UINT vk1, UINT vk2)
  810. {
  811. if (wParam == vk1)
  812. return vk2;
  813. if (wParam == vk2)
  814. return vk1;
  815. return (UINT)wParam;
  816. }
  817. UINT RTLSwapLeftRightArrows(CONTROLINFO *pci, WPARAM wParam)
  818. {
  819. if (pci->dwExStyle & RTL_MIRRORED_WINDOW) {
  820. return CCSwapKeys(wParam, VK_LEFT, VK_RIGHT);
  821. }
  822. return (UINT)wParam;
  823. }
  824. //
  825. // New for v5.01:
  826. //
  827. // Accessibility (and some other callers, sometimes even us) relies on
  828. // a XXM_GETITEM call filling the buffer and not just redirecting the
  829. // pointer. Accessibility is particularly impacted by this because they
  830. // live outside the process, so the redirected pointer means nothing
  831. // to them. Here, we copy the result back into the app buffer and return
  832. // the raw pointer. The caller will return the raw pointer back to the
  833. // app, so the answer is in two places, either the app buffer, or in
  834. // the raw pointer.
  835. //
  836. // Usage:
  837. //
  838. // if (nm.item.mask & LVIF_TEXT)
  839. // pitem->pszText = CCReturnDispInfoText(nm.item.pszText,
  840. // pitem->pszText, pitem->cchTextMax);
  841. //
  842. LPTSTR CCReturnDispInfoText(LPTSTR pszSrc, LPTSTR pszDest, UINT cchDest)
  843. {
  844. // Test pszSrc != pszDest first since the common case is that they
  845. // are equal.
  846. if (pszSrc != pszDest && !IsFlagPtr(pszSrc) && !IsFlagPtr(pszDest))
  847. StrCpyN(pszDest, pszSrc, cchDest);
  848. return pszSrc;
  849. }
  850. #define SUBSCROLLS 100
  851. #define abs(x) ( ( x > 0 ) ? x : -x)
  852. #define DEFAULT_MAXSCROLLTIME ((GetDoubleClickTime() / 2) + 1) // Ensure >= 1
  853. #define DEFAULT_MINSCROLL 8
  854. int SmoothScrollWindow(PSMOOTHSCROLLINFO psi)
  855. {
  856. int dx = psi->dx;
  857. int dy = psi->dy;
  858. LPCRECT lprcSrc = psi->lprcSrc;
  859. LPCRECT lprcClip = psi->lprcClip;
  860. HRGN hrgnUpdate = psi->hrgnUpdate;
  861. LPRECT lprcUpdate = psi->lprcUpdate;
  862. UINT fuScroll = psi->fuScroll;
  863. int iRet = SIMPLEREGION;
  864. RECT rcUpdate;
  865. RECT rcSrc;
  866. RECT rcClip;
  867. int xStep;
  868. int yStep;
  869. int iSlicesDone = 0;
  870. int iSlices;
  871. DWORD dwTimeStart, dwTimeNow;
  872. HRGN hrgnLocalUpdate;
  873. UINT cxMinScroll = psi->cxMinScroll;
  874. UINT cyMinScroll = psi->cyMinScroll;
  875. UINT uMaxScrollTime = psi->uMaxScrollTime;
  876. int iSubScrolls;
  877. PFNSMOOTHSCROLLPROC pfnScrollProc;
  878. if (!lprcUpdate)
  879. lprcUpdate = &rcUpdate;
  880. SetRectEmpty(lprcUpdate);
  881. if (psi->cbSize != sizeof(SMOOTHSCROLLINFO))
  882. return 0;
  883. // check the defaults
  884. if (!(psi->fMask & SSIF_MINSCROLL )
  885. || cxMinScroll == SSI_DEFAULT)
  886. cxMinScroll = DEFAULT_MINSCROLL;
  887. if (!(psi->fMask & SSIF_MINSCROLL)
  888. || cyMinScroll == SSI_DEFAULT)
  889. cyMinScroll = DEFAULT_MINSCROLL;
  890. if (!(psi->fMask & SSIF_MAXSCROLLTIME)
  891. || uMaxScrollTime == SSI_DEFAULT)
  892. uMaxScrollTime = DEFAULT_MAXSCROLLTIME;
  893. if (uMaxScrollTime < SUBSCROLLS)
  894. uMaxScrollTime = SUBSCROLLS;
  895. if ((!(fuScroll & SSW_EX_IGNORESETTINGS)) &&
  896. (!g_fSmoothScroll)) {
  897. fuScroll |= SSW_EX_IMMEDIATE;
  898. }
  899. if ((psi->fMask & SSIF_SCROLLPROC) && psi->pfnScrollProc) {
  900. pfnScrollProc = psi->pfnScrollProc;
  901. } else {
  902. pfnScrollProc = ScrollWindowEx;
  903. }
  904. #ifdef ScrollWindowEx
  905. #undef ScrollWindowEx
  906. #endif
  907. if (fuScroll & SSW_EX_IMMEDIATE) {
  908. return pfnScrollProc(psi->hwnd, dx, dy, lprcSrc, lprcClip, hrgnUpdate,
  909. lprcUpdate, LOWORD(fuScroll));
  910. }
  911. // copy input rects locally
  912. if (lprcSrc) {
  913. rcSrc = *lprcSrc;
  914. lprcSrc = &rcSrc;
  915. }
  916. if (lprcClip) {
  917. rcClip = *lprcClip;
  918. lprcClip = &rcClip;
  919. }
  920. if (!hrgnUpdate)
  921. hrgnLocalUpdate = CreateRectRgn(0,0,0,0);
  922. else
  923. hrgnLocalUpdate = hrgnUpdate;
  924. //set up initial vars
  925. dwTimeStart = GetTickCount();
  926. if (fuScroll & SSW_EX_NOTIMELIMIT) {
  927. xStep = cxMinScroll * (dx < 0 ? -1 : 1);
  928. yStep = cyMinScroll * (dy < 0 ? -1 : 1);
  929. } else {
  930. iSubScrolls = (uMaxScrollTime / DEFAULT_MAXSCROLLTIME) * SUBSCROLLS;
  931. if (!iSubScrolls)
  932. iSubScrolls = SUBSCROLLS;
  933. xStep = dx / iSubScrolls;
  934. yStep = dy / iSubScrolls;
  935. }
  936. if (xStep == 0 && dx)
  937. xStep = dx < 0 ? -1 : 1;
  938. if (yStep == 0 && dy)
  939. yStep = dy < 0 ? -1 : 1;
  940. while (dx || dy) {
  941. int x,y;
  942. RECT rcTempUpdate;
  943. if (fuScroll & SSW_EX_NOTIMELIMIT) {
  944. x = xStep;
  945. y = yStep;
  946. if (abs(x) > abs(dx))
  947. x = dx;
  948. if (abs(y) > abs(dy))
  949. y = dy;
  950. } else {
  951. int iTimePerScroll = uMaxScrollTime / iSubScrolls;
  952. if (!iTimePerScroll)
  953. iTimePerScroll = 1;
  954. dwTimeNow = GetTickCount();
  955. iSlices = ((dwTimeNow - dwTimeStart) / iTimePerScroll) - iSlicesDone;
  956. if (iSlices < 0)
  957. iSlices = 0;
  958. do {
  959. int iRet = 0;
  960. iSlices++;
  961. if ((iSlicesDone + iSlices) <= iSubScrolls) {
  962. x = xStep * iSlices;
  963. y = yStep * iSlices;
  964. // this could go over if we rounded ?Step up to 1(-1) above
  965. if (abs(x) > abs(dx))
  966. x = dx;
  967. if (abs(y) > abs(dy))
  968. y = dy;
  969. } else {
  970. x = dx;
  971. y = dy;
  972. }
  973. //DebugMsg(DM_TRACE, "SmoothScrollWindowCallback %d", iRet);
  974. if (x == dx && y == dy)
  975. break;
  976. if ((((UINT)(abs(x)) >= cxMinScroll) || !x) &&
  977. (((UINT)(abs(y)) >= cyMinScroll) || !y))
  978. break;
  979. } while (1);
  980. }
  981. if (pfnScrollProc(psi->hwnd, x, y, lprcSrc, lprcClip, hrgnLocalUpdate, &rcTempUpdate, LOWORD(fuScroll)) == ERROR) {
  982. iRet = ERROR;
  983. goto Bail;
  984. }
  985. // we don't need to do this always because if iSlices >= iSlicesDone, we'll have scrolled blanks
  986. //if (iSlices < iSlicesDone)
  987. RedrawWindow(psi->hwnd, NULL, hrgnLocalUpdate, RDW_ERASE | RDW_ERASENOW | RDW_INVALIDATE);
  988. UnionRect(lprcUpdate, &rcTempUpdate, lprcUpdate);
  989. ScrollShrinkRect(x,y, (LPRECT)lprcSrc);
  990. ScrollShrinkRect(x,y, (LPRECT)lprcClip);
  991. dx -= x;
  992. dy -= y;
  993. iSlicesDone += iSlices;
  994. }
  995. Bail:
  996. if (fuScroll & SW_SCROLLCHILDREN) {
  997. RedrawWindow(psi->hwnd, lprcUpdate, NULL, RDW_INVALIDATE);
  998. }
  999. if (hrgnLocalUpdate != hrgnUpdate)
  1000. DeleteObject(hrgnLocalUpdate);
  1001. return iRet;
  1002. }
  1003. typedef BOOL (WINAPI *PLAYSOUNDFN)(LPCTSTR lpsz, HANDLE hMod, DWORD dwFlags);
  1004. typedef UINT (WINAPI *UINTVOIDFN)();
  1005. TCHAR const c_szWinMMDll[] = TEXT("winmm.dll");
  1006. char const c_szPlaySound[] = "PlaySoundW";
  1007. char const c_szwaveOutGetNumDevs[] = "waveOutGetNumDevs";
  1008. extern TCHAR const c_szExplorer[];
  1009. BOOL g_fNeverPlaySound = FALSE;
  1010. void CCPlaySound(LPCTSTR lpszName)
  1011. {
  1012. if (g_fNeverPlaySound == FALSE)
  1013. {
  1014. TCHAR szSubKey[MAX_PATH];
  1015. TCHAR szFileName[MAX_PATH];
  1016. DWORD cbFileName = SIZEOF(szFileName);
  1017. TCHAR szFmt[] = TEXT("AppEvents\\Schemes\\Apps\\.Default\\%s\\.current");
  1018. // check the registry first
  1019. // if there's nothing registered, we blow off the play,
  1020. // but we don't set the MM_DONTLOAD flag so taht if they register
  1021. // something we will play it
  1022. if (ARRAYSIZE(szSubKey) > (lstrlen(szFmt) + lstrlen(lpszName)))
  1023. {
  1024. StringCchPrintf(szSubKey, ARRAYSIZE(szSubKey), szFmt, lpszName);
  1025. if ((RegQueryValue(HKEY_CURRENT_USER, szSubKey, szFileName, &cbFileName) == ERROR_SUCCESS))
  1026. {
  1027. PLAYSOUNDFN pfnPlaySound;
  1028. UINTVOIDFN pfnwaveOutGetNumDevs;
  1029. HANDLE hMM;
  1030. hMM = GetModuleHandle(c_szWinMMDll);
  1031. if (!hMM)
  1032. {
  1033. hMM = LoadLibrary(c_szWinMMDll);
  1034. }
  1035. if (hMM)
  1036. {
  1037. /// are there any devices?
  1038. pfnwaveOutGetNumDevs = (UINTVOIDFN)GetProcAddress(hMM, c_szwaveOutGetNumDevs);
  1039. pfnPlaySound = (PLAYSOUNDFN)GetProcAddress(hMM, c_szPlaySound);
  1040. if (!pfnPlaySound || !pfnwaveOutGetNumDevs || !pfnwaveOutGetNumDevs())
  1041. {
  1042. g_fNeverPlaySound = TRUE;
  1043. }
  1044. else
  1045. {
  1046. pfnPlaySound(szFileName, NULL, SND_FILENAME | SND_ASYNC);
  1047. }
  1048. }
  1049. }
  1050. }
  1051. }
  1052. }
  1053. BOOL CCForwardEraseBackground(HWND hwnd, HDC hdc)
  1054. {
  1055. HWND hwndParent = GetParent(hwnd);
  1056. LRESULT lres = 0;
  1057. if (hwndParent)
  1058. {
  1059. // Adjust the origin so the parent paints in the right place
  1060. POINT pt = {0,0};
  1061. MapWindowPoints(hwnd, hwndParent, &pt, 1);
  1062. OffsetWindowOrgEx(hdc,
  1063. pt.x,
  1064. pt.y,
  1065. &pt);
  1066. lres = SendMessage(hwndParent, WM_ERASEBKGND, (WPARAM) hdc, 0L);
  1067. SetWindowOrgEx(hdc, pt.x, pt.y, NULL);
  1068. }
  1069. return(lres != 0);
  1070. }
  1071. HFONT CCGetHotFont(HFONT hFont, HFONT *phFontHot)
  1072. {
  1073. if (!*phFontHot) {
  1074. LOGFONT lf;
  1075. // create the underline font
  1076. GetObject(hFont, sizeof(lf), &lf);
  1077. #ifndef DONT_UNDERLINE
  1078. lf.lfUnderline = TRUE;
  1079. #endif
  1080. *phFontHot = CreateFontIndirect(&lf);
  1081. }
  1082. return *phFontHot;
  1083. }
  1084. HFONT CCCreateStatusFont(void)
  1085. {
  1086. NONCLIENTMETRICS ncm;
  1087. ncm.cbSize = sizeof(NONCLIENTMETRICS);
  1088. SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0);
  1089. return CreateFontIndirect(&ncm.lfStatusFont);
  1090. }
  1091. void* CCLocalReAlloc(void* p, UINT uBytes)
  1092. {
  1093. if (uBytes) {
  1094. if (p) {
  1095. return LocalReAlloc(p, uBytes, LMEM_MOVEABLE | LMEM_ZEROINIT);
  1096. } else {
  1097. return LocalAlloc(LPTR, uBytes);
  1098. }
  1099. } else {
  1100. if (p)
  1101. LocalFree(p);
  1102. return NULL;
  1103. }
  1104. }
  1105. /*----------------------------------------------------------
  1106. Purpose: This function provides the commctrl version info. This
  1107. allows the caller to distinguish running NT SUR vs.
  1108. Win95 shell vs. Nashville, etc.
  1109. This API was not supplied in Win95 or NT SUR, so
  1110. the caller must GetProcAddress it. If this fails,
  1111. the caller is running on Win95 or NT SUR.
  1112. Returns: NO_ERROR
  1113. ERROR_INVALID_PARAMETER if pinfo is invalid
  1114. Cond: --
  1115. */
  1116. // All we have to do is declare this puppy and CCDllGetVersion does the rest
  1117. // Note that we use VER_FILEVERSION_DW because comctl32 uses a funky
  1118. // version scheme
  1119. DLLVER_DUALBINARY(VER_FILEVERSION_DW, VER_PRODUCTBUILD_QFE);
  1120. //
  1121. // Translate the given font to a code page used for thunking text
  1122. //
  1123. UINT GetCodePageForFont(HFONT hFont)
  1124. {
  1125. LOGFONT lf;
  1126. TCHAR szFontName[LF_FACESIZE];
  1127. CHARSETINFO csi;
  1128. DWORD dwSize, dwType;
  1129. HKEY hKey;
  1130. if (!GetObject (hFont, sizeof(lf), &lf))
  1131. {
  1132. return CP_ACP;
  1133. }
  1134. //
  1135. // Check for font substitutes
  1136. //
  1137. StringCchCopy(szFontName, ARRAYSIZE(szFontName), lf.lfFaceName);
  1138. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  1139. TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\FontSubstitutes"),
  1140. 0, KEY_READ, &hKey) == ERROR_SUCCESS)
  1141. {
  1142. dwSize = sizeof(szFontName);
  1143. RegQueryValueEx(hKey, lf.lfFaceName, NULL, &dwType,
  1144. (LPBYTE) szFontName, &dwSize);
  1145. RegCloseKey (hKey);
  1146. }
  1147. //
  1148. // This is to fix office for locales that use non 1252 versions
  1149. // of Ms Sans Serif and Ms Serif. These fonts incorrectly identify
  1150. // themselves as having an Ansi charset, so TranslateCharsetInfo will
  1151. // return the wrong value.
  1152. //
  1153. // NT bug 260697: Office 2000 uses Tahoma.
  1154. //
  1155. if ((lf.lfCharSet == ANSI_CHARSET) &&
  1156. (!lstrcmpi(L"Helv", szFontName) ||
  1157. !lstrcmpi(L"Ms Sans Serif", szFontName) ||
  1158. !lstrcmpi(L"Ms Serif", szFontName) ||
  1159. !lstrcmpi(L"Tahoma", szFontName)))
  1160. {
  1161. return CP_ACP;
  1162. }
  1163. //
  1164. // This is to fix FE office95a and Pro. msofe95.dll sets wrong charset when create
  1165. // listview control. so TranslateCharsetInfo will return the wrong value.
  1166. // Korea : DotumChe.
  1167. // Taiwan : New MingLight
  1168. // China : SongTi
  1169. if ((lf.lfCharSet == SHIFTJIS_CHARSET) &&
  1170. (!lstrcmpi(L"\xb3cb\xc6c0\xccb4", lf.lfFaceName)) || // Korea
  1171. (!lstrcmpi(L"\x65b0\x7d30\x660e\x9ad4", lf.lfFaceName)) || // Taiwan
  1172. (!lstrcmpi(L"\x5b8b\x4f53", lf.lfFaceName))) // PRC
  1173. {
  1174. return CP_ACP;
  1175. }
  1176. if (!TranslateCharsetInfo((DWORD FAR *) lf.lfCharSet, &csi, TCI_SRCCHARSET))
  1177. {
  1178. return CP_ACP;
  1179. }
  1180. return csi.ciACP;
  1181. }
  1182. typedef void (CALLBACK* NOTIFYWINEVENTPROC)(UINT, HWND, LONG, LONG_PTR);
  1183. #define DONOTHING_NOTIFYWINEVENT ((NOTIFYWINEVENTPROC)1)
  1184. // --------------------------------------------------------------------------
  1185. //
  1186. // MyNotifyWinEvent()
  1187. //
  1188. // This tries to get the proc address of NotifyWinEvent(). If it fails, we
  1189. // remember that and do nothing.
  1190. //
  1191. // NOTE TO NT FOLKS:
  1192. // Don't worry about this code. It will do nothing on NT, nothing yet
  1193. // that is. Active Accessibility will be ported to NT for Service Pack #1
  1194. // or at worst #2 after NT SUR ships, this code will work magically when
  1195. // that is done/
  1196. //
  1197. // --------------------------------------------------------------------------
  1198. void MyNotifyWinEvent(UINT event, HWND hwnd, LONG idContainer, LONG_PTR idChild)
  1199. {
  1200. static NOTIFYWINEVENTPROC s_pfnNotifyWinEvent = NULL;
  1201. if (!s_pfnNotifyWinEvent)
  1202. {
  1203. HMODULE hmod;
  1204. if (hmod = GetModuleHandle(TEXT("USER32")))
  1205. s_pfnNotifyWinEvent = (NOTIFYWINEVENTPROC)GetProcAddress(hmod,
  1206. "NotifyWinEvent");
  1207. if (!s_pfnNotifyWinEvent)
  1208. s_pfnNotifyWinEvent = DONOTHING_NOTIFYWINEVENT;
  1209. }
  1210. if (s_pfnNotifyWinEvent != DONOTHING_NOTIFYWINEVENT)
  1211. (* s_pfnNotifyWinEvent)(event, hwnd, idContainer, idChild);
  1212. }
  1213. LONG GetMessagePosClient(HWND hwnd, LPPOINT ppt)
  1214. {
  1215. LPARAM lParam;
  1216. POINT pt;
  1217. if (!ppt)
  1218. ppt = &pt;
  1219. lParam = GetMessagePos();
  1220. ppt->x = GET_X_LPARAM(lParam);
  1221. ppt->y = GET_Y_LPARAM(lParam);
  1222. ScreenToClient(hwnd, ppt);
  1223. return MAKELONG(ppt->x, ppt->y);
  1224. }
  1225. LPTSTR StrDup(LPCTSTR lpsz)
  1226. {
  1227. DWORD cchRet = lstrlen(lpsz) + 1;
  1228. LPTSTR lpszRet = (LPTSTR)LocalAlloc(LPTR, cchRet * sizeof(TCHAR));
  1229. if (lpszRet)
  1230. {
  1231. StringCchCopy(lpszRet, cchRet, lpsz);
  1232. }
  1233. return lpszRet;
  1234. }
  1235. LPSTR StrDupA(LPCSTR lpsz)
  1236. {
  1237. DWORD cchRet = lstrlenA(lpsz) + 1;
  1238. LPSTR lpszRet = (LPSTR)LocalAlloc(LPTR, cchRet * sizeof(CHAR));
  1239. if (lpszRet)
  1240. {
  1241. StringCchCopyA(lpszRet, cchRet, lpsz);
  1242. }
  1243. return lpszRet;
  1244. }
  1245. HWND GetDlgItemRect(HWND hDlg, int nIDItem, LPRECT prc) //relative to hDlg
  1246. {
  1247. HWND hCtrl = NULL;
  1248. if (prc)
  1249. {
  1250. hCtrl = GetDlgItem(hDlg, nIDItem);
  1251. if (hCtrl)
  1252. {
  1253. GetWindowRect(hCtrl, prc);
  1254. MapWindowRect(NULL, hDlg, prc);
  1255. }
  1256. else
  1257. SetRectEmpty(prc);
  1258. }
  1259. return hCtrl;
  1260. }
  1261. /*----------------------------------------------------------
  1262. Purpose: Calls the ADVPACK entry-point which executes an inf
  1263. file section.
  1264. */
  1265. HRESULT CallRegInstall(LPSTR szSection)
  1266. {
  1267. HRESULT hr = E_FAIL;
  1268. HINSTANCE hinstAdvPack = LoadLibrary(TEXT("ADVPACK.DLL"));
  1269. if (hinstAdvPack)
  1270. {
  1271. REGINSTALL pfnri = (REGINSTALL)GetProcAddress(hinstAdvPack, "RegInstall");
  1272. if (pfnri)
  1273. {
  1274. hr = pfnri(g_hinst, szSection, NULL);
  1275. }
  1276. FreeLibrary(hinstAdvPack);
  1277. }
  1278. return hr;
  1279. }
  1280. /*----------------------------------------------------------
  1281. Purpose: Install/uninstall user settings
  1282. */
  1283. STDAPI DllInstall(BOOL bInstall, LPCWSTR pszCmdLine)
  1284. {
  1285. #ifdef DEBUG
  1286. if (IsFlagSet(g_dwBreakFlags, BF_ONAPIENTER))
  1287. {
  1288. TraceMsg(TF_ALWAYS, "Stopping in DllInstall");
  1289. DEBUG_BREAK;
  1290. }
  1291. #endif
  1292. if (bInstall)
  1293. {
  1294. // Delete any old registration entries, then add the new ones.
  1295. // Keep ADVPACK.DLL loaded across multiple calls to RegInstall.
  1296. // (The inf engine doesn't guarantee DelReg/AddReg order, that's
  1297. // why we explicitly unreg and reg here.)
  1298. //
  1299. CallRegInstall("RegDll");
  1300. }
  1301. else
  1302. {
  1303. CallRegInstall("UnregDll");
  1304. }
  1305. return S_OK;
  1306. }
  1307. //---------------------------------------------------------------------------------------
  1308. void FAR PASCAL FlipRect(LPRECT prc)
  1309. {
  1310. SWAP(prc->left, prc->top, int);
  1311. SWAP(prc->right, prc->bottom, int);
  1312. }
  1313. //---------------------------------------------------------------------------------------
  1314. //
  1315. // Returns previous window bits.
  1316. DWORD SetWindowBits(HWND hWnd, int iWhich, DWORD dwBits, DWORD dwValue)
  1317. {
  1318. DWORD dwStyle;
  1319. DWORD dwNewStyle;
  1320. dwStyle = GetWindowLong(hWnd, iWhich);
  1321. dwNewStyle = ( dwStyle & ~dwBits ) | (dwValue & dwBits);
  1322. if (dwStyle != dwNewStyle) {
  1323. dwStyle = SetWindowLong(hWnd, iWhich, dwNewStyle);
  1324. }
  1325. return dwStyle;
  1326. }
  1327. //---------------------------------------------------------------------------------------
  1328. BOOL CCDrawEdge(HDC hdc, LPRECT lprc, UINT edge, UINT flags, LPCOLORSCHEME lpclrsc)
  1329. {
  1330. RECT rc, rcD;
  1331. UINT bdrType;
  1332. COLORREF clrTL, clrBR;
  1333. //
  1334. // Enforce monochromicity and flatness
  1335. //
  1336. // if (oemInfo.BitCount == 1)
  1337. // flags |= BF_MONO;
  1338. if (flags & BF_MONO)
  1339. flags |= BF_FLAT;
  1340. CopyRect(&rc, lprc);
  1341. //
  1342. // Draw the border segment(s), and calculate the remaining space as we
  1343. // go.
  1344. //
  1345. if (bdrType = (edge & BDR_OUTER))
  1346. {
  1347. DrawBorder:
  1348. //
  1349. // Get colors. Note the symmetry between raised outer, sunken inner and
  1350. // sunken outer, raised inner.
  1351. //
  1352. if (flags & BF_FLAT)
  1353. {
  1354. if (flags & BF_MONO)
  1355. clrBR = (bdrType & BDR_OUTER) ? g_clrWindowFrame : g_clrWindow;
  1356. else
  1357. clrBR = (bdrType & BDR_OUTER) ? g_clrBtnShadow: g_clrBtnFace;
  1358. clrTL = clrBR;
  1359. }
  1360. else
  1361. {
  1362. // 5 == HILIGHT
  1363. // 4 == LIGHT
  1364. // 3 == FACE
  1365. // 2 == SHADOW
  1366. // 1 == DKSHADOW
  1367. switch (bdrType)
  1368. {
  1369. // +2 above surface
  1370. case BDR_RAISEDOUTER: // 5 : 4
  1371. clrTL = ((flags & BF_SOFT) ? g_clrBtnHighlight : g_clr3DLight);
  1372. clrBR = g_clr3DDkShadow; // 1
  1373. if (lpclrsc) {
  1374. if (lpclrsc->clrBtnHighlight != CLR_DEFAULT)
  1375. clrTL = lpclrsc->clrBtnHighlight;
  1376. if (lpclrsc->clrBtnShadow != CLR_DEFAULT)
  1377. clrBR = lpclrsc->clrBtnShadow;
  1378. }
  1379. break;
  1380. // +1 above surface
  1381. case BDR_RAISEDINNER: // 4 : 5
  1382. clrTL = ((flags & BF_SOFT) ? g_clr3DLight : g_clrBtnHighlight);
  1383. clrBR = g_clrBtnShadow; // 2
  1384. if (lpclrsc) {
  1385. if (lpclrsc->clrBtnHighlight != CLR_DEFAULT)
  1386. clrTL = lpclrsc->clrBtnHighlight;
  1387. if (lpclrsc->clrBtnShadow != CLR_DEFAULT)
  1388. clrBR = lpclrsc->clrBtnShadow;
  1389. }
  1390. break;
  1391. // -1 below surface
  1392. case BDR_SUNKENOUTER: // 1 : 2
  1393. clrTL = ((flags & BF_SOFT) ? g_clr3DDkShadow : g_clrBtnShadow);
  1394. clrBR = g_clrBtnHighlight; // 5
  1395. if (lpclrsc) {
  1396. if (lpclrsc->clrBtnShadow != CLR_DEFAULT)
  1397. clrTL = lpclrsc->clrBtnShadow;
  1398. if (lpclrsc->clrBtnHighlight != CLR_DEFAULT)
  1399. clrBR = lpclrsc->clrBtnHighlight;
  1400. }
  1401. break;
  1402. // -2 below surface
  1403. case BDR_SUNKENINNER: // 2 : 1
  1404. clrTL = ((flags & BF_SOFT) ? g_clrBtnShadow : g_clr3DDkShadow);
  1405. clrBR = g_clr3DLight; // 4
  1406. if (lpclrsc) {
  1407. if (lpclrsc->clrBtnShadow != CLR_DEFAULT)
  1408. clrTL = lpclrsc->clrBtnShadow;
  1409. if (lpclrsc->clrBtnHighlight != CLR_DEFAULT)
  1410. clrBR = lpclrsc->clrBtnHighlight;
  1411. }
  1412. break;
  1413. default:
  1414. return(FALSE);
  1415. }
  1416. }
  1417. //
  1418. // Draw the sides of the border. NOTE THAT THE ALGORITHM FAVORS THE
  1419. // BOTTOM AND RIGHT SIDES, since the light source is assumed to be top
  1420. // left. If we ever decide to let the user set the light source to a
  1421. // particular corner, then change this algorithm.
  1422. //
  1423. // Bottom Right edges
  1424. if (flags & (BF_RIGHT | BF_BOTTOM))
  1425. {
  1426. // Right
  1427. if (flags & BF_RIGHT)
  1428. {
  1429. rc.right -= g_cxBorder;
  1430. // PatBlt(hdc, rc.right, rc.top, g_cxBorder, rc.bottom - rc.top, PATCOPY);
  1431. rcD.left = rc.right;
  1432. rcD.right = rc.right + g_cxBorder;
  1433. rcD.top = rc.top;
  1434. rcD.bottom = rc.bottom;
  1435. FillRectClr(hdc, &rcD, clrBR);
  1436. }
  1437. // Bottom
  1438. if (flags & BF_BOTTOM)
  1439. {
  1440. rc.bottom -= g_cyBorder;
  1441. // PatBlt(hdc, rc.left, rc.bottom, rc.right - rc.left, g_cyBorder, PATCOPY);
  1442. rcD.left = rc.left;
  1443. rcD.right = rc.right;
  1444. rcD.top = rc.bottom;
  1445. rcD.bottom = rc.bottom + g_cyBorder;
  1446. FillRectClr(hdc, &rcD, clrBR);
  1447. }
  1448. }
  1449. // Top Left edges
  1450. if (flags & (BF_TOP | BF_LEFT))
  1451. {
  1452. // Left
  1453. if (flags & BF_LEFT)
  1454. {
  1455. // PatBlt(hdc, rc.left, rc.top, g_cxBorder, rc.bottom - rc.top, PATCOPY);
  1456. rc.left += g_cxBorder;
  1457. rcD.left = rc.left - g_cxBorder;
  1458. rcD.right = rc.left;
  1459. rcD.top = rc.top;
  1460. rcD.bottom = rc.bottom;
  1461. FillRectClr(hdc, &rcD, clrTL);
  1462. }
  1463. // Top
  1464. if (flags & BF_TOP)
  1465. {
  1466. // PatBlt(hdc, rc.left, rc.top, rc.right - rc.left, g_cyBorder, PATCOPY);
  1467. rc.top += g_cyBorder;
  1468. rcD.left = rc.left;
  1469. rcD.right = rc.right;
  1470. rcD.top = rc.top - g_cyBorder;
  1471. rcD.bottom = rc.top;
  1472. FillRectClr(hdc, &rcD, clrTL);
  1473. }
  1474. }
  1475. }
  1476. if (bdrType = (edge & BDR_INNER))
  1477. {
  1478. //
  1479. // Strip this so the next time through, bdrType will be 0.
  1480. // Otherwise, we'll loop forever.
  1481. //
  1482. edge &= ~BDR_INNER;
  1483. goto DrawBorder;
  1484. }
  1485. //
  1486. // Fill the middle & clean up if asked
  1487. //
  1488. if (flags & BF_MIDDLE)
  1489. FillRectClr(hdc, &rc, (flags & BF_MONO) ? g_clrWindow : g_clrBtnFace);
  1490. if (flags & BF_ADJUST)
  1491. CopyRect(lprc, &rc);
  1492. return(TRUE);
  1493. }
  1494. //---------------------------------------------------------------------------------------
  1495. //CCInvalidateFrame -- SWP_FRAMECHANGED, w/o all the extra params
  1496. //
  1497. void CCInvalidateFrame(HWND hwnd)
  1498. {
  1499. SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
  1500. return;
  1501. }
  1502. //---------------------------------------------------------------------------------------
  1503. // FlipPoint - flip the x and y coordinates of a point
  1504. //
  1505. void FlipPoint(LPPOINT lppt)
  1506. {
  1507. SWAP(lppt->x, lppt->y, int);
  1508. }
  1509. //
  1510. // When we want to turn a tooltip into an infotip, we set its
  1511. // width to 300 "small pixels", where there are 72 small pixels
  1512. // per inch when you are in small fonts mode.
  1513. //
  1514. // Scale this value based on the magnification in effect
  1515. // on the owner's monitor. But never let the tooltip get
  1516. // bigger than 3/4 of the screen.
  1517. //
  1518. void CCSetInfoTipWidth(HWND hwndOwner, HWND hwndToolTips)
  1519. {
  1520. HDC hdc = GetDC(hwndOwner);
  1521. int iWidth = MulDiv(GetDeviceCaps(hdc, LOGPIXELSX), 300, 72);
  1522. int iMaxWidth = GetDeviceCaps(hdc, HORZRES) * 3 / 4;
  1523. SendMessage(hwndToolTips, TTM_SETMAXTIPWIDTH, 0, min(iWidth, iMaxWidth));
  1524. ReleaseDC(hwndOwner, hdc);
  1525. }
  1526. // Mirror a bitmap in a DC (mainly a text object in a DC)
  1527. //
  1528. // [samera]
  1529. //
  1530. void MirrorBitmapInDC( HDC hdc , HBITMAP hbmOrig )
  1531. {
  1532. HDC hdcMem;
  1533. HBITMAP hbm;
  1534. BITMAP bm;
  1535. if( !GetObject( hbmOrig , sizeof(BITMAP) , &bm ))
  1536. return;
  1537. hdcMem = CreateCompatibleDC( hdc );
  1538. if( !hdcMem )
  1539. return;
  1540. hbm = CreateCompatibleBitmap( hdc , bm.bmWidth , bm.bmHeight );
  1541. if( !hbm )
  1542. {
  1543. DeleteDC( hdcMem );
  1544. return;
  1545. }
  1546. //
  1547. // Flip the bitmap
  1548. //
  1549. SelectObject( hdcMem , hbm );
  1550. SET_DC_RTL_MIRRORED(hdcMem);
  1551. BitBlt( hdcMem , 0 , 0 , bm.bmWidth , bm.bmHeight ,
  1552. hdc , 0 , 0 , SRCCOPY );
  1553. SET_DC_LAYOUT(hdcMem,0);
  1554. //
  1555. // BUGBUG : The offset by 1 is to solve the off-by-one (in hdcMem) problem. Solved.
  1556. // [samera]
  1557. //
  1558. BitBlt( hdc , 0 , 0 , bm.bmWidth , bm.bmHeight ,
  1559. hdcMem , 0 , 0 , SRCCOPY );
  1560. DeleteDC( hdcMem );
  1561. DeleteObject( hbm );
  1562. return;
  1563. }
  1564. // returns TRUE if handled
  1565. BOOL CCWndProc(CONTROLINFO* pci, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* plres)
  1566. {
  1567. if (uMsg >= CCM_FIRST && uMsg < CCM_LAST) {
  1568. LRESULT lres = 0;
  1569. switch (uMsg) {
  1570. case CCM_SETUNICODEFORMAT:
  1571. lres = pci->bUnicode;
  1572. pci->bUnicode = BOOLFROMPTR(wParam);
  1573. break;
  1574. case CCM_GETUNICODEFORMAT:
  1575. lres = pci->bUnicode;
  1576. break;
  1577. case CCM_SETVERSION:
  1578. if (wParam <= COMCTL32_VERSION) {
  1579. lres = pci->iVersion;
  1580. pci->iVersion = (int)wParam;
  1581. } else
  1582. lres = -1;
  1583. break;
  1584. case CCM_GETVERSION:
  1585. lres = pci->iVersion;
  1586. break;
  1587. }
  1588. ASSERT(plres);
  1589. *plres = lres;
  1590. return TRUE;
  1591. }
  1592. return FALSE;
  1593. }
  1594. // The return value tells if the state changed or not (TRUE == change)
  1595. BOOL NEAR PASCAL CCOnUIState(LPCONTROLINFO pControlInfo,
  1596. UINT uMessage, WPARAM wParam, LPARAM lParam)
  1597. {
  1598. WORD wOldUIState = pControlInfo->wUIState;
  1599. // That's the only message we handle
  1600. if (WM_UPDATEUISTATE == uMessage)
  1601. {
  1602. switch (LOWORD(wParam))
  1603. {
  1604. case UIS_SET:
  1605. pControlInfo->wUIState |= HIWORD(wParam);
  1606. break;
  1607. case UIS_CLEAR:
  1608. pControlInfo->wUIState &= ~(HIWORD(wParam));
  1609. break;
  1610. }
  1611. }
  1612. // These message always need to be passed to DefWindowProc
  1613. return (wOldUIState != pControlInfo->wUIState);
  1614. }
  1615. BOOL CCNotifyNavigationKeyUsage(LPCONTROLINFO pControlInfo, WORD wFlag)
  1616. {
  1617. BOOL fRet = FALSE;
  1618. // do something only if not already in keyboard mode
  1619. if ((CCGetUIState(pControlInfo) & (UISF_HIDEFOCUS | UISF_HIDEACCEL)) != wFlag)
  1620. {
  1621. SendMessage(pControlInfo->hwndParent, WM_CHANGEUISTATE,
  1622. MAKELONG(UIS_CLEAR, wFlag), 0);
  1623. pControlInfo->wUIState &= ~(HIWORD(wFlag));
  1624. // we did the notify
  1625. fRet = TRUE;
  1626. }
  1627. return fRet;
  1628. }
  1629. BOOL CCGetUIState(LPCONTROLINFO pControlInfo)
  1630. {
  1631. return pControlInfo->wUIState;
  1632. }
  1633. LONG g_dwWindowCount = 0;
  1634. void CCCreateWindow()
  1635. {
  1636. if (InterlockedIncrement(&g_dwWindowCount) == 1)
  1637. {
  1638. // If the count goes to one, Refresh the global metrics
  1639. InitGlobalColors();
  1640. InitGlobalMetrics(0);
  1641. }
  1642. }
  1643. void CCDestroyWindow()
  1644. {
  1645. ASSERT( 0 != g_dwWindowCount );
  1646. InterlockedDecrement(&g_dwWindowCount);
  1647. }