forked from lsdev/LiteStep
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphics.cpp
More file actions
executable file
·712 lines (598 loc) · 24.2 KB
/
graphics.cpp
File metadata and controls
executable file
·712 lines (598 loc) · 24.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// This is a part of the Litestep Shell source code.
//
// Copyright (C) 1997-2015 LiteStep Development Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "png_support.h"
#include "../utility/core.hpp"
#include <algorithm>
#include "../utility/stringutility.h"
static void TransparentBltLSWorker(
HDC hdcDst, int nWidth, int nHeight,
HDC hdcSrc, int nXSrc, int nYSrc,
COLORREF colorTransparent);
//
// Since the transparent color for all LiteStep modules should be 0xFF00FF and
// we are going to assume a tolerance of 0x000000, we can ignore the clrTransp<
10BC0
/div>
// and clrTolerence parameter and hard code the values for the High and Low RGB
// bytes The orginial code is commented out, if a module needs the removed
// functionality, it should implement this function with the commented out code.
HRGN BitmapToRegion(
HBITMAP hbm,
COLORREF clrTransp, COLORREF clrTolerance,
int xoffset, int yoffset)
{
// start with a completely transparent rgn
// this is more correct as no bmp, should render a transparent background
HRGN hRgn = CreateRectRgn(0, 0, 0, 0);
if (hbm)
{
// create a dc for the 32 bit dib
HDC hdcMem = CreateCompatibleDC(NULL);
if (hdcMem)
{
VOID *pbits32;
HBITMAP hbm32;
BITMAP bm;
// get the size
GetObject(hbm, sizeof(BITMAP), &bm);
BITMAPINFOHEADER bmpInfo32;
bmpInfo32.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo32.biWidth = bm.bmWidth;
bmpInfo32.biHeight = bm.bmHeight;
bmpInfo32.biPlanes = 1;
bmpInfo32.biBitCount = 32;
bmpInfo32.biCompression = BI_RGB;
bmpInfo32.biSizeImage = 0;
bmpInfo32.biXPelsPerMeter = 0;
bmpInfo32.biYPelsPerMeter = 0;
bmpInfo32.biClrUsed = 0;
bmpInfo32.biClrImportant = 0;
hbm32 = CreateDIBSection(hdcMem, (BITMAPINFO*)&bmpInfo32,
DIB_RGB_COLORS, &pbits32, NULL, 0);
if (hbm32)
{
HBITMAP hbmOld32 = (HBITMAP)SelectObject(hdcMem, hbm32);
// Create a DC just to copy the bitmap into the memory D
HDC hdcTmp = CreateCompatibleDC(hdcMem);
if (hdcTmp)
{
// Get how many bytes per row we have for the bitmap bits
// (rounded up to 32 bits)
BITMAP bm32;
GetObject(hbm32, sizeof(bm32), &bm32);
while (bm32.bmWidthBytes % 4)
{
++bm32.bmWidthBytes;
}
#if defined(LS_COMPAT_TRANSPTOL)
// get the limits for the colors
BYTE clrHiR = (0xff - GetRValue(clrTolerance)) > GetRValue(clrTransp) ?
GetRValue(clrTransp) + GetRValue(clrTolerance) : 0xff;
BYTE clrHiG = (0xff - GetGValue(clrTolerance)) > GetGValue(clrTransp) ?
GetGValue(clrTransp) + GetGValue(clrTolerance) : 0xff;
BYTE clrHiB = (0xff - GetBValue(clrTolerance)) > GetBValue(clrTransp) ?
GetBValue(clrTransp) + GetBValue(clrTolerance) : 0xff;
BYTE clrLoR = GetRValue(clrTolerance) < GetRValue(clrTransp) ?
GetRValue(clrTransp) - GetRValue(clrTolerance) : 0x00;
BYTE clrLoG = GetGValue(clrTolerance) < GetGValue(clrTransp) ?
GetGValue(clrTransp) - GetGValue(clrTolerance) : 0x00;
BYTE clrLoB = GetBValue(clrTolerance) < GetBValue(clrTransp) ?
GetBValue(clrTransp) - GetBValue(clrTolerance) : 0x00;
#endif // LS_COMPAT_TRANSPTOL
// Copy the bitmap into the memory D
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcTmp, hbm);
BitBlt(hdcMem, 0, 0, bm.bmWidth, bm.bmHeight,
hdcTmp, 0, 0, SRCCOPY);
// Scan each bitmap row from bottom to top
// (the bitmap is inverted vertically)
#if defined(LS_COMPAT_TRANSPTOL)
BYTE *p;
#else
DWORD *p;
#endif // LS_COMPAT_TRANSPTOL
BYTE *p32 = (BYTE *)bm32.bmBits + \
(bm32.bmHeight - 1) * bm32.bmWidthBytes;
int y = 0;
while (y < bm.bmHeight)
{
int x = 0, x0;
while (x < bm.bmWidth)
{
// loop through all transparent pixels...
while (x < bm.bmWidth)
{
#if defined(LS_COMPAT_TRANSPTOL)
p = p32 + 4 * x;
// if the pixel is non-transparent, then break
if (*p < clrLoB || *p > clrHiB)
{
break;
}
++p;
if (*p < clrLoG || *p > clrHiG)
{
break;
}
++p;
if (*p < clrLoR || *p > clrHiR)
{
break;
}
#else
p = (DWORD*)(p32 + 4 * x);
if (*p != 0xFF00FF)
{
break;
}
#endif // LS_COMPAT_TRANSPTOL
++x;
}
// save first non transparent pixel offset
x0 = x;
// loop through all non transparent pixels
while (x < bm.bmWidth)
{
#if defined(LS_COMPAT_TRANSPTOL)
p = p32 + 4 * x;
// if the pixel is transparent, then break
if (*p >= clrLoB && *p <= clrHiB)
{
++p;
if (*p >= clrLoG && *p <= clrHiG)
{
++p;
if (*p >= clrLoR && *p <= clrHiR)
{
break;
}
}
}
#else
p = (DWORD*)(p32 + 4 * x);
if (*p == 0xFF00FF)
{
break;
}
#endif // LS_COMPAT_TRANSPTOL
++x;
}
// if found one or more non-transparent pixels in a
// row, add them to the rgn...
if ((x - x0) > 0)
{
HRGN hTempRgn = CreateRectRgn(
x0 + xoffset, y + yoffset,
x + xoffset, y + 1 + yoffset);
CombineRgn(hRgn, hRgn, hTempRgn, RGN_OR);
DeleteObject(hTempRgn);
}
++x;
}
++y;
p32 -= bm32.bmWidthBytes;
}
// Clean up
SelectObject(hdcTmp, hbmOld);
DeleteDC(hdcTmp);
}
SelectObject(hdcMem, hbmOld32);
DeleteObject(hbm32);
}
DeleteDC(hdcMem);
}
}
return hRgn;
}
//
// HBITMAP LoadLSImageW(LPCWSTR pwzImage, LPCWSTR pwzFile)
//
// Takes strings of the form:
// File.bmp
// .extract
// .extract=file.exe[,3]
HBITMAP LoadLSImageW(LPCWSTR pwzImage, LPCWSTR pwzFile)
{
HBITMAP hbmReturn = NULL;
if (pwzImage != NULL)
{
if (_wcsicmp(pwzImage, L".none") != 0)
{
wchar_t wzImage[MAX_PATH];
StringCchCopyW(wzImage, _countof(wzImage), pwzImage);
// Bitmap merging by Thedd
// Thedd - pic1.bmp|pic2.bmp merges the images. Works recursively,
// so pic1.bmp|.extract=whatever.dll,3|pic2.bmp also works etc...
// bitmap merging by grd
LPWSTR pszSecondImage = wcschr(wzImage, L'|');
if (pszSecondImage)
{
HDC hdcFirst, hdcSecond, hdcResult;
HBITMAP hbmFirst, hbmFirstOld;
HBITMAP hbmSecond, hbmSecondOld;
HBITMAP hbmResult, hbmResultOld;
HBRUSH hbrTransparent;
RECT rc;
int wdtFirst, hgtFirst;
int wdtSecond, hgtSecond;
int wdtResult, hgtResult;
// get the position after the [|] character
*pszSecondImage = '\0';
++pszSecondImage;
// load the two bitmaps
hbmFirst = LoadLSImageW(wzImage, pwzFile);
hbmSecond = LoadLSImageW(pszSecondImage, pwzFile);
// if the second one is NULL, then there's no merging to do and
if (hbmSecond != NULL)
{
// create mem dcs for the bitmaps
hdcFirst = CreateCompatibleDC(NULL);
hdcSecond = CreateCompatibleDC(NULL);
// select the bitmaps
hbmFirstOld = (HBITMAP)SelectObject(hdcFirst, hbmFirst);
hbmSecondOld = (HBITMAP)SelectObject(hdcSecond, hbmSecond);
// get the bitmap sizes..
GetLSBitmapSize(hbmFirst, &wdtFirst, &hgtFirst);
GetLSBitmapSize(hbmSecond, &wdtSecond, &hgtSecond);
// in earlier version of bitmap merge, those were painted on
// to each other now let's paint both images to a new one
// and we support different sized images!! therefore:
wdtResult = std::max(wdtFirst, wdtSecond);
hgtResult = std::max(hgtFirst, hgtSecond);
// create another dc, compatible with second dc
hdcResult = CreateCompatibleDC(hdcSecond);
// create a new bitmap for the new dc and select it
hbmResult = CreateCompatibleBitmap(hdcSecond,
wdtResult, hgtResult);
hbmResultOld = (HBITMAP)SelectObject(hdcResult, hbmResult);
rc.top = 0;
rc.left = 0;
rc.right = wdtResult;
rc.bottom = hgtResult;
// paint the background in transparent color...
hbrTransparent = CreateSolidBrush(RGB(255, 0, 255));
FillRect(hdcResult, &rc, hbrTransparent);
DeleteObject(hbrTransparent);
// first "standard blit" the second image into the new one:
BitBlt(hdcResult, (wdtResult - wdtSecond) / 2,
(hgtResult - hgtSecond) / 2, wdtSecond, hgtSecond,
hdcSecond, 0, 0, SRCCOPY);
// Secondly "tranparent blit" the first image over the
// second one Since TransparentBltLS double buffers the
// painting to reduce flicker and we are using only memory
// DC's in this function, we will just call
// TransparentBltLSWorker and shave off a few BitBlt calls
TransparentBltLSWorker(hdcResult, wdtFirst, hgtFirst,
hdcFirst, 0, 0, RGB(255, 0, 255));
// deselect the bitmap from the dc and delete the dc to get
// the image
SelectObject(hdcResult, hbmResultOld);
DeleteDC(hdcResult);
// delete all used objects
SelectObject(hdcFirst, hbmFirstOld);
DeleteObject(hbmFirst);
DeleteDC(hdcFirst);
SelectObject(hdcSecond, hbmSecondOld);
DeleteObject(hbmSecond);
DeleteDC(hdcSecond);
hbmReturn = hbmResult;
}
else
{
hbmReturn = hbmFirst;
}
}
else
{
if (!_wcsnicmp(wzImage, L".extract", 8 /*wcslen(L".extract")*/))
{
HICON hIcon = NULL;
hIcon = LoadLSIconW(wzImage, pwzFile);
if (hIcon)
{
hbmReturn = BitmapFromIcon(hIcon);
DestroyIcon(hIcon);
}
}
else
{
// Append the image name to the LiteStep image path and
// attempt to load the image.
wchar_t wzExpandedImage[MAX_PATH];
VarExpansionExW(wzExpandedImage, wzImage, _countof(wzExpandedImage));
LSGetImagePathW(wzImage, _countof(wzImage));
PathAppendW(wzImage, wzExpandedImage);
if (PathMatchSpecW(wzImage, L"*.png"))
{
hbmReturn = LoadFromPNG(wzImage);
}
else
{
hbmReturn = (HBITMAP)LoadImageW(
NULL, wzImage, IMAGE_BITMAP, 0, 0,
LR_DEFAULTCOLOR | LR_LOADFROMFILE);
}
// If that fails, treat the image as a fully qualified path
// and try loading it
if (hbmReturn == NULL)
{
if (PathMatchSpecW(wzExpandedImage, L"*.png"))
{
hbmReturn = LoadFromPNG(wzExpandedImage);
}
else
{
hbmReturn = (HBITMAP)LoadImageW(
NULL, wzExpandedImage, IMAGE_BITMAP, 0, 0,
LR_DEFAULTCOLOR | LR_LOADFROMFILE);
}
}
}
}
}
}
return hbmReturn;
}
//
// LoadLSImageA
//
HBITMAP LoadLSImageA(LPCSTR pszImage, LPCSTR pszFile)
{
return LoadLSImageW(
std::unique_ptr<wchar_t>(WCSFromMBS(pszImage)).get(),
std::unique_ptr<wchar_t>(WCSFromMBS(pszFile)).get()
);
}
//
// BitmapFromIcon(HICON hIcon)
//
// Creates a 64x64 bitmap of an icon, with pink in the transparent regions.
HBITMAP BitmapFromIcon(HICON hIcon)
{
ICONINFO infoIcon;
if (GetIconInfo(hIcon, &infoIcon))
{
HDC hDC;
HBITMAP hOldBMP;
HBRUSH hBrush;
hDC = CreateCompatibleDC(NULL);
hOldBMP = (HBITMAP)SelectObject(hDC, infoIcon.hbmColor);
hBrush = CreateSolidBrush(RGB (255, 0, 255));
DrawIconEx(hDC, 0, 0, hIcon, 0, 0, 0, hBrush, DI_NORMAL);
DeleteObject(hBrush);
DeleteObject(infoIcon.hbmMask);
SelectObject(hDC, hOldBMP);
DeleteDC(hDC);
return infoIcon.hbmColor;
}
return NULL;
}
//
// LoadLSIconW(LPCWSTR pwzIconPath, LPCWSTR pwzFile)
//
// Takes strings of the form:
// File.ico
// libary.icl,3 <- libary extraction in imagesfolder
// c:\path\ <- icon extraction for path out of desktop.ini
// .extract
// .extract=file.exe[,3] ... and returns an icon
HICON LoadLSIconW(LPCWSTR pwzIconPath, LPCWSTR pwzFile)
{
HICON hIcon = NULL;
if (pwzIconPath != NULL)
{
if (_wcsicmp(pwzIconPath, L".none") != 0)
{
wchar_t wzIconPath[MAX_PATH];
wchar_t wzIconLSImagePath[MAX_PATH];
LPWSTR pwzIconFile = (LPWSTR)pwzIconPath;
int nIcon = 0;
// here comes a large block which does nothing but turning it into
// the form <absolute path>[,<iconIndex>]
// if .extract but nothing else is there...
// then take the file specified as an icon (could probably be done
// earlier, but anyhow)
if (_wcsicmp(pwzIconPath, L".extract") == 0)
{
pwzIconFile = (LPWSTR)pwzFile;
}
else if (_wcsnicmp(pwzIconPath, L".extract=", 9) == 0)
{
// remove ".extract=" (as we won't use it anyway)
pwzIconFile = (LPWSTR)pwzIconPath + 9;
}
VarExpansionExW(wzIconPath, pwzIconFile, _countof(wzIconPath));
if (PathIsRelativeW(wzIconPath))
{
LSGetImagePathW(wzIconLSImagePath, _countof(wzIconLSImagePath));
PathAppendW(wzIconLSImagePath, wzIconPath);
pwzIconFile = wzIconLSImagePath;
}
else
{
pwzIconFile = wzIconPath;
}
// large block ends here, now time to separate path and index (if we
// have an index)
nIcon = PathParseIconLocationW(pwzIconFile);
// now we have the two vars we would like, and the loading can begin
// well not really, if it's a path, where we're going to get the
// icon form desktop.ini there is just a little bit more we have to
// do before we can start loading
if (PathIsDirectoryW(pwzIconFile))
{
wchar_t wzTemp[MAX_PATH];
PathAppendW(pwzIconFile, L"desktop.ini");
nIcon = GetPrivateProfileIntW(L".ShellClassInfo", L"IconIndex",
0, pwzIconFile);
GetPrivateProfileStringW(L".ShellClassInfo", L"IconFile",
L"", wzTemp, _countof(wzTemp), pwzIconFile);
StringCchCopyW(pwzIconFile, MAX_PATH, wzTemp);
}
// okay, now it's really time to load the icon... if it's an .ico
// file we want to do an LoadImage() thing, otherwise it's
// extracticon so lets find out the extension
if (PathMatchSpecW(pwzIconFile, L"*.ico"))
{
hIcon = (HICON)LoadImageW(
NULL, pwzIconFile, IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
}
else
{
hIcon = ExtractIconW(GetModuleHandle(NULL), pwzIconFile, nIcon);
if (hIcon == (HICON)1)
{
hIcon = NULL;
}
}
}
}
return hIcon;
}
//
// LoadLSIconA
//
HICON LoadLSIconA(LPCSTR pszIconPath, LPCSTR pszFile)
{
return LoadLSIconW(
std::unique_ptr<wchar_t>(WCSFromMBS(pszIconPath)).get(),
std::unique_ptr<wchar_t>(WCSFromMBS(pszFile)).get()
);
}
//
// GetLSBitmapSize(HBITMAP hBitmap, LPINT nWidth, LPINT nHeight)
//
void GetLSBitmapSize(HBITMAP hBitmap, LPINT nWidth, LPINT nHeight)
{
BITMAP hbmBitmap;
if (!GetObject(hBitmap, sizeof(hbmBitmap), (LPSTR) & hbmBitmap))
{
if (nWidth)
{
*nWidth = 0;
}
if (nHeight)
{
*nHeight = 0;
}
}
else
{
if (nWidth)
{
*nWidth = hbmBitmap.bmWidth;
}
if (nHeight)
{
*nHeight = hbmBitmap.bmHeight;
}
}
}
void TransparentBltLS(
HDC hdcDst, int nXDest, int nYDest, int nWidth, int nHeight,
HDC hdcSrc, int nXSrc, int nYSrc,
COLORREF colorTransparent)
{
HDC hdcDstCpy;
HBITMAP hbmDstCpy;
HBITMAP hbmOldDstCpy;
// create a destination compatble dc containing
// a copy of the destination dc
hdcDstCpy = CreateCompatibleDC(hdcDst);
hbmDstCpy = CreateCompatibleBitmap(hdcDst, nWidth, nHeight);
hbmOldDstCpy = (HBITMAP)SelectObject(hdcDstCpy, hbmDstCpy);
BitBlt(hdcDstCpy, 0, 0, nWidth, nHeight, hdcDst, nXDest, nYDest, SRCCOPY);
TransparentBltLSWorker(hdcDstCpy, nWidth, nHeight,
hdcSrc, nXSrc, nYSrc, colorTransparent);
// now we have created the image we want to blt
// in the destination copy dc
BitBlt(hdcDst, nXDest, nYDest, nWidth, nHeight, hdcDstCpy, 0, 0, SRCCOPY);
SelectObject(hdcDstCpy, hbmOldDstCpy);
DeleteObject(hbmDstCpy);
DeleteDC(hdcDstCpy);
}
static void TransparentBltLSWorker(
HDC hdcDst, int nWidth, int nHeight,
HDC hdcSrc, int nXSrc, int nYSrc,
COLORREF colorTransparent)
{
HDC hdcMem, hdcMask;
HBITMAP hbmMask, hbmMem;
HBITMAP hbmOldMem, hbmOldMask;
// create a destination compatble dc containing a copy of the source dc
hdcMem = CreateCompatibleDC(hdcDst);
hbmMem = CreateCompatibleBitmap(hdcDst, nWidth, nHeight);
hbmOldMem = (HBITMAP)SelectObject(hdcMem, hbmMem);
BitBlt(hdcMem, 0, 0, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, SRCCOPY);
// Create monochrome bitmap for the mask
hdcMask = CreateCompatibleDC(hdcDst);
hbmMask = CreateBitmap(nWidth, nHeight, 1, 1, NULL);
hbmOldMask = (HBITMAP)SelectObject(hdcMask, hbmMask);
// pixels matching the hdcMem bkcolor are white in the mask,
// while all others are black.
SetBkColor(hdcMem, colorTransparent);
// Create the mask from the memory dc holding the source image
BitBlt(hdcMask, 0, 0, nWidth, nHeight, hdcMem, 0, 0, SRCCOPY);
// Mask off source (XOR - hdcMem bkcolor is still the transparent color)
BitBlt(hdcMem, 0, 0, nWidth, nHeight, hdcMask, 0, 0, SRCINVERT);
// Mask off dest (assumption is made that hdcDest bkcolor is white)
BitBlt(hdcDst, 0, 0, nWidth, nHeight, hdcMask, 0, 0, SRCAND);
// Combine the foreground with the background
BitBlt(hdcDst, 0, 0, nWidth, nHeight, hdcMem, 0, 0, SRCPAINT);
SelectObject(hdcMask, hbmOldMask);
DeleteObject(hbmMask);
DeleteDC(hdcMask);
SelectObject(hdcMem, hbmOldMem);
DeleteObject(hbmMem);
DeleteDC(hdcMem);
}
void Frame3D(
HDC hdc, RECT rect, COLORREF TopColor, COLORREF BottomColor, int Width)
{
HPEN hPen1, hPen2, hOldPen;
--rect.bottom;
--rect.right;
hPen1 = CreatePen(PS_SOLID, 1, TopColor);
hPen2 = CreatePen(PS_SOLID, 1, BottomColor);
hOldPen = (HPEN)SelectObject(hdc, hPen1);
while (Width-- > 0)
{
POINT points[3];
// left, top borders (do not draw corners)
points[0].x = rect.left;
points[0].y = rect.bottom-1;
points[1].x = rect.left;
points[1].y = rect.top;
points[2].x = rect.right; // end point is not filled
points[2].y = rect.top;
SelectObject(hdc, hPen1);
Polyline(hdc, points, 3);
// bottom, right borders (draw corners)
points[0].y = rect.bottom;
points[1].x = rect.right;
points[1].y = rect.bottom;
points[2].y -= 1; // end point is not filled
SelectObject(hdc, hPen2);
Polyline(hdc, points, 3);
InflateRect(&rect, -1, -1);
}
SelectObject(hdc, hOldPen);
DeleteObject(hPen2);
DeleteObject(hPen1);
}