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.

1053 lines
29 KiB

  1. //
  2. // cuiutilcpp
  3. // = UI object library - util functions =
  4. //
  5. #include "private.h"
  6. #include "cuiutil.h"
  7. #include "cuiobj.h"
  8. #include "cuiwnd.h"
  9. #include "cuitip.h"
  10. #include "cuisys.h"
  11. #include "cmydc.h"
  12. #ifndef NOFONTLINK
  13. #include "fontlink.h"
  14. #endif /* !NOFONTLINK */
  15. //
  16. //
  17. //
  18. typedef BOOL (WINAPI *PFNUPDATELAYEREDWINDOW)( HWND hwnd, HDC hdcDst, POINT *pptDst, SIZE *psize, HDC hdcSrc, POINT *pptSrc, COLORREF crKey, BLENDFUNCTION *pblend, DWORD dwFlags );
  19. typedef HMONITOR (WINAPI *PFNMONITORFROMWINDOW)( HWND hwnd, DWORD dwFlags );
  20. typedef HMONITOR (WINAPI *PFNMONITORFROMRECT)( LPRECT prc, DWORD dwFlags );
  21. typedef HMONITOR (WINAPI *PFNMONITORFROMPOINT)( POINT pt, DWORD dwFlags );
  22. typedef BOOL (WINAPI *PFNGETMONITORINFO)( HMONITOR hMonitor, LPMONITORINFO lpmi );
  23. typedef BOOL (WINAPI *PFNANIMATEWINDOW)( HWND hwnd, DWORD dwTime, DWORD dwFlag );
  24. typedef BOOL (WINAPI *PFNGETPROCESSDEFAULTLAYOUT)( DWORD *pdw);
  25. typedef BOOL (WINAPI *PFNSETLAYOUT)( HDC hdc, DWORD dw);
  26. static PFNUPDATELAYEREDWINDOW vpfnUpdateLayeredWindow = NULL;
  27. static PFNMONITORFROMWINDOW vpfnMonitorFromWindow = NULL;
  28. static PFNMONITORFROMRECT vpfnMonitorFromRect = NULL;
  29. static PFNMONITORFROMPOINT vpfnMonitorFromPoint = NULL;
  30. static PFNGETMONITORINFO vpfnGetMonitorInfo = NULL;
  31. static PFNANIMATEWINDOW vpfnAnimateWindow = NULL;
  32. static PFNGETPROCESSDEFAULTLAYOUT vpfnGetProcessDefaultLayout = NULL;
  33. static PFNSETLAYOUT vpfnSetLayout = NULL;
  34. /* G E T H L I B U S E R 3 2 */
  35. /*------------------------------------------------------------------------------
  36. ------------------------------------------------------------------------------*/
  37. HINSTANCE GetHLibUser32( void )
  38. {
  39. static HINSTANCE hLibUser32 = NULL;
  40. if (hLibUser32 == NULL) {
  41. hLibUser32 = CUIGetSystemModuleHandle( TEXT("user32.dll") );
  42. }
  43. return hLibUser32;
  44. }
  45. /* G E T H L I B G D U 3 2 */
  46. /*------------------------------------------------------------------------------
  47. ------------------------------------------------------------------------------*/
  48. HINSTANCE GetHLibGdi32( void )
  49. {
  50. static HINSTANCE hLibGdi32 = NULL;
  51. if (hLibGdi32 == NULL) {
  52. hLibGdi32 = CUIGetSystemModuleHandle( TEXT("gdi32.dll") );
  53. }
  54. return hLibGdi32;
  55. }
  56. /* C U I I S U P D A T E L A Y E R E D W I N D O W A V A I L */
  57. /*------------------------------------------------------------------------------
  58. ------------------------------------------------------------------------------*/
  59. BOOL CUIIsUpdateLayeredWindowAvail( void )
  60. {
  61. static BOOL fInitialized = FALSE;
  62. if (!fInitialized) {
  63. HMODULE hmodUser32 = GetHLibUser32();
  64. if (hmodUser32)
  65. vpfnUpdateLayeredWindow = (PFNUPDATELAYEREDWINDOW)GetProcAddress( hmodUser32, TEXT("UpdateLayeredWindow") );
  66. }
  67. return (vpfnUpdateLayeredWindow != NULL);
  68. }
  69. /* C U I U P D A T E L A Y E R E D W I N D O W */
  70. /*------------------------------------------------------------------------------
  71. ------------------------------------------------------------------------------*/
  72. BOOL CUIUpdateLayeredWindow( HWND hwnd, HDC hdcDst, POINT *pptDst, SIZE *psize, HDC hdcSrc, POINT *pptSrc, COLORREF crKey, BLENDFUNCTION *pblend, DWORD dwFlags )
  73. {
  74. if (!CUIIsUpdateLayeredWindowAvail()) {
  75. return FALSE;
  76. }
  77. return vpfnUpdateLayeredWindow( hwnd, hdcDst, pptDst, psize, hdcSrc, pptSrc, crKey, pblend, dwFlags );
  78. }
  79. /* C U I I S M O N I T O R A P I A V A I L */
  80. /*------------------------------------------------------------------------------
  81. ------------------------------------------------------------------------------*/
  82. BOOL CUIIsMonitorAPIAvail( void )
  83. {
  84. static BOOL fInitialized = FALSE;
  85. if (!fInitialized) {
  86. HMODULE hmodUser32 = GetHLibUser32();
  87. if (hmodUser32)
  88. {
  89. vpfnGetMonitorInfo = (PFNGETMONITORINFO)GetProcAddress( hmodUser32, TEXT("GetMonitorInfoA") );
  90. vpfnMonitorFromWindow = (PFNMONITORFROMWINDOW)GetProcAddress( hmodUser32, TEXT("MonitorFromWindow") );
  91. vpfnMonitorFromRect = (PFNMONITORFROMRECT)GetProcAddress( hmodUser32, TEXT("MonitorFromRect") );
  92. vpfnMonitorFromPoint = (PFNMONITORFROMPOINT)GetProcAddress( hmodUser32, TEXT("MonitorFromPoint") );
  93. }
  94. }
  95. return (vpfnGetMonitorInfo != NULL)
  96. && (vpfnMonitorFromWindow != NULL)
  97. && (vpfnMonitorFromRect != NULL)
  98. && (vpfnMonitorFromPoint != NULL);
  99. }
  100. /* C U I G E T M O N I T O R I N F O */
  101. /*------------------------------------------------------------------------------
  102. ------------------------------------------------------------------------------*/
  103. BOOL CUIGetMonitorInfo( HMONITOR hMonitor, LPMONITORINFO lpmi )
  104. {
  105. if (!CUIIsMonitorAPIAvail()) {
  106. return FALSE;
  107. }
  108. return vpfnGetMonitorInfo( hMonitor, lpmi );
  109. }
  110. /* C U I M O N I T O R F R O M W I N D O W */
  111. /*------------------------------------------------------------------------------
  112. ------------------------------------------------------------------------------*/
  113. HMONITOR CUIMonitorFromWindow( HWND hwnd, DWORD dwFlags )
  114. {
  115. if (!CUIIsMonitorAPIAvail()) {
  116. return NULL;
  117. }
  118. return vpfnMonitorFromWindow( hwnd, dwFlags );
  119. }
  120. /* C U I M O N I T O R F R O M R E C T */
  121. /*------------------------------------------------------------------------------
  122. ------------------------------------------------------------------------------*/
  123. HMONITOR CUIMonitorFromRect( LPRECT prc, DWORD dwFlags )
  124. {
  125. if (!CUIIsMonitorAPIAvail()) {
  126. return NULL;
  127. }
  128. return vpfnMonitorFromRect( prc, dwFlags );
  129. }
  130. /* C U I M O N I T O R F R O M P O I N T */
  131. /*------------------------------------------------------------------------------
  132. ------------------------------------------------------------------------------*/
  133. HMONITOR CUIMonitorFromPoint( POINT pt, DWORD dwFlags )
  134. {
  135. if (!CUIIsMonitorAPIAvail()) {
  136. return NULL;
  137. }
  138. return vpfnMonitorFromPoint( pt, dwFlags );
  139. }
  140. /* C U I GET SCREENRECT
  141. /*------------------------------------------------------------------------------
  142. ------------------------------------------------------------------------------*/
  143. void CUIGetScreenRect(POINT pt, RECT *prc)
  144. {
  145. prc->left = 0;
  146. prc->top = 0;
  147. prc->right = GetSystemMetrics( SM_CXSCREEN );
  148. prc->bottom = GetSystemMetrics( SM_CYSCREEN );
  149. if (CUIIsMonitorAPIAvail()) {
  150. HMONITOR hMonitor;
  151. MONITORINFO MonitorInfo;
  152. hMonitor = CUIMonitorFromPoint( pt, MONITOR_DEFAULTTONEAREST );
  153. if (hMonitor != NULL) {
  154. MonitorInfo.cbSize = sizeof(MonitorInfo);
  155. if (CUIGetMonitorInfo( hMonitor, &MonitorInfo )) {
  156. *prc = MonitorInfo.rcMonitor;
  157. }
  158. }
  159. }
  160. return;
  161. }
  162. /* C U I GET WORDARE
  163. /*------------------------------------------------------------------------------
  164. ------------------------------------------------------------------------------*/
  165. void CUIGetWorkAreaRect(POINT pt, RECT *prc)
  166. {
  167. SystemParametersInfo(SPI_GETWORKAREA, 0, prc, FALSE);
  168. if (CUIIsMonitorAPIAvail()) {
  169. HMONITOR hMonitor;
  170. MONITORINFO MonitorInfo;
  171. hMonitor = CUIMonitorFromPoint( pt, MONITOR_DEFAULTTONEAREST );
  172. if (hMonitor != NULL) {
  173. MonitorInfo.cbSize = sizeof(MonitorInfo);
  174. if (CUIGetMonitorInfo( hMonitor, &MonitorInfo )) {
  175. *prc = MonitorInfo.rcWork;
  176. }
  177. }
  178. }
  179. return;
  180. }
  181. /* C U I I S A N I M A T E W I N D O W A V A I L */
  182. /*------------------------------------------------------------------------------
  183. ------------------------------------------------------------------------------*/
  184. BOOL CUIIsAnimateWindowAvail( void )
  185. {
  186. static BOOL fInitialized = FALSE;
  187. if (!fInitialized) {
  188. HMODULE hmodUser32 = GetHLibUser32();
  189. if (hmodUser32)
  190. vpfnAnimateWindow = (PFNANIMATEWINDOW)GetProcAddress( hmodUser32, TEXT("AnimateWindow") );
  191. }
  192. return (vpfnAnimateWindow != NULL);
  193. }
  194. /* C U I A N I M A T E W I N D O W */
  195. /*------------------------------------------------------------------------------
  196. ------------------------------------------------------------------------------*/
  197. BOOL CUIAnimateWindow( HWND hwnd, DWORD dwTime, DWORD dwFlag )
  198. {
  199. if (!CUIIsAnimateWindowAvail()) {
  200. return FALSE;
  201. }
  202. return vpfnAnimateWindow( hwnd, dwTime, dwFlag );
  203. }
  204. //
  205. //
  206. //
  207. BOOL g_fInitUIFBitmapDCs = FALSE;
  208. CBitmapDC *g_phdcSrc = NULL;
  209. CBitmapDC *g_phdcMask = NULL;
  210. CBitmapDC *g_phdcDst = NULL;
  211. void InitUIFUtil()
  212. {
  213. if (!g_phdcSrc)
  214. g_phdcSrc = new CBitmapDC(TRUE);
  215. if (!g_phdcMask)
  216. g_phdcMask = new CBitmapDC(TRUE);
  217. if (!g_phdcDst)
  218. g_phdcDst = new CBitmapDC(TRUE);
  219. if (g_phdcSrc && g_phdcMask && g_phdcDst)
  220. g_fInitUIFBitmapDCs = TRUE;
  221. }
  222. void DoneUIFUtil()
  223. {
  224. if (g_phdcSrc)
  225. delete g_phdcSrc;
  226. g_phdcSrc = NULL;
  227. if (g_phdcMask)
  228. delete g_phdcMask;
  229. g_phdcMask = NULL;
  230. if (g_phdcDst)
  231. delete g_phdcDst;
  232. g_phdcDst = NULL;
  233. g_fInitUIFBitmapDCs = FALSE;
  234. }
  235. /* C U I D R A W T E X T */
  236. /*------------------------------------------------------------------------------
  237. ------------------------------------------------------------------------------*/
  238. int CUIDrawText( HDC hDC, LPCWSTR pwch, int cwch, RECT *prc, UINT uFormat )
  239. {
  240. #ifndef NOFONTLINK
  241. return FLDrawTextW( hDC, pwch, cwch, prc, uFormat );
  242. #else /* NOFONTLINK */
  243. char *pch;
  244. int cch;
  245. int iRet;
  246. if (UIFIsWindowsNT()) {
  247. return DrawTextW( hDC, pwch, cwch, prc, uFormat );
  248. }
  249. if (cwch == -1) {
  250. cwch = StrLenW(pwch);
  251. }
  252. pch = new CHAR[ cwch*2+1 ];
  253. if (pch == NULL) {
  254. return 0;
  255. }
  256. cch = WideCharToMultiByte( CP_ACP, 0, pwch, cwch, pch, cwch*2+1, NULL, NULL );
  257. *(pch + cch) = '\0';
  258. iRet = DrawTextA( hDC, pch, cch, prc, uFormat );
  259. delete pch;
  260. return iRet;
  261. #endif /* NOFONTLINK */
  262. }
  263. /* C U I E X T T E X T O U T */
  264. /*------------------------------------------------------------------------------
  265. ------------------------------------------------------------------------------*/
  266. BOOL CUIExtTextOut( HDC hDC, int x, int y, UINT fuOptions, const RECT *prc, LPCWSTR pwch, UINT cwch, const int *lpDs )
  267. {
  268. #ifndef NOFONTLINK
  269. return FLExtTextOutW( hDC, x, y, fuOptions, prc, pwch, cwch, lpDs );
  270. #else /* NOFONTLINK */
  271. char *pch;
  272. int cch;
  273. BOOL fRet;
  274. if (UIFIsWindowsNT()) {
  275. return ExtTextOutW( hDC, x, y, fuOptions, prc, pwch, cwch, lpDs );
  276. }
  277. if (cwch == -1) {
  278. cwch = StrLenW(pwch);
  279. }
  280. pch = new CHAR[ cwch*2+1 ];
  281. if (pch == NULL) {
  282. return 0;
  283. }
  284. cch = WideCharToMultiByte( CP_ACP, 0, pwch, cwch, pch, cwch*2+1, NULL, NULL );
  285. *(pch + cch) = '\0';
  286. fRet = ExtTextOutA( hDC, x, y, fuOptions, prc, pch, cch, lpDs );
  287. delete pch;
  288. return fRet;
  289. #endif /* NOFONTLINK */
  290. }
  291. /* C U I G E T T E X T E X T E N T P O I N T 3 2 */
  292. /*------------------------------------------------------------------------------
  293. ------------------------------------------------------------------------------*/
  294. extern BOOL CUIGetTextExtentPoint32( HDC hDC, LPCWSTR pwch, int cwch, SIZE *psize )
  295. {
  296. #ifndef NOFONTLINK
  297. return FLGetTextExtentPoint32( hDC, pwch, cwch, psize );
  298. #else /* NOFONTLINK */
  299. char *pch;
  300. int cch;
  301. BOOL fRet;
  302. if (UIFIsWindowsNT()) {
  303. return GetTextExtentPoint32W( hDC, pwch, cwch, psize );
  304. }
  305. if (cwch == -1) {
  306. cwch = StrLenW(pwch);
  307. }
  308. pch = new CHAR[ cwch*2+1 ];
  309. if (pch == NULL) {
  310. return 0;
  311. }
  312. cch = WideCharToMultiByte( CP_ACP, 0, pwch, cwch, pch, cwch*2+1, NULL, NULL );
  313. *(pch + cch) = '\0';
  314. fRet = GetTextExtentPoint32A( hDC, pch, cch, psize );
  315. delete pch;
  316. return fRet;
  317. #endif /* NOFONTLINK */
  318. }
  319. /* C R E A T E D I T H E R B R U S H */
  320. /*------------------------------------------------------------------------------
  321. Create brush of pattern
  322. Returns handle of brush object when suceed, otherwise FALSE.
  323. ------------------------------------------------------------------------------*/
  324. HBRUSH CreateDitherBrush( void )
  325. {
  326. WORD rgwPattern[8] = { 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa };
  327. LOGBRUSH LogBrush;
  328. HBITMAP hBitmap;
  329. HBRUSH hBrush;
  330. hBitmap = CreateBitmap( 8, 8, 1, 1, rgwPattern );
  331. if (hBitmap == NULL) {
  332. return NULL;
  333. }
  334. LogBrush.lbHatch = (LONG_PTR)hBitmap;
  335. LogBrush.lbStyle = BS_PATTERN;
  336. hBrush = CreateBrushIndirect( &LogBrush );
  337. DeleteObject( hBitmap );
  338. return hBrush;
  339. }
  340. //+---------------------------------------------------------------------------
  341. //
  342. // ConvertBlackBKGBitmap
  343. //
  344. //----------------------------------------------------------------------------
  345. HBITMAP ChangeBitmapColor(const RECT *prc, HBITMAP hbmp, COLORREF rgbOld, COLORREF rgbNew)
  346. {
  347. if (!g_fInitUIFBitmapDCs)
  348. return NULL;
  349. int nWidth = prc->right - prc->left;
  350. int nHeight = prc->bottom - prc->top;
  351. DWORD DSPDxax = 0x00E20746;
  352. CSolidBrush cbr(rgbNew);
  353. g_phdcDst->SetDIB(nWidth, nHeight);
  354. g_phdcSrc->SetBitmap(hbmp);
  355. g_phdcMask->SetBitmap(nWidth, nHeight, 1, 1);
  356. BitBlt(*g_phdcDst, 0, 0, nWidth, nHeight, *g_phdcSrc, 0, 0, SRCCOPY);
  357. SelectObject(*g_phdcDst, (HBRUSH)cbr);
  358. SetBkColor(*g_phdcDst, rgbOld);
  359. // BitBlt(*g_phdcMask, 0, 0, nWidth, nHeight, *g_phdcDst, 0, 0, DSPDxax);
  360. BitBlt(*g_phdcMask, 0, 0, nWidth, nHeight, *g_phdcDst, 0, 0, MERGECOPY);
  361. SetBkColor(*g_phdcDst, RGB(255,255,255));
  362. SetTextColor(*g_phdcDst, RGB(0,0,0));
  363. BitBlt(*g_phdcDst, 0, 0, nWidth, nHeight, *g_phdcMask, 0, 0, DSPDxax);
  364. #if 0
  365. BitBlt(*g_phdcTmp, 0, 0, nWidth, nHeight, *g_phdcSrc, 0, 0, SRCCOPY);
  366. BitBlt(*g_phdcTmp, 30, 0, nWidth, nHeight, *g_phdcMask, 0, 0, SRCCOPY);
  367. BitBlt(*g_phdcTmp, 60, 0, nWidth, nHeight, *g_phdcDst, 0, 0, SRCCOPY);
  368. #endif
  369. g_phdcSrc->Uninit();
  370. g_phdcMask->Uninit();
  371. g_phdcDst->Uninit(TRUE);
  372. return g_phdcDst->GetBitmapAndKeep();
  373. }
  374. //+---------------------------------------------------------------------------
  375. //
  376. // ConvertBlackBKGBitmap
  377. //
  378. //----------------------------------------------------------------------------
  379. HBITMAP ConvertBlackBKGBitmap(const RECT *prc, HBITMAP hbmp, HBITMAP hbmpMask, HBRUSH hBr)
  380. {
  381. LOGBRUSH lb;
  382. HBRUSH hbrTemp;
  383. if (!g_fInitUIFBitmapDCs)
  384. return NULL;
  385. if (PtrToUlong(hBr) <= 50)
  386. {
  387. hbrTemp = GetSysColorBrush(PtrToUlong(hBr) - 1);
  388. }
  389. else
  390. {
  391. hbrTemp = hBr;
  392. }
  393. GetObject(hbrTemp, sizeof(lb), &lb);
  394. if ((lb.lbStyle != BS_SOLID) || (lb.lbColor != RGB(0,0,0)))
  395. return NULL;
  396. int nWidth = prc->right - prc->left;
  397. int nHeight = prc->bottom - prc->top;
  398. HBITMAP hbmpChanged;
  399. // hbmpChanged = hbmp;
  400. hbmpChanged = ChangeBitmapColor(prc, hbmp, RGB(0,0,0), RGB(255,255,255));
  401. if (!hbmpChanged)
  402. return NULL;
  403. g_phdcDst->SetDIB(nWidth, nHeight);
  404. g_phdcSrc->SetBitmap(hbmpChanged);
  405. g_phdcMask->SetBitmap(hbmpMask);
  406. RECT rc;
  407. ::SetRect(&rc, 0, 0, nWidth, nHeight);
  408. FillRect( *g_phdcDst, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH));
  409. BitBlt(*g_phdcDst, 0, 0, nWidth, nHeight, *g_phdcMask, 0, 0, SRCINVERT);
  410. BitBlt(*g_phdcDst, 0, 0, nWidth, nHeight, *g_phdcSrc, 0, 0, SRCAND);
  411. #if 0
  412. {
  413. CBitmapDC hdcTmp;
  414. BitBlt(hdcTmp, 0, 30, nWidth, nHeight, *g_phdcSrc, 0, 0, SRCCOPY);
  415. BitBlt(hdcTmp, 30, 30, nWidth, nHeight, *g_phdcMask, 0, 0, SRCCOPY);
  416. BitBlt(hdcTmp, 60, 30, nWidth, nHeight, *g_phdcDst, 0, 0, SRCCOPY);
  417. }
  418. #endif
  419. g_phdcSrc->Uninit();
  420. g_phdcMask->Uninit();
  421. g_phdcDst->Uninit(TRUE);
  422. DeleteObject(hbmpChanged);
  423. return g_phdcDst->GetBitmapAndKeep();
  424. }
  425. //+---------------------------------------------------------------------------
  426. //
  427. // CreateMaskBitmap
  428. //
  429. //----------------------------------------------------------------------------
  430. HBITMAP CreateMaskBmp(const RECT *prc, HBITMAP hbmp, HBITMAP hbmpMask, HBRUSH hbrBk, COLORREF colText, COLORREF colBk)
  431. {
  432. if (!g_fInitUIFBitmapDCs)
  433. return NULL;
  434. int nWidth = prc->right - prc->left;
  435. int nHeight = prc->bottom - prc->top;
  436. HBITMAP hbmpBlk = ConvertBlackBKGBitmap(prc, hbmp, hbmpMask, hbrBk);
  437. if (hbmpBlk)
  438. return hbmpBlk;
  439. g_phdcDst->SetDIB(nWidth, nHeight);
  440. g_phdcSrc->SetBitmap(hbmp);
  441. g_phdcMask->SetBitmap(hbmpMask);
  442. RECT rc;
  443. ::SetRect(&rc, 0, 0, nWidth, nHeight);
  444. COLORREF colTextOld = SetTextColor( *g_phdcDst, colText);
  445. COLORREF colBackOld = SetBkColor( *g_phdcDst, colBk);
  446. FillRect( *g_phdcDst, &rc, hbrBk);
  447. SetTextColor( *g_phdcDst, colTextOld );
  448. SetBkColor( *g_phdcDst, colBackOld );
  449. BitBlt(*g_phdcDst, 0, 0, nWidth, nHeight, *g_phdcMask, 0, 0, SRCAND);
  450. BitBlt(*g_phdcDst, 0, 0, nWidth, nHeight, *g_phdcSrc, 0, 0, SRCINVERT);
  451. g_phdcSrc->Uninit();
  452. g_phdcMask->Uninit();
  453. g_phdcDst->Uninit(TRUE);
  454. return g_phdcDst->GetBitmapAndKeep();
  455. }
  456. //+---------------------------------------------------------------------------
  457. //
  458. // CreateShadowMaskBitmap
  459. //
  460. //----------------------------------------------------------------------------
  461. HBITMAP CreateShadowMaskBmp(RECT *prc, HBITMAP hbmp, HBITMAP hbmpMask, HBRUSH hbrBk, HBRUSH hbrShadow)
  462. {
  463. if (!g_fInitUIFBitmapDCs)
  464. return NULL;
  465. prc->left--;
  466. prc->top--;
  467. int nWidth = prc->right - prc->left;
  468. int nHeight = prc->bottom - prc->top;
  469. CBitmapDC hdcDstShadow(TRUE);
  470. g_phdcDst->SetDIB(nWidth, nHeight);
  471. g_phdcSrc->SetBitmap(hbmp);
  472. g_phdcMask->SetBitmap(hbmpMask);
  473. hdcDstShadow.SetDIB(nWidth, nHeight);
  474. RECT rc;
  475. ::SetRect(&rc, 0, 0, nWidth, nHeight);
  476. FillRect( *g_phdcDst, &rc, hbrBk);
  477. FillRect(hdcDstShadow, &rc, hbrShadow);
  478. BitBlt(hdcDstShadow, 0, 0, nWidth, nHeight, *g_phdcMask, 0, 0, SRCPAINT);
  479. BitBlt(*g_phdcDst, 2, 2, nWidth, nHeight, hdcDstShadow, 0, 0, SRCAND);
  480. BitBlt(*g_phdcDst, 0, 0, nWidth, nHeight, *g_phdcMask, 0, 0, SRCAND);
  481. BitBlt(*g_phdcDst, 0, 0, nWidth, nHeight, *g_phdcSrc, 0, 0, SRCINVERT);
  482. g_phdcSrc->Uninit();
  483. g_phdcMask->Uninit();
  484. g_phdcDst->Uninit(TRUE);
  485. return g_phdcDst->GetBitmapAndKeep();
  486. }
  487. //+---------------------------------------------------------------------------
  488. //
  489. // CreateDisabledBitmap
  490. //
  491. //----------------------------------------------------------------------------
  492. HBITMAP CreateDisabledBitmap(const RECT *prc, HBITMAP hbmpMask, HBRUSH hbrBk, HBRUSH hbrShadow, BOOL fShadow)
  493. {
  494. if (!g_fInitUIFBitmapDCs)
  495. return NULL;
  496. int nWidth = prc->right - prc->left;
  497. int nHeight = prc->bottom - prc->top;
  498. g_phdcDst->SetDIB(nWidth, nHeight);
  499. g_phdcMask->SetBitmap(hbmpMask);
  500. g_phdcSrc->SetDIB(nWidth, nHeight);
  501. RECT rc;
  502. ::SetRect(&rc, 0, 0, nWidth, nHeight);
  503. FillRect( *g_phdcDst, &rc, hbrBk);
  504. FillRect( *g_phdcSrc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH));
  505. BitBlt(*g_phdcSrc, 0, 0, nWidth, nHeight, *g_phdcMask, 0, 0, SRCINVERT);
  506. if (fShadow)
  507. BitBlt(*g_phdcDst, 1, 1, nWidth, nHeight, *g_phdcSrc, 0, 0, SRCPAINT);
  508. else
  509. BitBlt(*g_phdcDst, 0, 0, nWidth, nHeight, *g_phdcSrc, 0, 0, SRCPAINT);
  510. #if 0
  511. BitBlt(*g_phdcTmp, 0, 30, 30, 30, *g_phdcMask, 0, 0, SRCCOPY);
  512. BitBlt(*g_phdcTmp, 30, 30, 30, 30, *g_phdcSrc, 0, 0, SRCCOPY);
  513. BitBlt(*g_phdcTmp, 60, 30, 30, 30, *g_phdcDst, 0, 0, SRCCOPY);
  514. #endif
  515. FillRect( *g_phdcSrc, &rc, hbrShadow);
  516. BitBlt(*g_phdcSrc, 0, 0, nWidth, nHeight, *g_phdcMask, 0, 0, SRCPAINT);
  517. BitBlt(*g_phdcDst, 0, 0, nWidth, nHeight, *g_phdcSrc, 0, 0, SRCAND);
  518. #if 0
  519. BitBlt(*g_phdcTmp, 0, 60, 30, 30, *g_phdcMask, 0, 0, SRCCOPY);
  520. BitBlt(*g_phdcTmp, 30, 60, 30, 30, *g_phdcSrc, 0, 0, SRCCOPY);
  521. BitBlt(*g_phdcTmp, 60, 60, 30, 30, *g_phdcDst, 0, 0, SRCCOPY);
  522. #endif
  523. g_phdcSrc->Uninit();
  524. g_phdcMask->Uninit();
  525. g_phdcDst->Uninit(TRUE);
  526. return g_phdcDst->GetBitmapAndKeep();
  527. }
  528. //+---------------------------------------------------------------------------
  529. //
  530. // CUIDrawState
  531. //
  532. //----------------------------------------------------------------------------
  533. BOOL CUIDrawState(HDC hdc, HBRUSH hbr, DRAWSTATEPROC lpOutputFunc, LPARAM lData, WPARAM wData, int x, int y, int cx, int cy, UINT fuFlags)
  534. {
  535. BOOL bRet;
  536. POINT ptOldOrg;
  537. BOOL fRetVal;
  538. // we have to do this viewport trick to get around the fact that
  539. // DrawState has a GDI bug in NT4, such that it handles offsets improperly.
  540. // so we do the offset by hand.
  541. fRetVal = SetViewportOrgEx( hdc, 0, 0, &ptOldOrg );
  542. Assert( fRetVal );
  543. bRet = DrawState(hdc,
  544. hbr,
  545. lpOutputFunc,
  546. lData,
  547. wData,
  548. x + ptOldOrg.x,
  549. y + ptOldOrg.y,
  550. cx,
  551. cy,
  552. fuFlags);
  553. fRetVal = SetViewportOrgEx( hdc, ptOldOrg.x, ptOldOrg.y, NULL );
  554. Assert( fRetVal );
  555. return bRet;
  556. }
  557. //+---------------------------------------------------------------------------
  558. //
  559. // DrawMaskBitmapOnDC
  560. //
  561. //----------------------------------------------------------------------------
  562. void DrawMaskBmpOnDC(HDC hdc, const RECT *prc, HBITMAP hbmp, HBITMAP hbmpMask)
  563. {
  564. if (!g_fInitUIFBitmapDCs)
  565. return;
  566. int nWidth = prc->right - prc->left;
  567. int nHeight = prc->bottom - prc->top;
  568. g_phdcDst->SetDIB(nWidth, nHeight);
  569. g_phdcSrc->SetBitmap(hbmp);
  570. g_phdcMask->SetBitmap(hbmpMask);
  571. RECT rc;
  572. ::SetRect(&rc, 0, 0, nWidth, nHeight);
  573. BitBlt(*g_phdcDst, 0, 0, nWidth, nHeight, hdc, prc->left, prc->top, SRCCOPY);
  574. BitBlt(*g_phdcDst, 0, 0, nWidth, nHeight, *g_phdcMask, 0, 0, SRCAND);
  575. BitBlt(*g_phdcDst, 0, 0, nWidth, nHeight, *g_phdcSrc, 0, 0, SRCINVERT);
  576. BitBlt(hdc, prc->left, prc->top, nWidth, nHeight, *g_phdcDst, 0, 0, SRCCOPY);
  577. g_phdcSrc->Uninit();
  578. g_phdcMask->Uninit();
  579. g_phdcDst->Uninit();
  580. }
  581. /* C U I G E T I C O N S I Z E */
  582. /*------------------------------------------------------------------------------
  583. get icon image size
  584. ------------------------------------------------------------------------------*/
  585. BOOL CUIGetIconSize( HICON hIcon, SIZE *psize )
  586. {
  587. ICONINFO IconInfo;
  588. BITMAP bmp;
  589. Assert( hIcon != NULL );
  590. Assert( psize != NULL );
  591. if (!GetIconInfo( hIcon, &IconInfo )) {
  592. return FALSE;
  593. }
  594. GetObject( IconInfo.hbmColor, sizeof(bmp), &bmp );
  595. DeleteObject( IconInfo.hbmColor );
  596. DeleteObject( IconInfo.hbmMask );
  597. psize->cx = bmp.bmWidth;
  598. psize->cy = bmp.bmHeight;
  599. return TRUE;
  600. }
  601. /* C U I G E T B I T M A P S I Z E */
  602. /*------------------------------------------------------------------------------
  603. get bitmap image size
  604. ------------------------------------------------------------------------------*/
  605. BOOL CUIGetBitmapSize( HBITMAP hBmp, SIZE *psize )
  606. {
  607. BITMAP bmp;
  608. Assert( hBmp != NULL );
  609. Assert( psize != NULL );
  610. if (GetObject( hBmp, sizeof(bmp), &bmp ) == 0) {
  611. return FALSE;
  612. }
  613. psize->cx = bmp.bmWidth;
  614. psize->cy = bmp.bmHeight;
  615. return TRUE;
  616. }
  617. //+---------------------------------------------------------------------------
  618. //
  619. // CUIGetIconBitmaps
  620. //
  621. //----------------------------------------------------------------------------
  622. BOOL CUIGetIconBitmaps(HICON hIcon, HBITMAP *phbmp, HBITMAP *phbmpMask, SIZE *psize)
  623. {
  624. if (!g_fInitUIFBitmapDCs)
  625. return FALSE;
  626. SIZE size;
  627. if (psize)
  628. size = *psize;
  629. else if (!CUIGetIconSize( hIcon, &size))
  630. return FALSE;
  631. g_phdcSrc->SetDIB(size.cx, size.cy);
  632. g_phdcMask->SetBitmap(size.cx, size.cy, 1, 1);
  633. RECT rc = {0, 0, size.cx, size.cy};
  634. FillRect(*g_phdcSrc, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH));
  635. DrawIconEx(*g_phdcSrc, 0, 0, hIcon, size.cx, size.cy, 0, NULL, DI_NORMAL);
  636. DrawIconEx(*g_phdcMask, 0, 0, hIcon, size.cx, size.cy, 0, NULL, DI_MASK);
  637. g_phdcSrc->Uninit(TRUE);
  638. g_phdcMask->Uninit(TRUE);
  639. *phbmp = g_phdcSrc->GetBitmapAndKeep();
  640. *phbmpMask = g_phdcMask->GetBitmapAndKeep();
  641. return TRUE;
  642. }
  643. //+---------------------------------------------------------------------------
  644. //
  645. // CUIGetProcessDefaultLayout
  646. //
  647. //----------------------------------------------------------------------------
  648. DWORD CUIProcessDefaultLayout()
  649. {
  650. static BOOL fInitialized = FALSE;
  651. DWORD dw;
  652. if (!fInitialized) {
  653. HMODULE hmodUser32 = GetHLibUser32();
  654. if (hmodUser32)
  655. vpfnGetProcessDefaultLayout = (PFNGETPROCESSDEFAULTLAYOUT)GetProcAddress( hmodUser32, TEXT("GetProcessDefaultLayout") );
  656. fInitialized = TRUE;
  657. }
  658. if (!vpfnGetProcessDefaultLayout)
  659. return 0;
  660. if (!vpfnGetProcessDefaultLayout(&dw))
  661. return 0;
  662. return dw;
  663. }
  664. //+---------------------------------------------------------------------------
  665. //
  666. // CUISetLayout
  667. //
  668. //----------------------------------------------------------------------------
  669. DWORD CUISetLayout(HDC hdc, DWORD dw)
  670. {
  671. static BOOL fInitialized = FALSE;
  672. if (!fInitialized) {
  673. HMODULE hmodGdi32 = GetHLibGdi32();
  674. if (hmodGdi32)
  675. vpfnSetLayout = (PFNSETLAYOUT)GetProcAddress( hmodGdi32, TEXT("SetLayout") );
  676. fInitialized = TRUE;
  677. }
  678. if (!vpfnSetLayout)
  679. return 0;
  680. return vpfnSetLayout(hdc, dw);
  681. }
  682. //+---------------------------------------------------------------------------
  683. //
  684. // CUISetLayout
  685. //
  686. //----------------------------------------------------------------------------
  687. HBITMAP CUIMirrorBitmap(HBITMAP hbmOrg, HBRUSH hbrBk)
  688. {
  689. if (!g_fInitUIFBitmapDCs)
  690. return NULL;
  691. BITMAP bm;
  692. if (!GetObject(hbmOrg, sizeof(BITMAP), &bm))
  693. {
  694. return NULL;
  695. }
  696. g_phdcSrc->SetBitmap(hbmOrg);
  697. g_phdcDst->SetDIB(bm.bmWidth, bm.bmHeight);
  698. g_phdcMask->SetDIB(bm.bmWidth, bm.bmHeight);
  699. RECT rc;
  700. ::SetRect(&rc, 0, 0, bm.bmWidth, bm.bmHeight);
  701. FillRect( *g_phdcDst, &rc, hbrBk);
  702. CUISetLayout(*g_phdcMask, LAYOUT_RTL);
  703. BitBlt(*g_phdcMask, 0, 0, bm.bmWidth, bm.bmHeight, *g_phdcSrc, 0, 0, SRCCOPY);
  704. CUISetLayout(*g_phdcMask, 0);
  705. //
  706. // The offset by 1 is to solve the off-by-one problem.
  707. //
  708. BitBlt(*g_phdcDst, 0, 0, bm.bmWidth, bm.bmHeight, *g_phdcMask, 1, 0, SRCCOPY);
  709. g_phdcSrc->Uninit();
  710. g_phdcMask->Uninit();
  711. g_phdcDst->Uninit(TRUE);
  712. return g_phdcDst->GetBitmapAndKeep();
  713. }
  714. //+---------------------------------------------------------------------------
  715. //
  716. // CUICicSystemModulePath
  717. //
  718. //----------------------------------------------------------------------------
  719. class CUICicSystemModulePath
  720. {
  721. public:
  722. CUICicSystemModulePath()
  723. {
  724. m_szPath[0] = TEXT('\0');
  725. m_uRet = 0;
  726. }
  727. UINT Init(LPCTSTR lpModuleName)
  728. {
  729. m_uRet = GetSystemDirectory(m_szPath, ARRAYSIZE(m_szPath));
  730. if (m_uRet)
  731. {
  732. if (m_szPath[m_uRet - 1] != TEXT('\\'))
  733. {
  734. m_szPath[m_uRet] = TEXT('\\');
  735. m_uRet++;
  736. }
  737. UINT uLength = lstrlen(lpModuleName);
  738. if (ARRAYSIZE(m_szPath) - m_uRet > uLength)
  739. {
  740. lstrcpyn(&m_szPath[m_uRet], lpModuleName, ARRAYSIZE(m_szPath) - m_uRet);
  741. m_uRet += uLength;
  742. }
  743. else
  744. m_uRet = 0;
  745. }
  746. return m_uRet;
  747. }
  748. LPTSTR GetPath()
  749. {
  750. return m_szPath;
  751. }
  752. private:
  753. TCHAR m_szPath[MAX_PATH + 1];
  754. UINT m_uRet;
  755. };
  756. //+---------------------------------------------------------------------------
  757. //
  758. // CUIGetSystemModuleHandle
  759. //
  760. //----------------------------------------------------------------------------
  761. HMODULE CUIGetSystemModuleHandle(LPCTSTR lpModuleName)
  762. {
  763. CUICicSystemModulePath path;
  764. if (!path.Init(lpModuleName))
  765. return NULL;
  766. return GetModuleHandle(path.GetPath());
  767. }
  768. //+---------------------------------------------------------------------------
  769. //
  770. // CUILoadSystemModuleHandle
  771. //
  772. //----------------------------------------------------------------------------
  773. HMODULE CUILoadSystemModuleHandle(LPCTSTR lpModuleName)
  774. {
  775. CUICicSystemModulePath path;
  776. if (!path.Init(lpModuleName))
  777. return NULL;
  778. return LoadLibrary(path.GetPath());
  779. }