Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

wmicon.c

Go to the documentation of this file.
00001 /***************************************************************************\ 00002 * Module Name: wmicon.c 00003 * 00004 * Icon Drawing Routines 00005 * 00006 * Copyright (c) 1985 - 1999, Microsoft Corporation 00007 * 00008 * 22-Jan-1991 MikeKe from win30 00009 * 13-Jan-1994 JohnL rewrote from Chicago (m5) 00010 \***************************************************************************/ 00011 00012 #include "precomp.h" 00013 #pragma hdrstop 00014 00015 #define SetBestStretchMode(hdc, bpp, fHT) \ 00016 GreSetStretchBltMode(hdc, \ 00017 (fHT ? HALFTONE : \ 00018 ((bpp) == 1 ? BLACKONWHITE : COLORONCOLOR))) 00019 00020 #define GetCWidth(cxOrg, lrF, cxDes) \ 00021 (cxOrg ? cxOrg : ((lrF & DI_DEFAULTSIZE) ? SYSMET(CXICON) : cxDes)) 00022 00023 #define GetCHeight(cyOrg, lrF, cyDes) \ 00024 (cyOrg ? cyOrg : ((lrF & DI_DEFAULTSIZE) ? SYSMET(CYICON) : cyDes)) 00025 00026 /***************************************************************************\ 00027 * BltIcon 00028 * 00029 * 00030 \***************************************************************************/ 00031 00032 BOOL BltIcon( 00033 HDC hdc, 00034 int x, 00035 int y, 00036 int cx, 00037 int cy, 00038 HDC hdcSrc, 00039 PCURSOR pcur, 00040 BOOL fMask, 00041 LONG rop) 00042 { 00043 HBITMAP hbmpSave; 00044 HBITMAP hbmpUse; 00045 LONG rgbText; 00046 LONG rgbBk; 00047 int nMode; 00048 00049 /* 00050 * Setup the DC for drawing 00051 */ 00052 hbmpUse = (fMask || !pcur->hbmColor ? pcur->hbmMask : pcur->hbmColor); 00053 00054 rgbBk = GreSetBkColor(hdc, 0x00FFFFFFL); 00055 rgbText = GreSetTextColor(hdc, 0x00000000L); 00056 nMode = SetBestStretchMode(hdc, pcur->bpp, FALSE); 00057 00058 hbmpSave = GreSelectBitmap(hdcSrc, hbmpUse); 00059 00060 /* 00061 * Do the output to the surface. By passing in (-1) as the background 00062 * color, we are telling GDI to use the background-color already set 00063 * in the DC. 00064 */ 00065 GreStretchBlt(hdc, 00066 x, 00067 y, 00068 cx, 00069 cy, 00070 hdcSrc, 00071 0, 00072 (fMask || pcur->hbmColor ? 0 : pcur->cy / 2), 00073 pcur->cx, 00074 pcur->cy / 2, 00075 rop, 00076 (COLORREF)-1); 00077 00078 GreSetStretchBltMode(hdc, nMode); 00079 GreSetTextColor(hdc, rgbText); 00080 GreSetBkColor(hdc, rgbBk); 00081 00082 GreSelectBitmap(hdcSrc, hbmpSave); 00083 00084 return TRUE; 00085 } 00086 00087 /***************************************************************************\ 00088 * DrawIconEx 00089 * 00090 * Draws icon in desired size. 00091 * 00092 \***************************************************************************/ 00093 BOOL _DrawIconEx( 00094 HDC hdc, 00095 int x, 00096 int y, 00097 PCURSOR pcur, 00098 int cx, 00099 int cy, 00100 UINT istepIfAniCur, 00101 HBRUSH hbr, 00102 UINT diFlags) 00103 { 00104 BOOL fSuccess = FALSE; 00105 00106 /* 00107 * If this is an animated cursor, just grab the ith frame and use it 00108 * for drawing. 00109 */ 00110 if (pcur->CURSORF_flags & CURSORF_ACON) { 00111 00112 if ((int)istepIfAniCur >= ((PACON)pcur)->cicur) { 00113 RIPERR0(ERROR_INVALID_PARAMETER, RIP_WARNING, "DrawIconEx, icon step out of range."); 00114 goto Done; 00115 } 00116 00117 pcur = ((PACON)pcur)->aspcur[((PACON)pcur)->aicur[istepIfAniCur]]; 00118 } 00119 00120 /* 00121 * Setup defaults. 00122 */ 00123 cx = GetCWidth(cx, diFlags, pcur->cx); 00124 cy = GetCHeight(cy, diFlags, (pcur->cy / 2)); 00125 00126 if (hbr) { 00127 00128 HBITMAP hbmpT = NULL; 00129 HDC hdcT; 00130 HBITMAP hbmpOld; 00131 POLYPATBLT PolyData; 00132 00133 if (hdcT = GreCreateCompatibleDC(hdc)) { 00134 00135 if (hbmpT = GreCreateCompatibleBitmap(hdc, cx, cy)) { 00136 POINT pt; 00137 BOOL bRet; 00138 00139 hbmpOld = GreSelectBitmap(hdcT, hbmpT); 00140 00141 /* 00142 * Set new dc's brush origin in same relative 00143 * location as passed-in dc's. 00144 */ 00145 bRet = GreGetBrushOrg(hdc, &pt); 00146 /* 00147 * Bug 292396 - joejo 00148 * Stop overactive asserts by replacing with RIPMSG. 00149 */ 00150 if (bRet != TRUE) { 00151 RIPMSG0(RIP_WARNING, "DrawIconEx, GreGetBrushOrg failed."); 00152 } 00153 00154 bRet = GreSetBrushOrg(hdcT, pt.x, pt.y, NULL); 00155 if (bRet != TRUE) { 00156 RIPMSG0(RIP_WARNING, "DrawIconEx, GreSetBrushOrg failed."); 00157 } 00158 00159 PolyData.x = 0; 00160 PolyData.y = 0; 00161 PolyData.cx = cx; 00162 PolyData.cy = cy; 00163 PolyData.BrClr.hbr = hbr; 00164 00165 bRet = GrePolyPatBlt(hdcT, PATCOPY, &PolyData, 1, PPB_BRUSH); 00166 if (bRet != TRUE) { 00167 RIPMSG0(RIP_WARNING, "DrawIconEx, GrePolyPatBlt failed."); 00168 } 00169 00170 /* 00171 * Output the image to the temporary memoryDC. 00172 */ 00173 BltIcon(hdcT, 0, 0, cx, cy, ghdcMem, pcur, TRUE, SRCAND); 00174 BltIcon(hdcT, 0, 0, cx, cy, ghdcMem, pcur, FALSE, SRCINVERT); 00175 00176 /* 00177 * Blt the bitmap to the original DC. 00178 */ 00179 GreBitBlt(hdc, x, y, cx, cy, hdcT, 0, 0, SRCCOPY, (COLORREF)-1); 00180 00181 GreSelectBitmap(hdcT, hbmpOld); 00182 00183 bRet = GreDeleteObject(hbmpT); 00184 if (bRet != TRUE) { 00185 RIPMSG0(RIP_WARNING, "DrawIconEx, GreDeleteObject failed. Possible Leak"); 00186 } 00187 00188 fSuccess = TRUE; 00189 } 00190 00191 GreDeleteDC(hdcT); 00192 } 00193 00194 } else { 00195 00196 if (diFlags & DI_MASK) { 00197 00198 BltIcon(hdc, 00199 x, 00200 y, 00201 cx, 00202 cy, 00203 ghdcMem, 00204 pcur, 00205 TRUE, 00206 ((diFlags & DI_IMAGE) ? SRCAND : SRCCOPY)); 00207 } 00208 00209 if (diFlags & DI_IMAGE) { 00210 00211 BltIcon(hdc, 00212 x, 00213 y, 00214 cx, 00215 cy, 00216 ghdcMem, 00217 pcur, 00218 FALSE, 00219 ((diFlags & DI_MASK) ? SRCINVERT : SRCCOPY)); 00220 } 00221 00222 fSuccess = TRUE; 00223 } 00224 00225 Done: 00226 00227 return fSuccess; 00228 }

Generated on Sat May 15 19:42:26 2004 for test by doxygen 1.3.7