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
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
|
// Win32++ Version 7.2
// Released: 5th AUgust 2011
//
// David Nash
// email: dnash@bigpond.net.au
// url: https://sourceforge.net/projects/win32-framework
//
//
// Copyright (c) 2005-2011 David Nash
//
// Permission is hereby granted, free of charge, to
// any person obtaining a copy of this software and
// associated documentation files (the "Software"),
// to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify,
// merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom
// the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice
// shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
//
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// gdi.h
// Declaration of the CDC class, and CBitmapInfoPtr class
// The CDC class provides a device context, along with the various associated
// objects such as Bitmaps, Brushes, Bitmaps, Fonts and Pens. This class
// handles the creation, selection, de-selection and deletion of these objects
// automatically. It also automatically deletes or releases the device context
// itself as appropriate. Any failure to create the new GDI object throws an
// exception.
//
// The CDC class is sufficient for most GDI programming needs. Sometimes
// however we need to have the GDI object seperated from the device context.
// Wrapper classes for GDI objects are provided for this purpose. The classes
// are CBitmap, CBrush, CFont, CPalette, CPen and CRgn. These classes
// automatically delete the GDI resouce assigned to them when their destructor
// is called. These wrapper class objects can be attached to the CDC as
// shown below.
//
// Coding Exampe without CDC ...
// void DrawLine()
// {
// HDC hdcClient = ::GetDC(m_hWnd);
// HDC hdcMem = ::CreateCompatibleDC(hdcClient);
// HBITMAP hBitmap = ::CreateCompatibleBitmap(hdcClient, cx, cy);
// HBITMAP hOldBitmap = (HBITMAP)::SelectObject(hdcMem, hBitmap);
// HPEN hPen = ::CreatePen(PS_SOLID, 1, RGB(255,0,0);
// HPEN hOldPen = (HPEN)::SelectObject(hdcMem, hPen);
// ::MoveToEx(hdcMem, 0, 0, NULL);
// ::LineTo(hdcMem, 50, 50);
// ::BitBlt(hdcClient, 0, 0, cx, cy, hdcMem, 0, 0);
// ::SelectObject(hdcMem, hOldPen);
// ::DeleteObject(hPen);
// ::SelectObject(hdcMem, hOldBitmap);
// ::DeleteObject(hBitmap);
// ::DeleteDC(hdcMem);
// ::ReleaseDC(m_hWnd, hdcClient);
// }
//
// Coding Example with CDC classes ...
// void DrawLine()
// {
// CClientDC dcClient(this)
// CMemDC dcMem(&dcClient);
// CBitmap* pOldBitmap = dcMem.CreateCompatibleBitmap(&dcClient, cx, cy);
// CPen* pOldPen = CMemDC.CreatePen(PS_SOLID, 1, RGB(255,0,0);
// CMemDC.MoveTo(0, 0);
// CMemDC.LineTo(50, 50);
// dcClient.BitBlt(0, 0, cx, cy, &CMemDC, 0, 0);
// }
//
// Coding Example with CDC classes and CPen ...
// void DrawLine()
// {
// CClientDC dcClient(this)
// CMemDC CMemDC(&dcClient);
// CBitmap* pOldBitmap = dcMem.CreateCompatibleBitmap(&dcClient, cx, cy);
// CPen MyPen(PS_SOLID, 1, RGB(255,0,0));
// CPen* pOldPen = CMemDC.SelectObject(&MyPen);
// CMemDC.MoveTo(0, 0);
// CMemDC.LineTo(50, 50);
// dcClient.BitBlt(0, 0, cx, cy, &CMemDC, 0, 0);
// }
// Notes:
// * When the CDC object drops out of scope, it's destructor is called, releasing
// or deleting the device context as appropriate.
// * When the destructor for CBitmap, CBrush, CPalette, CPen and CRgn are called,
// the destructor is called deleting their GDI object.
// * When the CDC object' destructor is called, any GDI objects created by one of
// the CDC member functions (CDC::CreatePen for example) will be deleted.
// * Bitmaps can only be selected into one device context at a time.
// * Palettes use SelectPalatte to select them into device the context.
// * Regions use SelectClipRgn to select them into the device context.
// * The FromHandle function can be used to convert a GDI handle (HDC, HPEN,
// HBITMAP etc) to a pointer of the appropriate GDI class (CDC, CPen CBitmap etc).
// The FromHandle function creates a temporary object unless the HANDLE is already
// assigned to a GDI class. Temporary objects don't delete their GDI object when
// their destructor is called.
// * All the GDI classes are reference counted. This allows functions to safely
// pass these objects by value, as well as by pointer or by reference.
// The CBitmapInfoPtr class is a convienient wrapper for the BITMAPINFO structure.
// The size of the BITMAPINFO structure is dependant on the type of HBITMAP, and its
// space needs to be allocated dynamically. CBitmapInfoPtr automatically allocates
// and deallocates the memory for the structure. A CBitmapInfoPtr object can be
// used anywhere in place of a LPBITMAPINFO. LPBITMAPINFO is used in functions like
// GetDIBits and SetDIBits.
//
// Coding example ...
// CDC MemDC = CreateCompatibleDC(NULL);
// CBitmapInfoPtr pbmi(hBitmap);
// MemDC.GetDIBits(hBitmap, 0, pbmi->bmiHeader.biHeight, NULL, pbmi, DIB_RGB_COLORS);
#ifndef _WIN32XX_GDI_H_
#define _WIN32XX_GDI_H_
#include "wincore.h"
// Disable macros from Windowsx.h
#undef CopyRgn
namespace Win32xx
{
/////////////////////////////////////////////////////////////////
// Declarations for some global functions in the Win32xx namespace
//
#ifndef _WIN32_WCE
void GrayScaleBitmap(CBitmap* pbmSource);
void TintBitmap(CBitmap* pbmSource, int cRed, int cGreen, int cBlue);
HIMAGELIST CreateDisabledImageList(HIMAGELIST himlNormal);
#endif
///////////////////////////////////////////////
// Declarations for the CGDIObject class
//
class CGDIObject
{
friend CBitmap* FromHandle(HBITMAP hBitmap);
friend CBrush* FromHandle(HBRUSH hBrush);
friend CDC* FromHandle(HDC hDC);
friend CFont* FromHandle(HFONT hFont);
friend CPalette* FromHandle(HPALETTE hPalette);
friend CPen* FromHandle(HPEN hPen);
friend CRgn* FromHandle(HRGN hRgn);
public:
struct DataMembers // A structure that contains the data members for CGDIObject
{
HGDIOBJ hGDIObject;
long Count;
BOOL bRemoveObject;
};
CGDIObject();
CGDIObject(const CGDIObject& rhs);
virtual ~CGDIObject();
CGDIObject& operator = ( const CGDIObject& rhs );
void operator = (HGDIOBJ hObject);
void Attach(HGDIOBJ hObject);
HGDIOBJ Detach();
HGDIOBJ GetHandle() const;
int GetObject(int nCount, LPVOID pObject) const;
protected:
DataMembers* m_pData;
private:
void AddToMap();
BOOL RemoveFromMap();
void Release();
};
///////////////////////////////////////////////
// Declarations for the CBitmap class
//
class CBitmap : public CGDIObject
{
public:
CBitmap();
CBitmap(HBITMAP hBitmap);
CBitmap(LPCTSTR lpstr);
CBitmap(int nID);
operator HBITMAP() const;
~CBitmap();
// Create and load methods
BOOL LoadBitmap(LPCTSTR lpszName);
BOOL LoadBitmap(int nID);
BOOL LoadImage(LPCTSTR lpszName, int cxDesired, int cyDesired, UINT fuLoad);
BOOL LoadImage(UINT nID, int cxDesired, int cyDesired, UINT fuLoad);
BOOL LoadOEMBitmap(UINT nIDBitmap);
HBITMAP CreateBitmap(int nWidth, int nHeight, UINT nPlanes, UINT nBitsPerPixel, LPCVOID lpBits);
HBITMAP CreateCompatibleBitmap(CDC* pDC, int nWidth, int nHeight);
HBITMAP CreateDIBSection(CDC* pDC, CONST BITMAPINFO* lpbmi, UINT uColorUse, LPVOID* ppvBits, HANDLE hSection, DWORD dwOffset);
#ifndef _WIN32_WCE
HBITMAP CreateDIBitmap(CDC* pDC, CONST BITMAPINFOHEADER* lpbmih, DWORD dwInit, LPCVOID lpbInit, CONST BITMAPINFO* lpbmi, UINT uColorUse);
HBITMAP CreateMappedBitmap(UINT nIDBitmap, UINT nFlags = 0, LPCOLORMAP lpColorMap = NULL, int nMapSize = 0);
HBITMAP CreateBitmapIndirect(LPBITMAP lpBitmap);
int GetDIBits(CDC* pDC, UINT uStartScan, UINT cScanLines, LPVOID lpvBits, LPBITMAPINFO lpbmi, UINT uColorUse) const;
int SetDIBits(CDC* pDC, UINT uStartScan, UINT cScanLines, CONST VOID* lpvBits, CONST BITMAPINFO* lpbmi, UINT uColorUse);
CSize GetBitmapDimensionEx() const;
CSize SetBitmapDimensionEx(int nWidth, int nHeight);
#endif // !_WIN32_WCE
// Attributes
BITMAP GetBitmapData() const;
};
///////////////////////////////////////////////
// Declarations for the CBrush class
//
class CBrush : public CGDIObject
{
public:
CBrush();
CBrush(HBRUSH hBrush);
CBrush(COLORREF crColor);
operator HBRUSH() const;
~CBrush();
HBRUSH CreateSolidBrush(COLORREF crColor);
HBRUSH CreatePatternBrush(CBitmap* pBitmap);
LOGBRUSH GetLogBrush() const;
#ifndef _WIN32_WCE
HBRUSH CreateHatchBrush(int nIndex, COLORREF crColor);
HBRUSH CreateBrushIndirect(LPLOGBRUSH lpLogBrush);
HBRUSH CreateDIBPatternBrush(HGLOBAL hglbDIBPacked, UINT fuColorSpec);
HBRUSH CreateDIBPatternBrushPt(LPCVOID lpPackedDIB, UINT nUsage);
#endif // !defined(_WIN32_WCE)
};
///////////////////////////////////////////////
// Declarations for the CFont class
//
class CFont : public CGDIObject
{
public:
CFont();
CFont(HFONT hFont);
CFont(const LOGFONT* lpLogFont);
operator HFONT() const;
~CFont();
// Create methods
HFONT CreateFontIndirect(const LOGFONT* lpLogFont);
HFONT CreatePointFont(int nPointSize, LPCTSTR lpszFaceName, CDC* pDC = NULL, BOOL bBold = FALSE, BOOL bItalic = FALSE);
HFONT CreatePointFontIndirect(const LOGFONT* lpLogFont, CDC* pDC = NULL);
#ifndef _WIN32_WCE
HFONT CreateFont(int nHeight, int nWidth, int nEscapement,
int nOrientation, int nWeight, DWORD dwItalic, DWORD dwUnderline,
DWORD dwStrikeOut, DWORD dwCharSet, DWORD dwOutPrecision,
DWORD dwClipPrecision, DWORD dwQuality, DWORD dwPitchAndFamily,
LPCTSTR lpszFacename);
#endif // #ifndef _WIN32_WCE
// Attributes
LOGFONT GetLogFont() const;
};
///////////////////////////////////////////////
// Declarations for the CPalette class
//
class CPalette : public CGDIObject
{
public:
CPalette();
CPalette(HPALETTE hPalette);
operator HPALETTE() const;
~CPalette();
// Create methods
HPALETTE CreatePalette(LPLOGPALETTE lpLogPalette);
#ifndef _WIN32_WCE
HPALETTE CreateHalftonePalette(CDC* pDC);
#endif // !_WIN32_WCE
// Attributes
int GetEntryCount() const;
UINT GetPaletteEntries(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors) const;
UINT SetPaletteEntries(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors);
// Operations
#ifndef _WIN32_WCE
BOOL ResizePalette(UINT nNumEntries);
void AnimatePalette(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors);
#endif // !_WIN32_WCE
UINT GetNearestPaletteIndex (COLORREF crColor) const;
};
///////////////////////////////////////////////
// Declarations for the CPen class
//
class CPen : public CGDIObject
{
public:
CPen();
CPen(HPEN hPen);
CPen(int nPenStyle, int nWidth, COLORREF crColor);
#ifndef _WIN32_WCE
CPen(int nPenStyle, int nWidth, const LOGBRUSH* pLogBrush, int nStyleCount = 0, const DWORD* lpStyle = NULL);
#endif // !_WIN32_WCE
operator HPEN() const;
~CPen();
HPEN CreatePen(int nPenStyle, int nWidth, COLORREF crColor);
HPEN CreatePenIndirect(LPLOGPEN lpLogPen);
LOGPEN GetLogPen() const;
#ifndef _WIN32_WCE
HPEN ExtCreatePen(int nPenStyle, int nWidth, const LOGBRUSH* pLogBrush, int nStyleCount = 0, const DWORD* lpStyle = NULL);
EXTLOGPEN GetExtLogPen() const;
#endif // !_WIN32_WCE
};
///////////////////////////////////////////////
// Declarations for the CRgn class
//
class CRgn : public CGDIObject
{
public:
CRgn();
CRgn(HRGN hRgn);
operator HRGN() const;
~CRgn ();
// Create methods
HRGN CreateRectRgn(int x1, int y1, int x2, int y2);
HRGN CreateRectRgnIndirect(const RECT& rc);
HRGN CreateFromData(const XFORM* lpXForm, int nCount, const RGNDATA* pRgnData);
#ifndef _WIN32_WCE
HRGN CreateEllipticRgn(int x1, int y1, int x2, int y2);
HRGN CreateEllipticRgnIndirect(const RECT& rc);
HRGN CreatePolygonRgn(LPPOINT lpPoints, int nCount, int nMode);
HRGN CreatePolyPolygonRgn(LPPOINT lpPoints, LPINT lpPolyCounts, int nCount, int nPolyFillMode);
HRGN CreateRoundRectRgn(int x1, int y1, int x2, int y2, int x3, int y3);
HRGN CreateFromPath(HDC hDC);
#endif // !_WIN32_WCE
// Operations
void SetRectRgn(int x1, int y1, int x2, int y2);
void SetRectRgn(const RECT& rc);
int CombineRgn(CRgn* pRgnSrc1, CRgn* pRgnSrc2, int nCombineMode);
int CombineRgn(CRgn* pRgnSrc, int nCombineMode);
int CopyRgn(CRgn* pRgnSrc);
BOOL EqualRgn(CRgn* pRgn) const;
int OffsetRgn(int x, int y);
int OffsetRgn(POINT& pt);
int GetRgnBox(RECT& rc) const;
BOOL PtInRegion(int x, int y) const;
BOOL PtInRegion(POINT& pt) const;
BOOL RectInRegion(const RECT& rc) const;
int GetRegionData(LPRGNDATA lpRgnData, int nDataSize) const;
};
///////////////////////////////////////////////
// Declarations for the CDC class
//
class CDC
{
friend class CWinApp;
friend class CWnd;
friend CDC* FromHandle(HDC hDC);
public:
struct DataMembers // A structure that contains the data members for CDC
{
std::vector<GDIPtr> m_vGDIObjects; // Smart pointers to internally created Bitmaps, Brushes, Fonts, Bitmaps and Regions
HDC hDC; // The HDC belonging to this CDC
long Count; // Reference count
BOOL bRemoveHDC; // Delete/Release the HDC on destruction
HWND hWnd; // The HWND of a Window or Client window DC
int nSavedDCState; // The save state of the HDC.
};
CDC(); // Constructs a new CDC without assigning a HDC
CDC(HDC hDC, HWND hWnd = 0); // Assigns a HDC to a new CDC
CDC(const CDC& rhs); // Constructs a new copy of the CDC
virtual ~CDC();
operator HDC() const { return m_pData->hDC; } // Converts a CDC to a HDC
CDC& operator = (const CDC& rhs); // Assigns a CDC to an existing CDC
void Attach(HDC hDC, HWND hWnd = 0);
void Destroy();
HDC Detach();
HDC GetHDC() const { return m_pData->hDC; }
CPalette* SelectPalette(const CPalette* pPalette, BOOL bForceBkgnd);
CBitmap* SelectObject(const CBitmap* pBitmap);
CBrush* SelectObject(const CBrush* pBrush);
CFont* SelectObject(const CFont* pFont);
CPalette* SelectObject(const CPalette* pPalette);
CPen* SelectObject(const CPen* pPen);
#ifndef _WIN32_WCE
void operator = (const HDC hDC);
#endif
// Initialization
BOOL CreateCompatibleDC(CDC* pDC);
BOOL CreateDC(LPCTSTR lpszDriver, LPCTSTR lpszDevice, LPCTSTR lpszOutput, const DEVMODE* pInitData);
int GetDeviceCaps(int nIndex) const;
#ifndef _WIN32_WCE
BOOL CreateIC(LPCTSTR lpszDriver, LPCTSTR lpszDevice, LPCTSTR lpszOutput, const DEVMODE* pInitData);
#endif
// Create and Select Bitmaps
CBitmap* CreateBitmap(int cx, int cy, UINT Planes, UINT BitsPerPixel, LPCVOID pvColors);
CBitmap* CreateCompatibleBitmap(CDC* pDC, int cx, int cy);
CBitmap* CreateDIBSection(CDC* pDC, const BITMAPINFO& bmi, UINT iUsage, LPVOID *ppvBits,
HANDLE hSection, DWORD dwOffset);
BITMAP GetBitmapData() const;
CBitmap* LoadBitmap(UINT nID);
CBitmap* LoadBitmap(LPCTSTR lpszName);
CBitmap* LoadImage(UINT nID, int cxDesired, int cyDesired, UINT fuLoad);
CBitmap* LoadImage(LPCTSTR lpszName, int cxDesired, int cyDesired, UINT fuLoad);
CBitmap* LoadOEMBitmap(UINT nIDBitmap); // for OBM_/OCR_/OIC
#ifndef _WIN32_WCE
CBitmap* CreateBitmapIndirect(LPBITMAP pBitmap);
CBitmap* CreateDIBitmap(CDC* pDC, const BITMAPINFOHEADER& bmih, DWORD fdwInit, LPCVOID lpbInit,
BITMAPINFO& bmi, UINT fuUsage);
CBitmap* CreateMappedBitmap(UINT nIDBitmap, UINT nFlags /*= 0*/, LPCOLORMAP lpColorMap /*= NULL*/, int nMapSize /*= 0*/);
#endif
// Create and Select Brushes
CBrush* CreatePatternBrush(CBitmap* pBitmap);
CBrush* CreateSolidBrush(COLORREF rbg);
LOGBRUSH GetLogBrush() const;
#ifndef _WIN32_WCE
CBrush* CreateBrushIndirect(LPLOGBRUSH pLogBrush);
CBrush* CreateHatchBrush(int fnStyle, COLORREF rgb);
CBrush* CreateDIBPatternBrush(HGLOBAL hglbDIBPacked, UINT fuColorSpec);
CBrush* CreateDIBPatternBrushPt(LPCVOID lpPackedDIB, UINT iUsage);
#endif
// Create and Select Fonts
CFont* CreateFontIndirect(LPLOGFONT plf);
LOGFONT GetLogFont() const;
#ifndef _WIN32_WCE
CFont* CreateFont(int nHeight, int nWidth, int nEscapement, int nOrientation, int fnWeight,
DWORD fdwItalic, DWORD fdwUnderline, DWORD fdwStrikeOut, DWORD fdwCharSet,
DWORD fdwOutputPrecision, DWORD fdwClipPrecision, DWORD fdwQuality,
DWORD fdwPitchAndFamily, LPCTSTR lpszFace);
#endif
// Create and Select Pens
CPen* CreatePen(int nStyle, int nWidth, COLORREF rgb);
CPen* CreatePenIndirect(LPLOGPEN pLogPen);
LOGPEN GetLogPen() const;
// Create Select Regions
int CreateRectRgn(int left, int top, int right, int bottom);
int CreateRectRgnIndirect(const RECT& rc);
int CreateFromData(const XFORM* Xform, DWORD nCount, const RGNDATA *pRgnData);
#ifndef _WIN32_WCE
int CreateEllipticRgn(int left, int top, int right, int bottom);
int CreateEllipticRgnIndirect(const RECT& rc);
int CreatePolygonRgn(LPPOINT ppt, int cPoints, int fnPolyFillMode);
int CreatePolyPolygonRgn(LPPOINT ppt, LPINT pPolyCounts, int nCount, int fnPolyFillMode);
#endif
// Wrappers for WinAPI functions
// Point and Line Drawing Functions
CPoint GetCurrentPosition() const;
CPoint MoveTo(int x, int y) const;
CPoint MoveTo(POINT pt) const;
BOOL LineTo(int x, int y) const;
BOOL LineTo(POINT pt) const;
COLORREF GetPixel(int x, int y) const;
COLORREF GetPixel(POINT pt) const;
COLORREF SetPixel(int x, int y, COLORREF crColor) const;
COLORREF SetPixel(POINT pt, COLORREF crColor) const;
#ifndef _WIN32_WCE
BOOL Arc(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) const;
BOOL Arc(RECT& rc, POINT ptStart, POINT ptEnd) const;
BOOL ArcTo(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) const;
BOOL ArcTo(RECT& rc, POINT ptStart, POINT ptEnd) const;
BOOL AngleArc(int x, int y, int nRadius, float fStartAngle, float fSweepAngle) const;
int GetArcDirection() const;
int SetArcDirection(int nArcDirection) const;
BOOL PolyDraw(const POINT* lpPoints, const BYTE* lpTypes, int nCount) const;
BOOL Polyline(LPPOINT lpPoints, int nCount) const;
BOOL PolyPolyline(const POINT* lpPoints, const DWORD* lpPolyPoints, int nCount) const;
BOOL PolylineTo(const POINT* lpPoints, int nCount) const;
BOOL PolyBezier(const POINT* lpPoints, int nCount) const;
BOOL PolyBezierTo(const POINT* lpPoints, int nCount) const;
BOOL SetPixelV(int x, int y, COLORREF crColor) const;
BOOL SetPixelV(POINT pt, COLORREF crColor) const;
#endif
// Shape Drawing Functions
void DrawFocusRect(const RECT& rc) const;
BOOL Ellipse(int x1, int y1, int x2, int y2) const;
BOOL Ellipse(const RECT& rc) const;
BOOL Polygon(LPPOINT lpPoints, int nCount) const;
BOOL Rectangle(int x1, int y1, int x2, int y2) const;
BOOL Rectangle(const RECT& rc) const;
BOOL RoundRect(int x1, int y1, int x2, int y2, int nWidth, int nHeight) const;
BOOL RoundRect(const RECT& rc, int nWidth, int nHeight) const;
#ifndef _WIN32_WCE
BOOL Chord(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) const;
BOOL Chord(const RECT& rc, POINT ptStart, POINT ptEnd) const;
BOOL Pie(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) const;
BOOL Pie(const RECT& rc, POINT ptStart, POINT ptEnd) const;
BOOL PolyPolygon(LPPOINT lpPoints, LPINT lpPolyCounts, int nCount) const;
#endif
// Fill and Image Drawing functions
BOOL FillRect(const RECT& rc, CBrush* pBrushr) const;
BOOL InvertRect(const RECT& rc) const;
BOOL DrawIconEx(int xLeft, int yTop, HICON hIcon, int cxWidth, int cyWidth, UINT istepIfAniCur, CBrush* pFlickerFreeDraw, UINT diFlags) const;
BOOL DrawEdge(const RECT& rc, UINT nEdge, UINT nFlags) const;
BOOL DrawFrameControl(const RECT& rc, UINT nType, UINT nState) const;
BOOL FillRgn(CRgn* pRgn, CBrush* pBrush) const;
void GradientFill(COLORREF Color1, COLORREF Color2, const RECT& rc, BOOL bVertical);
void SolidFill(COLORREF Color, const RECT& rc);
#ifndef _WIN32_WCE
BOOL DrawIcon(int x, int y, HICON hIcon) const;
BOOL DrawIcon(POINT point, HICON hIcon) const;
BOOL FrameRect(const RECT& rc, CBrush* pBrush) const;
BOOL PaintRgn(CRgn* pRgn) const;
#endif
// Bitmap Functions
void DrawBitmap(int x, int y, int cx, int cy, CBitmap& Bitmap, COLORREF clrMask);
int StretchDIBits(int XDest, int YDest, int nDestWidth, int nDestHeight, int XSrc, int YSrc, int nSrcWidth,
int nSrcHeight, CONST VOID *lpBits, BITMAPINFO& bi, UINT iUsage, DWORD dwRop) const;
BOOL PatBlt(int x, int y, int nWidth, int nHeight, DWORD dwRop) const;
BOOL BitBlt(int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, DWORD dwRop) const;
BOOL StretchBlt(int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, int nSrcWidth, int nSrcHeight, DWORD dwRop) const;
#ifndef _WIN32_WCE
int GetDIBits(CBitmap* pBitmap, UINT uStartScan, UINT cScanLines, LPVOID lpvBits, LPBITMAPINFO lpbi, UINT uUsage) const;
int SetDIBits(CBitmap* pBitmap, UINT uStartScan, UINT cScanLines, CONST VOID *lpvBits, LPBITMAPINFO lpbi, UINT fuColorUse) const;
int GetStretchBltMode() const;
int SetStretchBltMode(int iStretchMode) const;
BOOL FloodFill(int x, int y, COLORREF crColor) const;
BOOL ExtFloodFill(int x, int y, COLORREF crColor, UINT nFillType) const;
#endif
// Brush Functions
#ifdef GetDCBrushColor
COLORREF GetDCBrushColor() const;
COLORREF SetDCBrushColor(COLORREF crColor) const;
#endif
// Clipping Functions
int ExcludeClipRect(int Left, int Top, int Right, int BottomRect);
int ExcludeClipRect(const RECT& rc);
int GetClipBox(RECT& rc);
int GetClipRgn(HRGN hrgn);
int IntersectClipRect(int Left, int Top, int Right, int Bottom);
int IntersectClipRect(const RECT& rc);
BOOL RectVisible(const RECT& rc);
int SelectClipRgn(CRgn* pRgn);
#ifndef _WIN32_WCE
int ExtSelectClipRgn(CRgn* pRgn, int fnMode);
int OffsetClipRgn(int nXOffset, int nYOffset);
BOOL PtVisible(int X, int Y);
#endif
// Co-ordinate Functions
#ifndef _WIN32_WCE
BOOL DPtoLP(LPPOINT lpPoints, int nCount) const;
BOOL DPtoLP(RECT& rc) const;
BOOL LPtoDP(LPPOINT lpPoints, int nCount) const;
BOOL LPtoDP(RECT& rc) const;
#endif
// Layout Functions
DWORD GetLayout() const;
DWORD SetLayout(DWORD dwLayout) const;
// Mapping functions
#ifndef _WIN32_WCE
int GetMapMode() const;
int SetMapMode(int nMapMode) const;
BOOL GetViewportOrgEx(LPPOINT lpPoint) const;
BOOL SetViewportOrgEx(int x, int y, LPPOINT lpPoint = NULL) const;
BOOL SetViewportOrgEx(POINT point, LPPOINT lpPointRet = NULL) const;
BOOL OffsetViewportOrgEx(int nWidth, int nHeight, LPPOINT lpPoint = NULL) const;
BOOL GetViewportExtEx(LPSIZE lpSize) const;
BOOL SetViewportExtEx(int x, int y, LPSIZE lpSize) const;
BOOL SetViewportExtEx(SIZE size, LPSIZE lpSizeRet) const;
BOOL ScaleViewportExtEx(int xNum, int xDenom, int yNum, int yDenom, LPSIZE lpSize) const;
BOOL OffsetWindowOrg(int nWidth, int nHeight, LPPOINT lpPoint) const;
BOOL GetWindowExtEx(LPSIZE lpSize) const;
BOOL SetWindowExtEx(int x, int y, LPSIZE lpSize) const;
BOOL SetWindowExtEx(SIZE size, LPSIZE lpSizeRet) const;
BOOL ScaleWindowExtEx(int xNum, int xDenom, int yNum, int yDenom, LPSIZE lpSize) const;
BOOL GetWindowOrgEx(LPPOINT lpPoint) const;
BOOL SetWindowOrgEx(int x, int y, LPPOINT lpPoint) const;
BOOL SetWindowOrgEx(POINT point, LPPOINT lpPointRet) const;
BOOL OffsetWindowOrgEx(int nWidth, int nHeight, LPPOINT lpPoint) const;
#endif
// Printer Functions
int StartDoc(LPDOCINFO lpDocInfo) const;
int EndDoc() const;
int StartPage() const;
int EndPage() const;
int AbortDoc() const;
int SetAbortProc(BOOL (CALLBACK* lpfn)(HDC, int)) const;
// Text Functions
int DrawText(LPCTSTR lpszString, int nCount, LPRECT lprc, UINT nFormat) const;
BOOL ExtTextOut(int x, int y, UINT nOptions, LPCRECT lprc, LPCTSTR lpszString, int nCount = -1, LPINT lpDxWidths = NULL) const;
COLORREF GetBkColor() const;
int GetBkMode() const;
UINT GetTextAlign() const;
int GetTextFace(int nCount, LPTSTR lpszFacename) const;
COLORREF GetTextColor() const;
BOOL GetTextMetrics(TEXTMETRIC& Metrics) const;
COLORREF SetBkColor(COLORREF crColor) const;
int SetBkMode(int iBkMode) const;
UINT SetTextAlign(UINT nFlags) const;
COLORREF SetTextColor(COLORREF crColor) const;
#ifndef _WIN32_WCE
int DrawTextEx(LPTSTR lpszString, int nCount, LPRECT lprc, UINT nFormat, LPDRAWTEXTPARAMS lpDTParams) const;
CSize GetTabbedTextExtent(LPCTSTR lpszString, int nCount, int nTabPositions, LPINT lpnTabStopPositions) const;
int GetTextCharacterExtra() const;
CSize GetTextExtentPoint32(LPCTSTR lpszString, int nCount) const;
BOOL GrayString(CBrush* pBrush, GRAYSTRINGPROC lpOutputFunc, LPARAM lpData, int nCount, int x, int y, int nWidth, int nHeight) const;
int SetTextCharacterExtra(int nCharExtra) const;
int SetTextJustification(int nBreakExtra, int nBreakCount) const;
CSize TabbedTextOut(int x, int y, LPCTSTR lpszString, int nCount, int nTabPositions, LPINT lpnTabStopPositions, int nTabOrigin) const;
BOOL TextOut(int x, int y, LPCTSTR lpszString, int nCount = -1) const;
#endif
private:
void AddToMap();
static CDC* AddTempHDC(HDC hDC, HWND hWnd);
void Release();
BOOL RemoveFromMap();
DataMembers* m_pData; // pointer to the class's data members
};
class CClientDC : public CDC
{
public:
CClientDC(const CWnd* pWnd)
{
if (pWnd) assert(pWnd->IsWindow());
HWND hWnd = pWnd? pWnd->GetHwnd() : GetDesktopWindow();
Attach(::GetDC(hWnd), hWnd);
}
virtual ~CClientDC() {}
};
class CMemDC : public CDC
{
public:
CMemDC(const CDC* pDC)
{
if (pDC) assert(pDC->GetHDC());
HDC hDC = pDC? pDC->GetHDC() : NULL;
Attach(::CreateCompatibleDC(hDC));
}
virtual ~CMemDC() {}
};
class CPaintDC : public CDC
{
public:
CPaintDC(const CWnd* pWnd)
{
assert(pWnd->IsWindow());
m_hWnd = pWnd->GetHwnd();
Attach(::BeginPaint(pWnd->GetHwnd(), &m_ps), m_hWnd);
}
virtual ~CPaintDC() { ::EndPaint(m_hWnd, &m_ps); }
private:
HWND m_hWnd;
PAINTSTRUCT m_ps;
};
class CWindowDC : public CDC
{
public:
CWindowDC(const CWnd* pWnd)
{
if (pWnd) assert(pWnd->IsWindow());
HWND hWnd = pWnd? pWnd->GetHwnd() : GetDesktopWindow();
Attach(::GetWindowDC(hWnd), hWnd);
}
virtual ~CWindowDC() {}
};
#ifndef _WIN32_WCE
class CMetaFileDC : public CDC
{
public:
CMetaFileDC() : m_hMF(0), m_hEMF(0) {}
virtual ~CMetaFileDC()
{
if (m_hMF)
{
::CloseMetaFile(GetHDC());
::DeleteMetaFile(m_hMF);
}
if (m_hEMF)
{
::CloseEnhMetaFile(GetHDC());
::DeleteEnhMetaFile(m_hEMF);
}
}
void Create(LPCTSTR lpszFilename = NULL) { Attach(::CreateMetaFile(lpszFilename)); }
void CreateEnhanced(CDC* pDCRef, LPCTSTR lpszFileName, LPCRECT lpBounds, LPCTSTR lpszDescription)
{
HDC hDC = pDCRef? pDCRef->GetHDC() : NULL;
::CreateEnhMetaFile(hDC, lpszFileName, lpBounds, lpszDescription);
assert(GetHDC());
}
HMETAFILE Close() { return ::CloseMetaFile(GetHDC()); }
HENHMETAFILE CloseEnhanced() { return ::CloseEnhMetaFile(GetHDC()); }
private:
HMETAFILE m_hMF;
HENHMETAFILE m_hEMF;
};
#endif
///////////////////////////////////////////////
// Declarations for the CBitmapInfoPtr class
// The CBitmapInfoPtr class is a convienient wrapper for the BITMAPINFO structure.
class CBitmapInfoPtr
{
public:
CBitmapInfoPtr(CBitmap* pBitmap)
{
BITMAP bmSource = pBitmap->GetBitmapData();
// Convert the color format to a count of bits.
WORD cClrBits = (WORD)(bmSource.bmPlanes * bmSource.bmBitsPixel);
if (cClrBits == 1) cClrBits = 1;
else if (cClrBits <= 4) cClrBits = 4;
else if (cClrBits <= 8) cClrBits = 8;
else if (cClrBits <= 16) cClrBits = 16;
else if (cClrBits <= 24) cClrBits = 24;
else cClrBits = 32;
// Allocate memory for the BITMAPINFO structure.
UINT uQuadSize = (cClrBits == 24)? 0 : sizeof(RGBQUAD) * (int)(1 << cClrBits);
m_bmi.assign(sizeof(BITMAPINFOHEADER) + uQuadSize, 0);
m_pbmiArray = (LPBITMAPINFO) &m_bmi[0];
m_pbmiArray->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
m_pbmiArray->bmiHeader.biHeight = bmSource.bmHeight;
m_pbmiArray->bmiHeader.biWidth = bmSource.bmWidth;
m_pbmiArray->bmiHeader.biPlanes = bmSource.bmPlanes;
m_pbmiArray->bmiHeader.biBitCount = bmSource.bmBitsPixel;
m_pbmiArray->bmiHeader.biCompression = BI_RGB;
if (cClrBits < 24)
m_pbmiArray->bmiHeader.biClrUsed = (1<<cClrBits);
}
LPBITMAPINFO get() const { return m_pbmiArray; }
operator LPBITMAPINFO() const { return m_pbmiArray; }
LPBITMAPINFO operator->() const { return m_pbmiArray; }
private:
CBitmapInfoPtr(const CBitmapInfoPtr&); // Disable copy construction
CBitmapInfoPtr& operator = (const CBitmapInfoPtr&); // Disable assignment operator
LPBITMAPINFO m_pbmiArray;
std::vector<byte> m_bmi;
};
CBitmap* FromHandle(HBITMAP hBitmap);
CBrush* FromHandle(HBRUSH hBrush);
CFont* FromHandle(HFONT hFont);
CPalette* FromHandle(HPALETTE hPalette);
CPen* FromHandle(HPEN hPen);
CRgn* FromHandle(HRGN hRgn);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
namespace Win32xx
{
///////////////////////////////////////////////
// Declarations for the CGDIObject class
//
inline CGDIObject::CGDIObject()
// Constructs the CGDIObject
{
m_pData = new DataMembers;
m_pData->hGDIObject = 0;
m_pData->Count = 1L;
m_pData->bRemoveObject = TRUE;
}
inline CGDIObject::CGDIObject(const CGDIObject& rhs)
// Note: A copy of a CGDIObject is a clone of the original.
// Both objects manipulate the one HGDIOBJ.
{
m_pData = rhs.m_pData;
InterlockedIncrement(&m_pData->Count);
}
inline CGDIObject::~CGDIObject()
// Deconstructs the CGDIObject
{
Release();
}
inline CGDIObject& CGDIObject::operator = ( const CGDIObject& rhs )
// Note: A copy of a CGDIObject is a clone of the original.
// Both objects manipulate the one HGDIOBJ.
{
if (this != &rhs)
{
InterlockedIncrement(&rhs.m_pData->Count);
Release();
m_pData = rhs.m_pData;
}
return *this;
}
inline void CGDIObject::operator = (HGDIOBJ hObject)
{
assert(m_pData);
assert (m_pData->hGDIObject == NULL);
m_pData->hGDIObject = hObject;
}
inline void CGDIObject::AddToMap()
// Store the HDC and CDC pointer in the HDC map
{
assert( GetApp() );
GetApp()->m_csMapLock.Lock();
assert(m_pData->hGDIObject);
assert(!GetApp()->GetCGDIObjectFromMap(m_pData->hGDIObject));
GetApp()->m_mapGDI.insert(std::make_pair(m_pData->hGDIObject, this));
GetApp()->m_csMapLock.Release();
}
inline void CGDIObject::Attach(HGDIOBJ hObject)
// Attaches a GDI HANDLE to the CGDIObject.
// The HGDIOBJ will be automatically deleted when the destructor is called unless it is detached.
{
assert(m_pData);
if (m_pData->hGDIObject != NULL && m_pData->hGDIObject != hObject)
{
::DeleteObject(Detach());
}
CGDIObject* pObject = GetApp()->GetCGDIObjectFromMap(hObject);
if (pObject)
{
delete m_pData;
m_pData = pObject->m_pData;
InterlockedIncrement(&m_pData->Count);
}
else
{
m_pData->hGDIObject = hObject;
AddToMap();
}
}
inline HGDIOBJ CGDIObject::Detach()
// Detaches the HGDIOBJ from this object.
{
assert(m_pData);
assert(m_pData->hGDIObject);
GetApp()->m_csMapLock.Lock();
RemoveFromMap();
HGDIOBJ hObject = m_pData->hGDIObject;
m_pData->hGDIObject = 0;
if (m_pData->Count)
{
if (InterlockedDecrement(&m_pData->Count) == 0)
{
delete m_pData;
}
}
GetApp()->m_csMapLock.Release();
// Assign values to our data members
m_pData = new DataMembers;
m_pData->hGDIObject = 0;
m_pData->Count = 1L;
m_pData->bRemoveObject = TRUE;
return hObject;
}
inline HGDIOBJ CGDIObject::GetHandle() const
{
assert(m_pData);
return m_pData->hGDIObject;
}
inline int CGDIObject::GetObject(int nCount, LPVOID pObject) const
{
assert(m_pData);
return ::GetObject(m_pData->hGDIObject, nCount, pObject);
}
inline void CGDIObject::Release()
{
assert(m_pData);
BOOL bSucceeded = TRUE;
if (InterlockedDecrement(&m_pData->Count) == 0)
{
if (m_pData->hGDIObject != NULL)
{
if (m_pData->bRemoveObject)
bSucceeded = ::DeleteObject(m_pData->hGDIObject);
else
bSucceeded = TRUE;
}
RemoveFromMap();
delete m_pData;
m_pData = 0;
}
assert(bSucceeded);
}
inline BOOL CGDIObject::RemoveFromMap()
{
BOOL Success = FALSE;
if( GetApp() )
{
// Allocate an iterator for our HDC map
std::map<HGDIOBJ, CGDIObject*, CompareGDI>::iterator m;
CWinApp* pApp = GetApp();
if (pApp)
{
// Erase the CGDIObject pointer entry from the map
pApp->m_csMapLock.Lock();
m = pApp->m_mapGDI.find(m_pData->hGDIObject);
if (m != pApp->m_mapGDI.end())
{
pApp->m_mapGDI.erase(m);
Success = TRUE;
}
pApp->m_csMapLock.Release();
}
}
return Success;
}
///////////////////////////////////////////////
// Declarations for the CBitmap class
//
inline CBitmap::CBitmap()
{
}
inline CBitmap::CBitmap(HBITMAP hBitmap)
{
assert(m_pData);
Attach(hBitmap);
}
inline CBitmap::CBitmap(LPCTSTR lpszName)
{
LoadBitmap(lpszName);
}
inline CBitmap::CBitmap(int nID)
{
LoadBitmap(nID);
}
inline CBitmap::operator HBITMAP() const
{
assert(m_pData);
return (HBITMAP)m_pData->hGDIObject;
}
inline CBitmap::~CBitmap()
{
}
inline BOOL CBitmap::LoadBitmap(int nID)
// Loads a bitmap from a resource using the resource ID.
{
return LoadBitmap(MAKEINTRESOURCE(nID));
}
inline BOOL CBitmap::LoadBitmap(LPCTSTR lpszName)
// Loads a bitmap from a resource using the resource string.
{
assert(GetApp());
assert(m_pData);
HBITMAP hBitmap = (HBITMAP)::LoadImage(GetApp()->GetResourceHandle(), lpszName, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
if (hBitmap)
{
Attach(hBitmap);
}
return (0 != hBitmap); // boolean expression
}
inline BOOL CBitmap::LoadImage(UINT nID, int cxDesired, int cyDesired, UINT fuLoad)
// Loads a bitmap from a resource using the resource ID.
{
return LoadImage(MAKEINTRESOURCE(nID), cxDesired, cyDesired, fuLoad);
}
inline BOOL CBitmap::LoadImage(LPCTSTR lpszName, int cxDesired, int cyDesired, UINT fuLoad)
// Loads a bitmap from a resource using the resource string.
{
assert(GetApp());
assert(m_pData);
HBITMAP hBitmap = (HBITMAP)::LoadImage(GetApp()->GetResourceHandle(), lpszName, IMAGE_BITMAP, cxDesired, cyDesired, fuLoad);
if (hBitmap)
{
Attach(hBitmap);
}
return (0 != hBitmap); // boolean expression
}
inline BOOL CBitmap::LoadOEMBitmap(UINT nIDBitmap) // for OBM_/OCR_/OIC_
// Loads a predefined bitmap
// Predefined bitmaps include: OBM_BTNCORNERS, OBM_BTSIZE, OBM_CHECK, OBM_CHECKBOXES, OBM_CLOSE, OBM_COMBO
// OBM_DNARROW, OBM_DNARROWD, OBM_DNARROWI, OBM_LFARROW, OBM_LFARROWD, OBM_LFARROWI, OBM_MNARROW,OBM_OLD_CLOSE
// OBM_OLD_DNARROW, OBM_OLD_LFARROW, OBM_OLD_REDUCE, OBM_OLD_RESTORE, OBM_OLD_RGARROW, OBM_OLD_UPARROW
// OBM_OLD_ZOOM, OBM_REDUCE, OBM_REDUCED, OBM_RESTORE, OBM_RESTORED, OBM_RGARROW, OBM_RGARROWD, OBM_RGARROWI
// OBM_SIZE, OBM_UPARROW, OBM_UPARROWD, OBM_UPARROWI, OBM_ZOOM, OBM_ZOOMD
{
assert(m_pData);
HBITMAP hBitmap = ::LoadBitmap(NULL, MAKEINTRESOURCE(nIDBitmap));
if (hBitmap)
{
Attach( ::LoadBitmap(NULL, MAKEINTRESOURCE(nIDBitmap)) );
}
return (0 != hBitmap); // boolean expression
}
#ifndef _WIN32_WCE
inline HBITMAP CBitmap::CreateMappedBitmap(UINT nIDBitmap, UINT nFlags /*= 0*/, LPCOLORMAP lpColorMap /*= NULL*/, int nMapSize /*= 0*/)
// Creates a new bitmap using the bitmap data and colors specified by the bitmap resource and the color mapping information.
{
assert(GetApp());
assert(m_pData);
HBITMAP hBitmap = ::CreateMappedBitmap(GetApp()->GetResourceHandle(), nIDBitmap, (WORD)nFlags, lpColorMap, nMapSize);
Attach(hBitmap);
return hBitmap;
}
#endif // !_WIN32_WCE
inline HBITMAP CBitmap::CreateBitmap(int nWidth, int nHeight, UINT nPlanes, UINT nBitsPerPixel, LPCVOID lpBits)
// Creates a bitmap with the specified width, height, and color format (color planes and bits-per-pixel).
{
assert(m_pData);
HBITMAP hBitmap = ::CreateBitmap(nWidth, nHeight, nPlanes, nBitsPerPixel, lpBits);
Attach(hBitmap);
return hBitmap;
}
#ifndef _WIN32_WCE
inline HBITMAP CBitmap::CreateBitmapIndirect(LPBITMAP lpBitmap)
// Creates a bitmap with the width, height, and color format specified in the BITMAP structure.
{
assert(m_pData);
HBITMAP hBitmap = ::CreateBitmapIndirect(lpBitmap);
Attach(hBitmap);
return hBitmap;
}
#endif // !_WIN32_WCE
inline HBITMAP CBitmap::CreateCompatibleBitmap(CDC* pDC, int nWidth, int nHeight)
// Creates a bitmap compatible with the device that is associated with the specified device context.
{
assert(m_pData);
assert(pDC);
HBITMAP hBitmap = ::CreateCompatibleBitmap(pDC->GetHDC(), nWidth, nHeight);
Attach(hBitmap);
return hBitmap;
}
// Attributes
inline BITMAP CBitmap::GetBitmapData() const
// Retrieves the BITMAP structure
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
BITMAP bmp = {0};
::GetObject(m_pData->hGDIObject, sizeof(BITMAP), &bmp);
return bmp;
}
#ifndef _WIN32_WCE
inline CSize CBitmap::GetBitmapDimensionEx() const
// Retrieves the dimensions of a compatible bitmap.
// The retrieved dimensions must have been set by the SetBitmapDimensionEx function.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
CSize Size;
::GetBitmapDimensionEx((HBITMAP)m_pData->hGDIObject, &Size);
return Size;
}
inline CSize CBitmap::SetBitmapDimensionEx(int nWidth, int nHeight)
// The SetBitmapDimensionEx function assigns preferred dimensions to a bitmap.
// These dimensions can be used by applications; however, they are not used by the system.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
CSize Size;
::SetBitmapDimensionEx((HBITMAP)m_pData->hGDIObject, nWidth, nHeight, Size);
return Size;
}
// DIB support
inline HBITMAP CBitmap::CreateDIBitmap(CDC* pDC, CONST BITMAPINFOHEADER* lpbmih, DWORD dwInit, CONST VOID* lpbInit, CONST BITMAPINFO* lpbmi, UINT uColorUse)
// Creates a compatible bitmap (DDB) from a DIB and, optionally, sets the bitmap bits.
{
assert(m_pData);
assert(pDC);
HBITMAP hBitmap = ::CreateDIBitmap(pDC->GetHDC(), lpbmih, dwInit, lpbInit, lpbmi, uColorUse);
Attach(hBitmap);
return hBitmap;
}
#endif // !_WIN32_WCE
inline HBITMAP CBitmap::CreateDIBSection(CDC* pDC, CONST BITMAPINFO* lpbmi, UINT uColorUse, VOID** ppvBits, HANDLE hSection, DWORD dwOffset)
// Creates a DIB that applications can write to directly. The function gives you a pointer to the location of the bitmap bit values.
// You can supply a handle to a file-mapping object that the function will use to create the bitmap, or you can let the system allocate the memory for the bitmap.
{
assert(m_pData);
assert(pDC);
HBITMAP hBitmap = ::CreateDIBSection(pDC->GetHDC(), lpbmi, uColorUse, ppvBits, hSection, dwOffset);
Attach(hBitmap);
return hBitmap;
}
#ifndef _WIN32_WCE
inline int CBitmap::GetDIBits(CDC* pDC, UINT uStartScan, UINT cScanLines, LPVOID lpvBits, LPBITMAPINFO lpbmi, UINT uColorUse) const
// Retrieves the bits of the specified compatible bitmap and copies them into a buffer as a DIB using the specified format.
{
assert(m_pData);
assert(pDC);
assert(m_pData->hGDIObject != NULL);
return ::GetDIBits(pDC->GetHDC(), (HBITMAP)m_pData->hGDIObject, uStartScan, cScanLines, lpvBits, lpbmi, uColorUse);
}
inline int CBitmap::SetDIBits(CDC* pDC, UINT uStartScan, UINT cScanLines, CONST VOID* lpvBits, CONST BITMAPINFO* lpbmi, UINT uColorUse)
// Sets the pixels in a compatible bitmap (DDB) using the color data found in the specified DIB.
{
assert(m_pData);
assert(pDC);
assert(m_pData->hGDIObject != NULL);
return ::SetDIBits(pDC->GetHDC(), (HBITMAP)m_pData->hGDIObject, uStartScan, cScanLines, lpvBits, lpbmi, uColorUse);
}
#endif // !_WIN32_WCE
///////////////////////////////////////////////
// Definitions of the CBrush class
//
inline CBrush::CBrush()
{
}
inline CBrush::CBrush(HBRUSH hBrush)
{
assert(m_pData);
Attach(hBrush);
}
inline CBrush::CBrush(COLORREF crColor)
{
Attach( ::CreateSolidBrush(crColor) );
assert (m_pData->hGDIObject);
}
inline CBrush::operator HBRUSH() const
{
assert(m_pData);
return (HBRUSH)m_pData->hGDIObject;
}
inline CBrush::~CBrush()
{
}
inline HBRUSH CBrush::CreateSolidBrush(COLORREF crColor)
// Creates a logical brush that has the specified solid color.
{
assert(m_pData);
HBRUSH hBrush = ::CreateSolidBrush(crColor);
Attach(hBrush);
return hBrush;
}
#ifndef _WIN32_WCE
inline HBRUSH CBrush::CreateHatchBrush(int nIndex, COLORREF crColor)
// Creates a logical brush that has the specified hatch pattern and color.
{
assert(m_pData);
HBRUSH hBrush = ::CreateHatchBrush(nIndex, crColor);
Attach(hBrush);
return hBrush;
}
inline HBRUSH CBrush::CreateBrushIndirect(LPLOGBRUSH lpLogBrush)
// Creates a logical brush from style, color, and pattern specified in the LOGPRUSH struct.
{
assert(m_pData);
HBRUSH hBrush = ::CreateBrushIndirect(lpLogBrush);
Attach(hBrush);
return hBrush;
}
inline HBRUSH CBrush::CreateDIBPatternBrush(HGLOBAL hglbDIBPacked, UINT fuColorSpec)
// Creates a logical brush that has the pattern specified by the specified device-independent bitmap (DIB).
{
assert(m_pData);
HBRUSH hBrush = ::CreateDIBPatternBrush(hglbDIBPacked, fuColorSpec);
Attach(hBrush);
return hBrush;
}
inline HBRUSH CBrush::CreateDIBPatternBrushPt(LPCVOID lpPackedDIB, UINT nUsage)
// Creates a logical brush that has the pattern specified by the device-independent bitmap (DIB).
{
assert(m_pData);
HBRUSH hBrush = ::CreateDIBPatternBrushPt(lpPackedDIB, nUsage);
Attach(hBrush);
return hBrush;
}
#endif // !defined(_WIN32_WCE)
inline HBRUSH CBrush::CreatePatternBrush(CBitmap* pBitmap)
// Creates a logical brush with the specified bitmap pattern. The bitmap can be a DIB section bitmap,
// which is created by the CreateDIBSection function, or it can be a device-dependent bitmap.
{
assert(m_pData);
assert(pBitmap);
HBRUSH hBrush = ::CreatePatternBrush(*pBitmap);
Attach(hBrush);
return hBrush;
}
inline LOGBRUSH CBrush::GetLogBrush() const
// Retrieves the LOGBRUSH structure that defines the style, color, and pattern of a physical brush.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
LOGBRUSH LogBrush = {0};
::GetObject (m_pData->hGDIObject, sizeof(LOGBRUSH), &LogBrush);
return LogBrush;
}
///////////////////////////////////////////////
// Definitions of the CFont class
//
inline CFont::CFont()
{
}
inline CFont::CFont(HFONT hFont)
{
assert(m_pData);
Attach(hFont);
}
inline CFont::CFont(const LOGFONT* lpLogFont)
{
assert(m_pData);
Attach( ::CreateFontIndirect(lpLogFont) );
}
inline CFont::operator HFONT() const
{
assert(m_pData);
return (HFONT)m_pData->hGDIObject;
}
inline CFont::~CFont()
{
}
inline HFONT CFont::CreateFontIndirect(const LOGFONT* lpLogFont)
// Creates a logical font that has the specified characteristics.
{
assert(m_pData);
HFONT hFont = ::CreateFontIndirect(lpLogFont);
Attach(hFont);
return hFont;
}
inline HFONT CFont::CreatePointFont(int nPointSize, LPCTSTR lpszFaceName, CDC* pDC /*= NULL*/, BOOL bBold /*= FALSE*/, BOOL bItalic /*= FALSE*/)
// Creates a font of a specified typeface and point size.
{
LOGFONT logFont = { 0 };
logFont.lfCharSet = DEFAULT_CHARSET;
logFont.lfHeight = nPointSize;
lstrcpy(logFont.lfFaceName, lpszFaceName);
if (bBold)
logFont.lfWeight = FW_BOLD;
if (bItalic)
logFont.lfItalic = (BYTE)TRUE;
return CreatePointFontIndirect(&logFont, pDC);
}
inline HFONT CFont::CreatePointFontIndirect(const LOGFONT* lpLogFont, CDC* pDC /* = NULL*/)
// Creates a font of a specified typeface and point size.
// This function automatically converts the height in lfHeight to logical units using the specified device context.
{
HDC hDC = pDC? pDC->GetHDC() : NULL;
HDC hDC1 = (hDC != NULL) ? hDC : ::GetDC(HWND_DESKTOP);
// convert nPointSize to logical units based on hDC
LOGFONT logFont = *lpLogFont;
#ifndef _WIN32_WCE
POINT pt = { 0, 0 };
pt.y = ::MulDiv(::GetDeviceCaps(hDC1, LOGPIXELSY), logFont.lfHeight, 720); // 72 points/inch, 10 decipoints/point
::DPtoLP(hDC1, &pt, 1);
POINT ptOrg = { 0, 0 };
::DPtoLP(hDC1, &ptOrg, 1);
logFont.lfHeight = -abs(pt.y - ptOrg.y);
#else // CE specific
// DP and LP are always the same on CE
logFont.lfHeight = -abs(((::GetDeviceCaps(hDC1, LOGPIXELSY)* logFont.lfHeight)/ 720));
#endif // _WIN32_WCE
if (hDC == NULL)
::ReleaseDC (NULL, hDC1);
return CreateFontIndirect (&logFont);
}
#ifndef _WIN32_WCE
inline HFONT CFont::CreateFont(int nHeight, int nWidth, int nEscapement,
int nOrientation, int nWeight, DWORD dwItalic, DWORD dwUnderline,
DWORD dwStrikeOut, DWORD dwCharSet, DWORD dwOutPrecision,
DWORD dwClipPrecision, DWORD dwQuality, DWORD dwPitchAndFamily,
LPCTSTR lpszFacename)
// Creates a logical font with the specified characteristics.
{
HFONT hFont = ::CreateFont(nHeight, nWidth, nEscapement,
nOrientation, nWeight, dwItalic, dwUnderline, dwStrikeOut,
dwCharSet, dwOutPrecision, dwClipPrecision, dwQuality,
dwPitchAndFamily, lpszFacename);
Attach(hFont);
return hFont;
}
#endif // #ifndef _WIN32_WCE
inline LOGFONT CFont::GetLogFont() const
// Retrieves the Logfont structure that contains font attributes.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
LOGFONT LogFont = {0};
::GetObject(m_pData->hGDIObject, sizeof(LOGFONT), &LogFont);
return LogFont;
}
///////////////////////////////////////////////
// Definitions of the CPalette class
//
inline CPalette::CPalette()
{
}
inline CPalette::CPalette(HPALETTE hPalette)
{
Attach(hPalette);
}
inline CPalette::operator HPALETTE() const
{
assert(m_pData);
return (HPALETTE)m_pData->hGDIObject;
}
inline CPalette::~CPalette ()
{
}
inline HPALETTE CPalette::CreatePalette(LPLOGPALETTE lpLogPalette)
// Creates a logical palette from the information in the specified LOGPALETTE structure.
{
assert(m_pData);
HPALETTE hPalette = ::CreatePalette (lpLogPalette);
Attach(hPalette);
return hPalette;
}
#ifndef _WIN32_WCE
inline HPALETTE CPalette::CreateHalftonePalette(CDC* pDC)
// Creates a halftone palette for the specified device context (DC).
{
assert(m_pData);
assert(pDC);
HPALETTE hPalette = ::CreateHalftonePalette(pDC->GetHDC());
Attach(hPalette);
return hPalette;
}
#endif // !_WIN32_WCE
inline int CPalette::GetEntryCount() const
// Retrieve the number of entries in the palette.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
WORD nEntries = 0;
::GetObject(m_pData->hGDIObject, sizeof(WORD), &nEntries);
return (int)nEntries;
}
inline UINT CPalette::GetPaletteEntries(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors) const
// Retrieves a specified range of palette entries from the palette.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
return ::GetPaletteEntries((HPALETTE)m_pData->hGDIObject, nStartIndex, nNumEntries, lpPaletteColors);
}
inline UINT CPalette::SetPaletteEntries(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors)
// Sets RGB (red, green, blue) color values and flags in a range of entries in the palette.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
return ::SetPaletteEntries((HPALETTE)m_pData->hGDIObject, nStartIndex, nNumEntries, lpPaletteColors);
}
#ifndef _WIN32_WCE
inline void CPalette::AnimatePalette(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors)
// Replaces entries in the palette.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
::AnimatePalette((HPALETTE)m_pData->hGDIObject, nStartIndex, nNumEntries, lpPaletteColors);
}
inline BOOL CPalette::ResizePalette(UINT nNumEntries)
// Increases or decreases the size of the palette based on the specified value.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
return ::ResizePalette((HPALETTE)m_pData->hGDIObject, nNumEntries);
}
#endif // !_WIN32_WCE
inline UINT CPalette::GetNearestPaletteIndex(COLORREF crColor) const
// Retrieves the index for the entry in the palette most closely matching a specified color value.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
return ::GetNearestPaletteIndex((HPALETTE)m_pData->hGDIObject, crColor);
}
///////////////////////////////////////////////
// Declarations for the CPen class
//
inline CPen::CPen()
{
}
inline CPen::CPen(HPEN hPen)
{
Attach(hPen);
}
inline CPen::CPen(int nPenStyle, int nWidth, COLORREF crColor)
{
assert(m_pData);
Attach( ::CreatePen(nPenStyle, nWidth, crColor) );
}
#ifndef _WIN32_WCE
inline CPen::CPen(int nPenStyle, int nWidth, const LOGBRUSH* pLogBrush, int nStyleCount /*= 0*/, const DWORD* lpStyle /*= NULL*/)
{
assert(m_pData);
Attach( ::ExtCreatePen(nPenStyle, nWidth, pLogBrush, nStyleCount, lpStyle) );
}
#endif // !_WIN32_WCE
inline CPen::operator HPEN () const
{
assert(m_pData);
return (HPEN)m_pData->hGDIObject;
}
inline CPen::~CPen()
{
}
inline HPEN CPen::CreatePen(int nPenStyle, int nWidth, COLORREF crColor)
// Creates a logical pen that has the specified style, width, and color.
{
assert(m_pData);
HPEN hPen = ::CreatePen(nPenStyle, nWidth, crColor);
Attach(hPen);
return hPen;
}
inline HPEN CPen::CreatePenIndirect(LPLOGPEN lpLogPen)
// Creates a logical cosmetic pen that has the style, width, and color specified in a structure.
{
assert(m_pData);
HPEN hPen = ::CreatePenIndirect(lpLogPen);
Attach(hPen);
return hPen;
}
inline LOGPEN CPen::GetLogPen() const
{
// Retrieves the LOGPEN struct that specifies the pen's style, width, and color.
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
LOGPEN LogPen = {0};
::GetObject(m_pData->hGDIObject, sizeof(LOGPEN), &LogPen);
return LogPen;
}
#ifndef _WIN32_WCE
inline HPEN CPen::ExtCreatePen(int nPenStyle, int nWidth, const LOGBRUSH* pLogBrush, int nStyleCount /* = 0*/, const DWORD* lpStyle /*= NULL*/)
// Creates a logical cosmetic or geometric pen that has the specified style, width, and brush attributes.
{
assert(m_pData);
HPEN hPen = ::ExtCreatePen(nPenStyle, nWidth, pLogBrush, nStyleCount, lpStyle);
Attach(hPen);
return hPen;
}
inline EXTLOGPEN CPen::GetExtLogPen() const
// Retrieves the EXTLOGPEN struct that specifies the pen's style, width, color and brush attributes.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
EXTLOGPEN ExLogPen = {0};
::GetObject(m_pData->hGDIObject, sizeof(EXTLOGPEN), &ExLogPen);
return ExLogPen;
}
#endif // !_WIN32_WCE
///////////////////////////////////////////////
// Definitions of the CRgn class
//
inline CRgn::CRgn()
{
}
inline CRgn::CRgn(HRGN hRgn)
{
assert(m_pData);
Attach(hRgn);
}
inline CRgn::operator HRGN() const
{
assert(m_pData);
return (HRGN)m_pData->hGDIObject;
}
inline CRgn::~CRgn()
{
}
inline HRGN CRgn::CreateRectRgn(int x1, int y1, int x2, int y2)
// Creates a rectangular region.
{
assert(m_pData);
HRGN hRgn = ::CreateRectRgn(x1, y1, x2, y2);
Attach(hRgn);
return hRgn;
}
inline HRGN CRgn::CreateRectRgnIndirect(const RECT& rc)
// Creates a rectangular region.
{
assert(m_pData);
HRGN hRgn = ::CreateRectRgnIndirect(&rc);
Attach(hRgn);
return hRgn;
}
#ifndef _WIN32_WCE
inline HRGN CRgn::CreateEllipticRgn(int x1, int y1, int x2, int y2)
// Creates an elliptical region.
{
assert(m_pData);
HRGN hRgn = ::CreateEllipticRgn(x1, y1, x2, y2);
Attach(hRgn);
return hRgn;
}
inline HRGN CRgn::CreateEllipticRgnIndirect(const RECT& rc)
// Creates an elliptical region.
{
assert(m_pData);
HRGN hRgn = ::CreateEllipticRgnIndirect(&rc);
Attach(hRgn);
return hRgn;
}
inline HRGN CRgn::CreatePolygonRgn(LPPOINT lpPoints, int nCount, int nMode)
// Creates a polygonal region.
{
assert(m_pData);
HRGN hRgn = ::CreatePolygonRgn(lpPoints, nCount, nMode);
Attach(hRgn);
return hRgn;
}
inline HRGN CRgn::CreatePolyPolygonRgn(LPPOINT lpPoints, LPINT lpPolyCounts, int nCount, int nPolyFillMode)
// Creates a region consisting of a series of polygons. The polygons can overlap.
{
assert(m_pData);
HRGN hRgn = ::CreatePolyPolygonRgn(lpPoints, lpPolyCounts, nCount, nPolyFillMode);
Attach(hRgn);
return hRgn;
}
inline HRGN CRgn::CreateRoundRectRgn(int x1, int y1, int x2, int y2, int x3, int y3)
// Creates a rectangular region with rounded corners.
{
assert(m_pData);
HRGN hRgn = ::CreateRoundRectRgn(x1, y1, x2, y2, x3, y3);
Attach(hRgn);
return hRgn;
}
inline HRGN CRgn::CreateFromPath(HDC hDC)
// Creates a region from the path that is selected into the specified device context.
// The resulting region uses device coordinates.
{
assert(m_pData);
assert(hDC != NULL);
HRGN hRgn = ::PathToRegion(hDC);
Attach(hRgn);
return hRgn;
}
#endif // !_WIN32_WCE
inline HRGN CRgn::CreateFromData(const XFORM* lpXForm, int nCount, const RGNDATA* pRgnData)
// Creates a region from the specified region and transformation data.
{
assert(m_pData);
HRGN hRgn = ::ExtCreateRegion(lpXForm, nCount, pRgnData);
Attach(hRgn);
return hRgn;
}
inline void CRgn::SetRectRgn(int x1, int y1, int x2, int y2)
// converts the region into a rectangular region with the specified coordinates.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
::SetRectRgn((HRGN)m_pData->hGDIObject, x1, y1, x2, y2);
}
inline void CRgn::SetRectRgn(const RECT& rc)
// converts the region into a rectangular region with the specified coordinates.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
::SetRectRgn((HRGN)m_pData->hGDIObject, rc.left, rc.top, rc.right, rc.bottom);
}
inline int CRgn::CombineRgn(CRgn* pRgnSrc1, CRgn* pRgnSrc2, int nCombineMode)
// Combines two sepcified regions and stores the result.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
assert(pRgnSrc1);
assert(pRgnSrc2);
return ::CombineRgn((HRGN)m_pData->hGDIObject, *pRgnSrc1, *pRgnSrc2, nCombineMode);
}
inline int CRgn::CombineRgn(CRgn* pRgnSrc, int nCombineMode)
// Combines the sepcified region with the current region.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
assert(pRgnSrc);
return ::CombineRgn((HRGN)m_pData->hGDIObject, (HRGN)m_pData->hGDIObject, *pRgnSrc, nCombineMode);
}
inline int CRgn::CopyRgn(CRgn* pRgnSrc)
// Assigns the specified region to the current region.
{
assert(m_pData);
assert(m_pData->hGDIObject == NULL);
assert(pRgnSrc);
return ::CombineRgn((HRGN)m_pData->hGDIObject, *pRgnSrc, NULL, RGN_COPY);
}
inline BOOL CRgn::EqualRgn(CRgn* pRgn) const
// Checks the two specified regions to determine whether they are identical.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
assert(pRgn);
return ::EqualRgn((HRGN)m_pData->hGDIObject, *pRgn);
}
inline int CRgn::OffsetRgn(int x, int y)
// Moves a region by the specified offsets.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
return ::OffsetRgn((HRGN)m_pData->hGDIObject, x, y);
}
inline int CRgn::OffsetRgn(POINT& pt)
// Moves a region by the specified offsets.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
return ::OffsetRgn((HRGN)m_pData->hGDIObject, pt.x, pt.y);
}
inline int CRgn::GetRgnBox(RECT& rc) const
// Retrieves the bounding rectangle of the region, and stores it in the specified RECT.
// The return value indicates the region's complexity: NULLREGION;SIMPLEREGION; or COMPLEXREGION.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
return ::GetRgnBox((HRGN)m_pData->hGDIObject, &rc);
}
inline int CRgn::GetRegionData(LPRGNDATA lpRgnData, int nDataSize) const
// Fills the specified buffer with data describing a region.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
return (int)::GetRegionData((HRGN)m_pData->hGDIObject, nDataSize, lpRgnData);
}
inline BOOL CRgn::PtInRegion(int x, int y) const
// Determines whether the specified point is inside the specified region.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
return ::PtInRegion((HRGN)m_pData->hGDIObject, x, y);
}
inline BOOL CRgn::PtInRegion(POINT& pt) const
// Determines whether the specified point is inside the specified region.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
return ::PtInRegion((HRGN)m_pData->hGDIObject, pt.x, pt.y);
}
inline BOOL CRgn::RectInRegion(const RECT& rc) const
// Determines whether the specified rect is inside the specified region.
{
assert(m_pData);
assert(m_pData->hGDIObject != NULL);
return ::RectInRegion((HRGN)m_pData->hGDIObject, &rc);
}
///////////////////////////////////////////////
// Definitions of the CDC class
//
inline CDC::CDC()
{
// Allocate memory for our data members
m_pData = new DataMembers;
// Assign values to our data members
m_pData->hDC = 0;
m_pData->Count = 1L;
m_pData->bRemoveHDC = TRUE;
m_pData->hWnd = 0;
}
inline CDC::CDC(HDC hDC, HWND hWnd /*= 0*/)
// This constructor assigns an existing HDC to the CDC
// The HDC WILL be released or deleted when the CDC object is destroyed
// The hWnd paramter is only used in WindowsCE. It specifies the HWND of a Window or
// Window Client DC
// Note: this constructor permits a call like this:
// CDC MyCDC = SomeHDC;
// or
// CDC MyCDC = ::CreateCompatibleDC(SomeHDC);
// or
// CDC MyCDC = ::GetDC(SomeHWND);
{
UNREFERENCED_PARAMETER(hWnd);
assert(hDC);
CDC* pDC = GetApp()->GetCDCFromMap(hDC);
if (pDC)
{
m_pData = pDC->m_pData;
InterlockedIncrement(&m_pData->Count);
}
else
{
// Allocate memory for our data members
m_pData = new DataMembers;
// Assign values to our data members
m_pData->hDC = hDC;
m_pData->Count = 1L;
m_pData->bRemoveHDC = TRUE;
m_pData->nSavedDCState = ::SaveDC(hDC);
#ifndef _WIN32_WCE
m_pData->hWnd = ::WindowFromDC(hDC);
#else
m_pData->hWnd = hWnd;
#endif
if (m_pData->hWnd)
AddToMap();
}
}
#ifndef _WIN32_WCE
inline void CDC::operator = (const HDC hDC)
// Note: this assignment operater permits a call like this:
// CDC MyCDC;
// MyCDC = SomeHDC;
{
Attach(hDC);
}
#endif
inline CDC::CDC(const CDC& rhs) // Copy constructor
// The copy constructor is called when a temporary copy of the CDC needs to be created.
// This can happen when a CDC is passed by value in a function call. Each CDC copy manages
// the same Device Context and GDI objects.
{
m_pData = rhs.m_pData;
InterlockedIncrement(&m_pData->Count);
}
inline CDC& CDC::operator = (const CDC& rhs)
// Note: A copy of a CDC is a clone of the original.
// Both objects manipulate the one HDC
{
if (this != &rhs)
{
InterlockedIncrement(&rhs.m_pData->Count);
Release();
m_pData = rhs.m_pData;
}
return *this;
}
inline CDC::~CDC ()
{
Release();
}
inline void CDC::AddToMap()
// Store the HDC and CDC pointer in the HDC map
{
assert( GetApp() );
assert(m_pData->hDC);
GetApp()->m_csMapLock.Lock();
assert(m_pData->hDC);
assert(!GetApp()->GetCDCFromMap(m_pData->hDC));
GetApp()->m_mapHDC.insert(std::make_pair(m_pData->hDC, this));
GetApp()->m_csMapLock.Release();
}
inline void CDC::Attach(HDC hDC, HWND hWnd /* = 0*/)
// Attaches a HDC to the CDC object.
// The HDC will be automatically deleted or released when the destructor is called.
// The hWnd parameter is only used on WindowsCE. It specifies the HWND of a Window or
// Window Client DC
{
UNREFERENCED_PARAMETER(hWnd);
assert(m_pData);
assert(0 == m_pData->hDC);
assert(hDC);
CDC* pDC = GetApp()->GetCDCFromMap(hDC);
if (pDC)
{
delete m_pData;
m_pData = pDC->m_pData;
InterlockedIncrement(&m_pData->Count);
}
else
{
m_pData->hDC = hDC;
#ifndef _WIN32_WCE
m_pData->hWnd = ::WindowFromDC(hDC);
#else
m_pData->hWnd = hWnd;
#endif
if (m_pData->hWnd == 0)
AddToMap();
m_pData->nSavedDCState = ::SaveDC(hDC);
}
}
inline HDC CDC::Detach()
// Detaches the HDC from this object.
{
assert(m_pData);
assert(m_pData->hDC);
GetApp()->m_csMapLock.Lock();
RemoveFromMap();
HDC hDC = m_pData->hDC;
m_pData->hDC = 0;
if (m_pData->Count)
{
if (InterlockedDecrement(&m_pData->Count) == 0)
{
delete m_pData;
}
}
GetApp()->m_csMapLock.Release();
// Assign values to our data members
m_pData = new DataMembers;
m_pData->hDC = 0;
m_pData->Count = 1L;
m_pData->bRemoveHDC = TRUE;
m_pData->hWnd = 0;
return hDC;
}
// Initialization
inline BOOL CDC::CreateCompatibleDC(CDC* pDC)
// Returns a memory device context (DC) compatible with the specified device.
{
assert(m_pData->hDC == NULL);
HDC hdcSource = (pDC == NULL)? NULL : pDC->GetHDC();
HDC hDC = ::CreateCompatibleDC(hdcSource);
if (hDC)
{
m_pData->hDC = hDC;
AddToMap();
}
return (hDC != NULL); // boolean expression
}
inline BOOL CDC::CreateDC(LPCTSTR lpszDriver, LPCTSTR lpszDevice, LPCTSTR lpszOutput, const DEVMODE* pInitData)
// Returns a device context (DC) for a device using the specified name.
{
assert(m_pData->hDC == NULL);
HDC hDC = ::CreateDC(lpszDriver, lpszDevice, lpszOutput, pInitData);
if (hDC)
{
m_pData->hDC = hDC;
AddToMap();
}
return (hDC != NULL); // boolean expression
}
#ifndef _WIN32_WCE
inline BOOL CDC::CreateIC(LPCTSTR lpszDriver, LPCTSTR lpszDevice, LPCTSTR lpszOutput, const DEVMODE* pInitData)
{
assert(m_pData->hDC == NULL);
HDC hDC = ::CreateIC(lpszDriver, lpszDevice, lpszOutput, pInitData);
if (hDC)
{
m_pData->hDC = hDC;
AddToMap();
}
return (hDC != NULL); // boolean expression
}
#endif
inline void CDC::DrawBitmap(int x, int y, int cx, int cy, CBitmap& Bitmap, COLORREF clrMask)
// Draws the specified bitmap to the specified DC using the mask colour provided as the transparent colour
// Suitable for use with a Window DC or a memory DC
{
// Create the Image memory DC
CMemDC dcImage(this);
dcImage.SetBkColor(clrMask);
dcImage.SelectObject(&Bitmap);
// Create the Mask memory DC
CMemDC dcMask(this);
dcMask.CreateBitmap(cx, cy, 1, 1, NULL);
dcMask.BitBlt(0, 0, cx, cy, &dcImage, 0, 0, SRCCOPY);
// Mask the image to 'this' DC
BitBlt(x, y, cx, cy, &dcImage, 0, 0, SRCINVERT);
BitBlt(x, y, cx, cy, &dcMask, 0, 0, SRCAND);
BitBlt(x, y, cx, cy, &dcImage, 0, 0, SRCINVERT);
}
inline CDC* CDC::AddTempHDC(HDC hDC, HWND hWnd)
// Returns the CDC object associated with the device context handle
// The HDC is removed when the CDC is destroyed
{
assert( GetApp() );
CDC* pDC = new CDC;
pDC->m_pData->hDC = hDC;
GetApp()->AddTmpDC(pDC);
pDC->m_pData->bRemoveHDC = TRUE;
pDC->m_pData->hWnd = hWnd;
return pDC;
}
inline void CDC::GradientFill(COLORREF Color1, COLORREF Color2, const RECT& rc, BOOL bVertical)
// An efficient color gradient filler compatible with all Windows operating systems
{
int Width = rc.right - rc.left;
int Height = rc.bottom - rc.top;
int r1 = GetRValue(Color1);
int g1 = GetGValue(Color1);
int b1 = GetBValue(Color1);
int r2 = GetRValue(Color2);
int g2 = GetGValue(Color2);
int b2 = GetBValue(Color2);
COLORREF OldBkColor = GetBkColor();
if (bVertical)
{
for(int i=0; i < Width; ++i)
{
int r = r1 + (i * (r2-r1) / Width);
int g = g1 + (i * (g2-g1) / Width);
int b = b1 + (i * (b2-b1) / Width);
SetBkColor(RGB(r, g, b));
CRect line( i + rc.left, rc.top, i + 1 + rc.left, rc.top+Height);
ExtTextOut(0, 0, ETO_OPAQUE, line, NULL, 0, 0);
}
}
else
{
for(int i=0; i < Height; ++i)
{
int r = r1 + (i * (r2-r1) / Height);
int g = g1 + (i * (g2-g1) / Height);
int b = b1 + (i * (b2-b1) / Height);
SetBkColor(RGB(r, g, b));
CRect line(rc.left, i + rc.top, rc.left+Width, i + 1 + rc.top);
ExtTextOut(0, 0, ETO_OPAQUE, line, NULL, 0, 0);
}
}
SetBkColor(OldBkColor);
}
inline void CDC::Release()
{
GetApp()->m_csMapLock.Lock();
if (m_pData->Count)
{
if (InterlockedDecrement(&m_pData->Count) == 0)
{
Destroy();
delete m_pData;
m_pData = 0;
}
}
GetApp()->m_csMapLock.Release();
}
inline BOOL CDC::RemoveFromMap()
{
BOOL Success = FALSE;
if( GetApp() )
{
// Allocate an iterator for our HDC map
std::map<HDC, CDC*, CompareHDC>::iterator m;
CWinApp* pApp = GetApp();
if (pApp)
{
// Erase the CDC pointer entry from the map
pApp->m_csMapLock.Lock();
m = pApp->m_mapHDC.find(m_pData->hDC);
if (m != pApp->m_mapHDC.end())
{
pApp->m_mapHDC.erase(m);
Success = TRUE;
}
pApp->m_csMapLock.Release();
}
}
return Success;
}
inline void CDC::SolidFill(COLORREF Color, const RECT& rc)
// Fills a rectangle with a solid color
{
COLORREF OldColor = SetBkColor(Color);
ExtTextOut(0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
SetBkColor(OldColor);
}
// Bitmap functions
inline CBitmap* CDC::CreateCompatibleBitmap(CDC* pDC, int cx, int cy)
// Creates a compatible bitmap and selects it into the device context.
{
assert(m_pData->hDC);
assert(pDC);
CBitmap* pBitmap = new CBitmap;
pBitmap->CreateCompatibleBitmap(pDC, cx, cy);
m_pData->m_vGDIObjects.push_back(pBitmap);
return SelectObject(pBitmap);
}
inline CBitmap* CDC::CreateBitmap(int cx, int cy, UINT Planes, UINT BitsPerPixel, LPCVOID pvColors)
// Creates a bitmap and selects it into the device context.
// Returns a pointer to the old bitmap selected out of the device context
{
assert(m_pData->hDC);
CBitmap* pBitmap = new CBitmap;
pBitmap->CreateBitmap(cx, cy, Planes, BitsPerPixel, pvColors);
m_pData->m_vGDIObjects.push_back(pBitmap);
return SelectObject(pBitmap);
}
#ifndef _WIN32_WCE
inline CBitmap* CDC::CreateBitmapIndirect (LPBITMAP lpBitmap)
// Creates a bitmap and selects it into the device context.
// Returns a pointer to the old bitmap selected out of the device context
{
assert(m_pData->hDC);
CBitmap* pBitmap = new CBitmap;
pBitmap->CreateBitmapIndirect(lpBitmap);
m_pData->m_vGDIObjects.push_back(pBitmap);
return SelectObject(pBitmap);
}
inline CBitmap* CDC::CreateDIBitmap(CDC* pDC, const BITMAPINFOHEADER& bmih, DWORD fdwInit, LPCVOID lpbInit,
BITMAPINFO& bmi, UINT fuUsage)
// Creates a bitmap and selects it into the device context.
// Returns a pointer to the old bitmap selected out of the device context
{
assert(m_pData->hDC);
assert(pDC);
CBitmap* pBitmap = new CBitmap;
pBitmap->CreateDIBitmap(pDC, &bmih, fdwInit, lpbInit, &bmi, fuUsage);
m_pData->m_vGDIObjects.push_back(pBitmap);
return SelectObject(pBitmap);
}
#endif
inline CBitmap* CDC::CreateDIBSection(CDC* pDC, const BITMAPINFO& bmi, UINT iUsage, LPVOID *ppvBits,
HANDLE hSection, DWORD dwOffset)
// Creates a bitmap and selects it into the device context.
// Returns a pointer to the old bitmap selected out of the device context
{
assert(m_pData->hDC);
assert(pDC);
CBitmap* pBitmap = new CBitmap;
pBitmap->CreateDIBSection(pDC, &bmi, iUsage, ppvBits, hSection, dwOffset);
m_pData->m_vGDIObjects.push_back(pBitmap);
return SelectObject(pBitmap);
}
inline void CDC::Destroy()
// Deletes or releases the device context and returns the CDC object to its
// default state, ready for reuse.
{
if (m_pData->hDC)
{
RemoveFromMap();
if (m_pData->bRemoveHDC)
{
// Return the DC back to its initial state
::RestoreDC(m_pData->hDC, m_pData->nSavedDCState);
// We need to release a Window DC, and delete a memory DC
if (m_pData->hWnd)
::ReleaseDC(m_pData->hWnd, m_pData->hDC);
else
if (!::DeleteDC(m_pData->hDC))
::ReleaseDC(NULL, m_pData->hDC);
m_pData->hDC = 0;
m_pData->hWnd = 0;
m_pData->bRemoveHDC = TRUE;
}
}
// RemoveFromMap();
}
inline BITMAP CDC::GetBitmapData() const
// Retrieves the BITMAP information for the current HBITMAP.
{
assert(m_pData->hDC);
HBITMAP hbm = (HBITMAP)::GetCurrentObject(m_pData->hDC, OBJ_BITMAP);
BITMAP bm = {0};
::GetObject(hbm, sizeof(bm), &bm);
return bm;
}
inline CBitmap* CDC::LoadBitmap(UINT nID)
// Loads a bitmap from the resource and selects it into the device context
{
return LoadBitmap(MAKEINTRESOURCE(nID));
}
inline CBitmap* CDC::LoadBitmap(LPCTSTR lpszName)
// Loads a bitmap from the resource and selects it into the device context
// Returns a pointer to the old bitmap selected out of the device context
{
assert(m_pData->hDC);
CBitmap* pBitmap = new CBitmap;
BOOL bResult = pBitmap->LoadBitmap(lpszName);
m_pData->m_vGDIObjects.push_back(pBitmap);
return bResult? SelectObject(pBitmap) : NULL;
}
inline CBitmap* CDC::LoadImage(UINT nID, int cxDesired, int cyDesired, UINT fuLoad)
// Loads a bitmap from the resource and selects it into the device context
// Returns a pointer to the old bitmap selected out of the device context
{
return LoadImage(nID, cxDesired, cyDesired, fuLoad);
}
inline CBitmap* CDC::LoadImage(LPCTSTR lpszName, int cxDesired, int cyDesired, UINT fuLoad)
// Loads a bitmap from the resource and selects it into the device context
// Returns a pointer to the old bitmap selected out of the device context
{
assert(m_pData->hDC);
CBitmap* pBitmap = new CBitmap;
BOOL bResult = pBitmap->LoadImage(lpszName, cxDesired, cyDesired, fuLoad);
m_pData->m_vGDIObjects.push_back(pBitmap);
return bResult? SelectObject(pBitmap) : NULL;
}
inline CBitmap* CDC::LoadOEMBitmap(UINT nIDBitmap) // for OBM_/OCR_/OIC_
// Loads a predefined system bitmap and selects it into the device context
// Returns a pointer to the old bitmap selected out of the device context
{
assert(m_pData->hDC);
CBitmap* pBitmap = new CBitmap;
BOOL bResult = pBitmap->LoadOEMBitmap(nIDBitmap);
m_pData->m_vGDIObjects.push_back(pBitmap);
return bResult? SelectObject(pBitmap) : NULL;
}
#ifndef _WIN32_WCE
inline CBitmap* CDC::CreateMappedBitmap(UINT nIDBitmap, UINT nFlags /*= 0*/, LPCOLORMAP lpColorMap /*= NULL*/, int nMapSize /*= 0*/)
// creates and selects a new bitmap using the bitmap data and colors specified by the bitmap resource and the color mapping information.
// Returns a pointer to the old bitmap selected out of the device context
{
assert(m_pData->hDC);
CBitmap* pBitmap = new CBitmap;
pBitmap->CreateMappedBitmap(nIDBitmap, (WORD)nFlags, lpColorMap, nMapSize);
m_pData->m_vGDIObjects.push_back(pBitmap);
return SelectObject(pBitmap);
}
#endif // !_WIN32_WCE
// Brush functions
#ifndef _WIN32_WCE
inline CBrush* CDC::CreateBrushIndirect(LPLOGBRUSH pLogBrush)
// Creates the brush and selects it into the device context.
// Returns a pointer to the old brush selected out of the device context.
{
assert(m_pData->hDC);
CBrush* pBrush = new CBrush;
pBrush->CreateBrushIndirect(pLogBrush);
m_pData->m_vGDIObjects.push_back(pBrush);
return SelectObject(pBrush);
}
inline CBrush* CDC::CreateHatchBrush(int fnStyle, COLORREF rgb)
// Creates a brush with the specified hatch pattern and color, and selects it into the device context.
// Returns a pointer to the old brush selected out of the device context.
{
assert(m_pData->hDC);
CBrush* pBrush = new CBrush;
pBrush->CreateHatchBrush(fnStyle, rgb);
m_pData->m_vGDIObjects.push_back(pBrush);
return SelectObject(pBrush);
}
inline CBrush* CDC::CreateDIBPatternBrush(HGLOBAL hglbDIBPacked, UINT fuColorSpec)
// Creates a logical from the specified device-independent bitmap (DIB), and selects it into the device context.
// Returns a pointer to the old brush selected out of the device context.
{
assert(m_pData->hDC);
CBrush* pBrush = new CBrush;
pBrush->CreateDIBPatternBrush(hglbDIBPacked, fuColorSpec);
m_pData->m_vGDIObjects.push_back(pBrush);
return SelectObject(pBrush);
}
inline CBrush* CDC::CreateDIBPatternBrushPt(LPCVOID lpPackedDIB, UINT iUsage)
// Creates a logical from the specified device-independent bitmap (DIB), and selects it into the device context.
// Returns a pointer to the old brush selected out of the device context.
{
assert(m_pData->hDC);
CBrush* pBrush = new CBrush;
pBrush->CreateDIBPatternBrushPt(lpPackedDIB, iUsage);
m_pData->m_vGDIObjects.push_back(pBrush);
return SelectObject(pBrush);
}
#endif
inline CBrush* CDC::CreatePatternBrush(CBitmap* pBitmap)
// Creates the brush with the specified pattern, and selects it into the device context.
// Returns a pointer to the old brush selected out of the device context.
{
assert(m_pData->hDC);
assert(pBitmap);
CBrush* pBrush = new CBrush;
pBrush->CreatePatternBrush(pBitmap);
m_pData->m_vGDIObjects.push_back(pBrush);
return SelectObject(pBrush);
}
inline CBrush* CDC::CreateSolidBrush(COLORREF rgb)
// Creates the brush with the specified color, and selects it into the device context.
// Returns a pointer to the old brush selected out of the device context.
{
assert(m_pData->hDC);
CBrush* pBrush = new CBrush;
pBrush->CreateSolidBrush(rgb);
m_pData->m_vGDIObjects.push_back(pBrush);
return SelectObject(pBrush);
}
inline LOGBRUSH CDC::GetLogBrush() const
// Retrieves the current brush information
{
assert(m_pData->hDC);
HBRUSH hBrush = (HBRUSH)::GetCurrentObject(m_pData->hDC, OBJ_BRUSH);
LOGBRUSH lBrush = {0};
::GetObject(hBrush, sizeof(lBrush), &lBrush);
return lBrush;
}
// Font functions
#ifndef _WIN32_WCE
inline CFont* CDC::CreateFont (
int nHeight, // height of font
int nWidth, // average character width
int nEscapement, // angle of escapement
int nOrientation, // base-line orientation angle
int fnWeight, // font weight
DWORD fdwItalic, // italic attribute option
DWORD fdwUnderline, // underline attribute option
DWORD fdwStrikeOut, // strikeout attribute option
DWORD fdwCharSet, // character set identifier
DWORD fdwOutputPrecision, // output precision
DWORD fdwClipPrecision, // clipping precision
DWORD fdwQuality, // output quality
DWORD fdwPitchAndFamily, // pitch and family
LPCTSTR lpszFace // typeface name
)
// Creates a logical font with the specified characteristics.
// Returns a pointer to the old font selected out of the device context.
{
assert(m_pData->hDC);
CFont* pFont = new CFont;
pFont->CreateFont (nHeight, nWidth, nEscapement, nOrientation, fnWeight,
fdwItalic, fdwUnderline, fdwStrikeOut, fdwCharSet,
fdwOutputPrecision, fdwClipPrecision, fdwQuality,
fdwPitchAndFamily, lpszFace);
m_pData->m_vGDIObjects.push_back(pFont);
return SelectObject(pFont);
}
#endif
inline CFont* CDC::CreateFontIndirect(LPLOGFONT plf)
// Creates a logical font and selects it into the device context.
// Returns a pointer to the old font selected out of the device context.
{
assert(m_pData->hDC);
CFont* pFont = new CFont;
pFont->CreateFontIndirect(plf);
m_pData->m_vGDIObjects.push_back(pFont);
return SelectObject(pFont);
}
inline LOGFONT CDC::GetLogFont() const
// Retrieves the current font information.
{
assert(m_pData->hDC);
HFONT hFont = (HFONT)::GetCurrentObject(m_pData->hDC, OBJ_FONT);
LOGFONT lFont = {0};
::GetObject(hFont, sizeof(lFont), &lFont);
return lFont;
}
// Pen functions
inline CPen* CDC::CreatePen (int nStyle, int nWidth, COLORREF rgb)
// Creates the pen and selects it into the device context.
// Returns a pointer to the old pen selected out of the device context.
{
assert(m_pData->hDC);
CPen* pPen = new CPen;
pPen->CreatePen(nStyle, nWidth, rgb);
m_pData->m_vGDIObjects.push_back(pPen);
return SelectObject(pPen);
}
inline CPen* CDC::CreatePenIndirect (LPLOGPEN pLogPen)
// Creates the pen and selects it into the device context.
// Returns a pointer to the old pen selected out of the device context.
{
assert(m_pData->hDC);
CPen* pPen = new CPen;
pPen->CreatePenIndirect(pLogPen);
m_pData->m_vGDIObjects.push_back(pPen);
return SelectObject(pPen);
}
inline LOGPEN CDC::GetLogPen() const
// Retrieves the current pen information as a LOGPEN
{
assert(m_pData->hDC);
HPEN hPen = (HPEN)::GetCurrentObject(m_pData->hDC, OBJ_PEN);
LOGPEN lPen = {0};
::GetObject(hPen, sizeof(lPen), &lPen);
return lPen;
}
// Region functions
inline int CDC::CreateRectRgn(int left, int top, int right, int bottom)
// Creates a rectangular region from the rectangle co-ordinates.
// The return value specifies the region's complexity: NULLREGION;SIMPLEREGION;COMPLEXREGION;ERROR.
{
assert(m_pData->hDC);
CRgn* pRgn = new CRgn;
pRgn->CreateRectRgn(left, top, right, bottom);
m_pData->m_vGDIObjects.push_back(pRgn);
return SelectClipRgn(pRgn);
}
inline int CDC::CreateRectRgnIndirect(const RECT& rc)
// Creates a rectangular region from the rectangle co-ordinates.
// The return value specifies the region's complexity: NULLREGION;SIMPLEREGION;COMPLEXREGION;ERROR.
{
assert(m_pData->hDC);
CRgn* pRgn = new CRgn;
pRgn->CreateRectRgnIndirect(rc);
m_pData->m_vGDIObjects.push_back(pRgn);
return SelectClipRgn(pRgn);
}
inline int CDC::CreateFromData(const XFORM* Xform, DWORD nCount, const RGNDATA *pRgnData)
// Creates a region from the specified region data and tranformation data.
// The return value specifies the region's complexity: NULLREGION;SIMPLEREGION;COMPLEXREGION;ERROR.
// Notes: GetRegionData can be used to get a region's data
// If the XFROM pointer is NULL, the identity transformation is used.
{
assert(m_pData->hDC);
CRgn* pRgn = new CRgn;
pRgn->CreateFromData(Xform, nCount, pRgnData);
m_pData->m_vGDIObjects.push_back(pRgn);
return SelectClipRgn(pRgn);
}
#ifndef _WIN32_WCE
inline int CDC::CreateEllipticRgn(int left, int top, int right, int bottom)
// Creates the ellyiptical region from the bounding rectangle co-ordinates
// and selects it into the device context.
// The return value specifies the region's complexity: NULLREGION;SIMPLEREGION;COMPLEXREGION;ERROR.
{
assert(m_pData->hDC);
CRgn* pRgn = new CRgn;
pRgn->CreateEllipticRgn(left, top, right, bottom);
m_pData->m_vGDIObjects.push_back(pRgn);
return SelectClipRgn(pRgn);
}
inline int CDC::CreateEllipticRgnIndirect(const RECT& rc)
// Creates the ellyiptical region from the bounding rectangle co-ordinates
// and selects it into the device context.
// The return value specifies the region's complexity: NULLREGION;SIMPLEREGION;COMPLEXREGION;ERROR.
{
assert(m_pData->hDC);
CRgn* pRgn = new CRgn;
pRgn->CreateEllipticRgnIndirect(rc);
m_pData->m_vGDIObjects.push_back(pRgn);
return SelectClipRgn(pRgn);
}
inline int CDC::CreatePolygonRgn(LPPOINT ppt, int cPoints, int fnPolyFillMode)
// Creates the polygon region from the array of points and selects it into
// the device context. The polygon is presumed closed.
// The return value specifies the region's complexity: NULLREGION;SIMPLEREGION;COMPLEXREGION;ERROR.
{
assert(m_pData->hDC);
CRgn* pRgn = new CRgn;
pRgn->CreatePolygonRgn(ppt, cPoints, fnPolyFillMode);
m_pData->m_vGDIObjects.push_back(pRgn);
return SelectClipRgn(pRgn);
}
inline int CDC::CreatePolyPolygonRgn(LPPOINT ppt, LPINT pPolyCounts, int nCount, int fnPolyFillMode)
// Creates the polygon region from a series of polygons.The polygons can overlap.
// The return value specifies the region's complexity: NULLREGION;SIMPLEREGION;COMPLEXREGION;ERROR.
{
assert(m_pData->hDC);
CRgn* pRgn = new CRgn;
pRgn->CreatePolyPolygonRgn(ppt, pPolyCounts, nCount, fnPolyFillMode);
m_pData->m_vGDIObjects.push_back(pRgn);
return SelectClipRgn(pRgn);
}
#endif
// Wrappers for WinAPI functions
inline int CDC::GetDeviceCaps (int nIndex) const
// Retrieves device-specific information for the specified device.
{
assert(m_pData->hDC);
return ::GetDeviceCaps(m_pData->hDC, nIndex);
}
// Brush Functions
#ifdef GetDCBrushColor
inline COLORREF CDC::GetDCBrushColor() const
{
assert(m_pData->hDC);
return ::GetDCBrushColor(m_pData->hDC);
}
inline COLORREF CDC::SetDCBrushColor(COLORREF crColor) const
{
assert(m_pData->hDC);
return ::SetDCBrushColor(m_pData->hDC, crColor);
}
#endif
// Clipping functions
inline int CDC::ExcludeClipRect(int Left, int Top, int Right, int BottomRect)
// Creates a new clipping region that consists of the existing clipping region minus the specified rectangle.
{
assert(m_pData->hDC);
return ::ExcludeClipRect(m_pData->hDC, Left, Top, Right, BottomRect);
}
inline int CDC::ExcludeClipRect(const RECT& rc)
// Creates a new clipping region that consists of the existing clipping region minus the specified rectangle.
{
assert(m_pData->hDC);
return ::ExcludeClipRect(m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom);
}
inline int CDC::GetClipBox (RECT& rc)
// Retrieves the dimensions of the tightest bounding rectangle that can be drawn around the current visible area on the device.
{
assert(m_pData->hDC);
return ::GetClipBox(m_pData->hDC, &rc);
}
inline int CDC::GetClipRgn(HRGN hrgn)
// Retrieves a handle identifying the current application-defined clipping region for the specified device context.
// hrgn: A handle to an existing region before the function is called.
// After the function returns, this parameter is a handle to a copy of the current clipping region.
{
assert(m_pData->hDC);
return ::GetClipRgn(m_pData->hDC, hrgn);
}
inline int CDC::IntersectClipRect(int Left, int Top, int Right, int Bottom)
// Creates a new clipping region from the intersection of the current clipping region and the specified rectangle.
{
assert(m_pData->hDC);
return ::IntersectClipRect(m_pData->hDC, Left, Top, Right, Bottom);
}
inline int CDC::IntersectClipRect(const RECT& rc)
// Creates a new clipping region from the intersection of the current clipping region and the specified rectangle.
{
assert(m_pData->hDC);
return ::IntersectClipRect(m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom);
}
inline BOOL CDC::RectVisible(const RECT& rc)
// Determines whether any part of the specified rectangle lies within the clipping region of a device context.
{
assert(m_pData->hDC);
return ::RectVisible (m_pData->hDC, &rc);
}
inline int CDC::SelectClipRgn(CRgn* pRgn)
// Selects a region as the current clipping region for the specified device context.
// Note: Only a copy of the selected region is used.
// To remove a device-context's clipping region, specify a NULL region handle.
{
assert(m_pData->hDC);
return ::SelectClipRgn(m_pData->hDC, pRgn? (HRGN)pRgn->GetHandle() : 0);
}
#ifndef _WIN32_WCE
inline int CDC::ExtSelectClipRgn(CRgn* pRgn, int fnMode)
// Combines the specified region with the current clipping region using the specified mode.
{
assert(m_pData->hDC);
assert(pRgn);
return ::ExtSelectClipRgn(m_pData->hDC, *pRgn, fnMode);
}
#endif
inline CBitmap* CDC::SelectObject(const CBitmap* pBitmap)
// Use this to attach an existing bitmap.
{
assert(m_pData->hDC);
assert(pBitmap);
return FromHandle( (HBITMAP)::SelectObject(m_pData->hDC, *pBitmap) );
}
inline CBrush* CDC::SelectObject(const CBrush* pBrush)
// Use this to attach an existing brush.
{
assert(m_pData->hDC);
assert(pBrush);
return FromHandle( (HBRUSH)::SelectObject(m_pData->hDC, *pBrush) );
}
inline CFont* CDC::SelectObject(const CFont* pFont)
// Use this to attach an existing font.
{
assert(m_pData->hDC);
assert(pFont);
return FromHandle( (HFONT)::SelectObject(m_pData->hDC, *pFont) );
}
inline CPalette* CDC::SelectObject(const CPalette* pPalette)
// Use this to attach an existing Palette.
{
assert(m_pData->hDC);
assert(pPalette);
return FromHandle( (HPALETTE)::SelectObject(m_pData->hDC, *pPalette) );
}
inline CPen* CDC::SelectObject(const CPen* pPen)
// Use this to attach an existing pen.
{
assert(m_pData->hDC);
assert(pPen);
return FromHandle( (HPEN)::SelectObject(m_pData->hDC, *pPen) );
}
inline CPalette* CDC::SelectPalette(const CPalette* pPalette, BOOL bForceBkgnd)
// Use this to attach an existing palette.
{
assert(m_pData->hDC);
assert(pPalette);
return FromHandle( (HPALETTE)::SelectPalette(m_pData->hDC, *pPalette, bForceBkgnd) );
}
#ifndef _WIN32_WCE
inline BOOL CDC::PtVisible(int X, int Y)
// Determines whether the specified point is within the clipping region of a device context.
{
assert(m_pData->hDC);
return ::PtVisible (m_pData->hDC, X, Y);
}
inline int CDC::OffsetClipRgn(int nXOffset, int nYOffset)
// Moves the clipping region of a device context by the specified offsets.
{
assert(m_pData->hDC);
return ::OffsetClipRgn (m_pData->hDC, nXOffset, nYOffset);
}
#endif
// Point and Line Drawing Functions
inline CPoint CDC::GetCurrentPosition() const
// Returns the current "MoveToEx" position.
{
assert(m_pData->hDC);
CPoint pt;
::MoveToEx(m_pData->hDC, 0, 0, &pt);
::MoveToEx(m_pData->hDC, pt.x, pt.y, NULL);
return pt;
}
inline CPoint CDC::MoveTo(int x, int y) const
// Updates the current position to the specified point.
{
assert(m_pData->hDC);
return ::MoveToEx(m_pData->hDC, x, y, NULL);
}
inline CPoint CDC::MoveTo(POINT pt) const
// Updates the current position to the specified point
{
assert(m_pData->hDC);
return ::MoveToEx(m_pData->hDC, pt.x, pt.y, NULL);
}
inline BOOL CDC::LineTo(int x, int y) const
// Draws a line from the current position up to, but not including, the specified point.
{
assert(m_pData->hDC);
return ::LineTo(m_pData->hDC, x, y);
}
inline BOOL CDC::LineTo(POINT pt) const
// Draws a line from the current position up to, but not including, the specified point.
{
assert(m_pData->hDC);
return ::LineTo(m_pData->hDC, pt.x, pt.y);
}
#ifndef _WIN32_WCE
inline BOOL CDC::Arc(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) const
// Draws an elliptical arc.
{
assert(m_pData->hDC);
return ::Arc(m_pData->hDC, x1, y1, x2, y2, x3, y3, x4, y4);
}
inline BOOL CDC::Arc(RECT& rc, POINT ptStart, POINT ptEnd) const
// Draws an elliptical arc.
{
assert(m_pData->hDC);
return ::Arc(m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom,
ptStart.x, ptStart.y, ptEnd.x, ptEnd.y);
}
inline BOOL CDC::ArcTo(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) const
// Draws an elliptical arc.
{
assert(m_pData->hDC);
return ::ArcTo(m_pData->hDC, x1, y1, x2, y2, x3, y3, x4, y4);
}
inline BOOL CDC::ArcTo(RECT& rc, POINT ptStart, POINT ptEnd) const
// Draws an elliptical arc.
{
assert(m_pData->hDC);
return ::ArcTo (m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom,
ptStart.x, ptStart.y, ptEnd.x, ptEnd.y);
}
inline BOOL CDC::AngleArc(int x, int y, int nRadius, float fStartAngle, float fSweepAngle) const
// Draws a line segment and an arc.
{
assert(m_pData->hDC);
return ::AngleArc(m_pData->hDC, x, y, nRadius, fStartAngle, fSweepAngle);
}
inline int CDC::GetArcDirection() const
// Retrieves the current arc direction ( AD_COUNTERCLOCKWISE or AD_CLOCKWISE ).
{
assert(m_pData->hDC);
return ::GetArcDirection(m_pData->hDC);
}
inline int CDC::SetArcDirection(int nArcDirection) const
// Sets the current arc direction ( AD_COUNTERCLOCKWISE or AD_CLOCKWISE ).
{
assert(m_pData->hDC);
return ::SetArcDirection(m_pData->hDC, nArcDirection);
}
inline BOOL CDC::PolyDraw(const POINT* lpPoints, const BYTE* lpTypes, int nCount) const
// Draws a set of line segments and Bzier curves.
{
assert(m_pData->hDC);
return ::PolyDraw(m_pData->hDC, lpPoints, lpTypes, nCount);
}
inline BOOL CDC::Polyline(LPPOINT lpPoints, int nCount) const
// Draws a series of line segments by connecting the points in the specified array.
{
assert(m_pData->hDC);
return ::Polyline(m_pData->hDC, lpPoints, nCount);
}
inline BOOL CDC::PolyPolyline(const POINT* lpPoints, const DWORD* lpPolyPoints, int nCount) const
// Draws multiple series of connected line segments.
{
assert(m_pData->hDC);
return ::PolyPolyline(m_pData->hDC, lpPoints, lpPolyPoints, nCount);
}
inline BOOL CDC::PolylineTo(const POINT* lpPoints, int nCount) const
// Draws one or more straight lines.
{
assert(m_pData->hDC);
return ::PolylineTo(m_pData->hDC, lpPoints, nCount);
}
inline BOOL CDC::PolyBezier(const POINT* lpPoints, int nCount) const
// Draws one or more Bzier curves.
{
assert(m_pData->hDC);
return ::PolyBezier(m_pData->hDC, lpPoints, nCount);
}
inline BOOL CDC::PolyBezierTo(const POINT* lpPoints, int nCount) const
// Draws one or more Bzier curves.
{
assert(m_pData->hDC);
return ::PolyBezierTo(m_pData->hDC, lpPoints, nCount );
}
inline COLORREF CDC::GetPixel(int x, int y) const
// Retrieves the red, green, blue (RGB) color value of the pixel at the specified coordinates.
{
assert(m_pData->hDC);
return ::GetPixel(m_pData->hDC, x, y);
}
inline COLORREF CDC::GetPixel(POINT pt) const
// Retrieves the red, green, blue (RGB) color value of the pixel at the specified coordinates.
{
assert(m_pData->hDC);
return ::GetPixel(m_pData->hDC, pt.x, pt.y);
}
inline COLORREF CDC::SetPixel (int x, int y, COLORREF crColor) const
// Sets the pixel at the specified coordinates to the specified color.
{
assert(m_pData->hDC);
return ::SetPixel(m_pData->hDC, x, y, crColor);
}
inline COLORREF CDC::SetPixel(POINT pt, COLORREF crColor) const
// Sets the pixel at the specified coordinates to the specified color.
{
assert(m_pData->hDC);
return ::SetPixel(m_pData->hDC, pt.x, pt.y, crColor);
}
inline BOOL CDC::SetPixelV(int x, int y, COLORREF crColor) const
// Sets the pixel at the specified coordinates to the closest approximation of the specified color.
{
assert(m_pData->hDC);
return ::SetPixelV(m_pData->hDC, x, y, crColor);
}
inline BOOL CDC::SetPixelV(POINT pt, COLORREF crColor) const
// Sets the pixel at the specified coordinates to the closest approximation of the specified color.
{
assert(m_pData->hDC);
return ::SetPixelV(m_pData->hDC, pt.x, pt.y, crColor);
}
#endif
// Shape Drawing Functions
inline void CDC::DrawFocusRect(const RECT& rc) const
// Draws a rectangle in the style used to indicate that the rectangle has the focus.
{
assert(m_pData->hDC);
::DrawFocusRect(m_pData->hDC, &rc);
}
inline BOOL CDC::Ellipse(int x1, int y1, int x2, int y2) const
// Draws an ellipse. The center of the ellipse is the center of the specified bounding rectangle.
{
assert(m_pData->hDC);
return ::Ellipse(m_pData->hDC, x1, y1, x2, y2);
}
inline BOOL CDC::Ellipse(const RECT& rc) const
// Draws an ellipse. The center of the ellipse is the center of the specified bounding rectangle.
{
assert(m_pData->hDC);
return ::Ellipse(m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom);
}
inline BOOL CDC::Polygon(LPPOINT lpPoints, int nCount) const
// Draws a polygon consisting of two or more vertices connected by straight lines.
{
assert(m_pData->hDC);
return ::Polygon(m_pData->hDC, lpPoints, nCount);
}
inline BOOL CDC::Rectangle(int x1, int y1, int x2, int y2) const
// Draws a rectangle. The rectangle is outlined by using the current pen and filled by using the current brush.
{
assert(m_pData->hDC);
return ::Rectangle(m_pData->hDC, x1, y1, x2, y2);
}
inline BOOL CDC::Rectangle(const RECT& rc) const
// Draws a rectangle. The rectangle is outlined by using the current pen and filled by using the current brush.
{
assert(m_pData->hDC);
return ::Rectangle(m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom);
}
inline BOOL CDC::RoundRect(int x1, int y1, int x2, int y2, int nWidth, int nHeight) const
// Draws a rectangle with rounded corners.
{
assert(m_pData->hDC);
return ::RoundRect(m_pData->hDC, x1, y1, x2, y2, nWidth, nHeight);
}
inline BOOL CDC::RoundRect(const RECT& rc, int nWidth, int nHeight) const
// Draws a rectangle with rounded corners.
{
assert(m_pData->hDC);
return ::RoundRect(m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom, nWidth, nHeight );
}
#ifndef _WIN32_WCE
inline BOOL CDC::Chord(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) const
// Draws a chord (a region bounded by the intersection of an ellipse and a line segment, called a secant).
{
assert(m_pData->hDC);
return ::Chord(m_pData->hDC, x1, y1, x2, y2, x3, y3, x4, y4);
}
inline BOOL CDC::Chord(const RECT& rc, POINT ptStart, POINT ptEnd) const
// Draws a chord (a region bounded by the intersection of an ellipse and a line segment, called a secant).
{
assert(m_pData->hDC);
return ::Chord(m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom,
ptStart.x, ptStart.y, ptEnd.x, ptEnd.y);
}
inline BOOL CDC::Pie(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) const
// Draws a pie-shaped wedge bounded by the intersection of an ellipse and two radials.
{
assert(m_pData->hDC);
return ::Pie(m_pData->hDC, x1, y1, x2, y2, x3, y3, x4, y4);
}
inline BOOL CDC::Pie(const RECT& rc, POINT ptStart, POINT ptEnd) const
// Draws a pie-shaped wedge bounded by the intersection of an ellipse and two radials.
{
assert(m_pData->hDC);
return ::Pie(m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom,
ptStart.x, ptStart.y, ptEnd.x, ptEnd.y);
}
inline BOOL CDC::PolyPolygon(LPPOINT lpPoints, LPINT lpPolyCounts, int nCount) const
// Draws a series of closed polygons.
{
assert(m_pData->hDC);
return ::PolyPolygon(m_pData->hDC, lpPoints, lpPolyCounts, nCount);
}
#endif
// Fill and 3D Drawing functions
inline BOOL CDC::FillRect(const RECT& rc, CBrush* pBrush) const
// Fills a rectangle by using the specified brush.
{
assert(m_pData->hDC);
assert(pBrush);
return (BOOL)::FillRect(m_pData->hDC, &rc, *pBrush);
}
inline BOOL CDC::InvertRect(const RECT& rc) const
// Inverts a rectangle in a window by performing a logical NOT operation on the color values for each pixel in the rectangle's interior.
{
assert(m_pData->hDC);
return ::InvertRect( m_pData->hDC, &rc);
}
inline BOOL CDC::DrawIconEx(int xLeft, int yTop, HICON hIcon, int cxWidth, int cyWidth, UINT istepIfAniCur, CBrush* pFlickerFreeDraw, UINT diFlags) const
// draws an icon or cursor, performing the specified raster operations, and stretching or compressing the icon or cursor as specified.
{
assert(m_pData->hDC);
HBRUSH hFlickerFreeDraw = pFlickerFreeDraw? (HBRUSH)pFlickerFreeDraw->GetHandle() : NULL;
return ::DrawIconEx(m_pData->hDC, xLeft, yTop, hIcon, cxWidth, cyWidth, istepIfAniCur, hFlickerFreeDraw, diFlags);
}
inline BOOL CDC::DrawEdge(const RECT& rc, UINT nEdge, UINT nFlags) const
// Draws one or more edges of rectangle.
{
assert(m_pData->hDC);
return ::DrawEdge(m_pData->hDC, (LPRECT)&rc, nEdge, nFlags);
}
inline BOOL CDC::DrawFrameControl(const RECT& rc, UINT nType, UINT nState) const
// Draws a frame control of the specified type and style.
{
assert(m_pData->hDC);
return ::DrawFrameControl(m_pData->hDC, (LPRECT)&rc, nType, nState);
}
inline BOOL CDC::FillRgn(CRgn* pRgn, CBrush* pBrush) const
// Fills a region by using the specified brush.
{
assert(m_pData->hDC);
assert(pRgn);
assert(pBrush);
return ::FillRgn(m_pData->hDC, *pRgn, *pBrush);
}
#ifndef _WIN32_WCE
inline BOOL CDC::DrawIcon(int x, int y, HICON hIcon) const
// Draws an icon or cursor.
{
assert(m_pData->hDC);
return ::DrawIcon(m_pData->hDC, x, y, hIcon);
}
inline BOOL CDC::DrawIcon(POINT pt, HICON hIcon) const
// Draws an icon or cursor.
{
assert(m_pData->hDC);
return ::DrawIcon(m_pData->hDC, pt.x, pt.y, hIcon);
}
inline BOOL CDC::FrameRect(const RECT& rc, CBrush* pBrush) const
// Draws a border around the specified rectangle by using the specified brush.
{
assert(m_pData->hDC);
assert(pBrush);
return (BOOL)::FrameRect(m_pData->hDC, &rc, *pBrush);
}
inline BOOL CDC::PaintRgn(CRgn* pRgn) const
// Paints the specified region by using the brush currently selected into the device context.
{
assert(m_pData->hDC);
assert(pRgn);
return ::PaintRgn(m_pData->hDC, *pRgn);
}
#endif
// Bitmap Functions
inline int CDC::StretchDIBits(int XDest, int YDest, int nDestWidth, int nDestHeight, int XSrc, int YSrc, int nSrcWidth,
int nSrcHeight, CONST VOID *lpBits, BITMAPINFO& bi, UINT iUsage, DWORD dwRop) const
// Copies the color data for a rectangle of pixels in a DIB to the specified destination rectangle.
{
assert(m_pData->hDC);
return ::StretchDIBits(m_pData->hDC, XDest, YDest, nDestWidth, nDestHeight, XSrc, YSrc, nSrcWidth, nSrcHeight, lpBits, &bi, iUsage, dwRop);
}
inline BOOL CDC::PatBlt(int x, int y, int nWidth, int nHeight, DWORD dwRop) const
// Paints the specified rectangle using the brush that is currently selected into the device context.
{
assert(m_pData->hDC);
return ::PatBlt(m_pData->hDC, x, y, nWidth, nHeight, dwRop);
}
inline BOOL CDC::BitBlt(int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, DWORD dwRop) const
// Performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context.
{
assert(m_pData->hDC);
assert(pSrcDC);
return ::BitBlt(m_pData->hDC, x, y, nWidth, nHeight, pSrcDC->GetHDC(), xSrc, ySrc, dwRop);
}
inline BOOL CDC::StretchBlt(int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, int nSrcWidth, int nSrcHeight, DWORD dwRop) const
// Copies a bitmap from a source rectangle into a destination rectangle, stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary.
{
assert(m_pData->hDC);
assert(pSrcDC);
return ::StretchBlt(m_pData->hDC, x, y, nWidth, nHeight, pSrcDC->GetHDC(), xSrc, ySrc, nSrcWidth, nSrcHeight, dwRop);
}
#ifndef _WIN32_WCE
inline int CDC::GetDIBits(CBitmap* pBitmap, UINT uStartScan, UINT cScanLines, LPVOID lpvBits, LPBITMAPINFO lpbi, UINT uUsage) const
// Retrieves the bits of the specified compatible bitmap and copies them into a buffer as a DIB using the specified format.
{
assert(m_pData->hDC);
assert(pBitmap);
return ::GetDIBits(m_pData->hDC, *pBitmap, uStartScan, cScanLines, lpvBits, lpbi, uUsage);
}
inline int CDC::SetDIBits(CBitmap* pBitmap, UINT uStartScan, UINT cScanLines, CONST VOID *lpvBits, LPBITMAPINFO lpbi, UINT fuColorUse) const
// Sets the pixels in a compatible bitmap (DDB) using the color data found in the specified DIB.
{
assert(m_pData->hDC);
return ::SetDIBits(m_pData->hDC, *pBitmap, uStartScan, cScanLines, lpvBits, lpbi, fuColorUse);
}
inline int CDC::GetStretchBltMode() const
// Retrieves the current stretching mode.
// Possible modes: BLACKONWHITE, COLORONCOLOR, HALFTONE, STRETCH_ANDSCANS, STRETCH_DELETESCANS, STRETCH_HALFTONE, STRETCH_ORSCANS, WHITEONBLACK
{
assert(m_pData->hDC);
return ::GetStretchBltMode(m_pData->hDC);
}
inline int CDC::SetStretchBltMode(int iStretchMode) const
// Sets the stretching mode.
// Possible modes: BLACKONWHITE, COLORONCOLOR, HALFTONE, STRETCH_ANDSCANS, STRETCH_DELETESCANS, STRETCH_HALFTONE, STRETCH_ORSCANS, WHITEONBLACK
{
assert(m_pData->hDC);
return ::SetStretchBltMode(m_pData->hDC, iStretchMode);
}
inline BOOL CDC::FloodFill(int x, int y, COLORREF crColor) const
// Fills an area of the display surface with the current brush.
{
assert(m_pData->hDC);
return ::FloodFill(m_pData->hDC, x, y, crColor);
}
inline BOOL CDC::ExtFloodFill(int x, int y, COLORREF crColor, UINT nFillType) const
// Fills an area of the display surface with the current brush.
// Fill type: FLOODFILLBORDER or FLOODFILLSURFACE
{
assert(m_pData->hDC);
return ::ExtFloodFill(m_pData->hDC, x, y, crColor, nFillType );
}
// co-ordinate functions
inline BOOL CDC::DPtoLP(LPPOINT lpPoints, int nCount) const
// Converts device coordinates into logical coordinates.
{
assert(m_pData->hDC);
return ::DPtoLP(m_pData->hDC, lpPoints, nCount);
}
inline BOOL CDC::DPtoLP(RECT& rc) const
// Converts device coordinates into logical coordinates.
{
assert(m_pData->hDC);
return ::DPtoLP(m_pData->hDC, (LPPOINT)&rc, 2);
}
inline BOOL CDC::LPtoDP(LPPOINT lpPoints, int nCount) const
// Converts logical coordinates into device coordinates.
{
assert(m_pData->hDC);
return ::LPtoDP(m_pData->hDC, lpPoints, nCount);
}
inline BOOL CDC::LPtoDP(RECT& rc) const
// Converts logical coordinates into device coordinates.
{
assert(m_pData->hDC);
return ::LPtoDP(m_pData->hDC, (LPPOINT)&rc, 2);
}
#endif
// Layout Functions
inline DWORD CDC::GetLayout() const
// Returns the layout of a device context (LAYOUT_RTL and LAYOUT_BITMAPORIENTATIONPRESERVED).
{
#if defined(WINVER) && defined(GetLayout) && (WINVER >= 0x0500)
return ::GetLayout(m_pData->hDC);
#else
return 0;
#endif
}
inline DWORD CDC::SetLayout(DWORD dwLayout) const
// changes the layout of a device context (DC).
// dwLayout values: LAYOUT_RTL or LAYOUT_BITMAPORIENTATIONPRESERVED
{
#if defined(WINVER) && defined (SetLayout) && (WINVER >= 0x0500)
// Sets the layout of a device context
return ::SetLayout(m_pData->hDC, dwLayout);
#else
UNREFERENCED_PARAMETER(dwLayout); // no-op
return 0;
#endif
}
// Mapping Functions
#ifndef _WIN32_WCE
inline int CDC::GetMapMode() const
// Rretrieves the current mapping mode.
// Possible modes: MM_ANISOTROPIC, MM_HIENGLISH, MM_HIMETRIC, MM_ISOTROPIC, MM_LOENGLISH, MM_LOMETRIC, MM_TEXT, and MM_TWIPS.
{
assert(m_pData->hDC);
return ::GetMapMode(m_pData->hDC);
}
inline BOOL CDC::GetViewportOrgEx(LPPOINT lpPoint) const
// Retrieves the x-coordinates and y-coordinates of the viewport origin for the device context.
{
assert(m_pData->hDC);
return ::GetViewportOrgEx(m_pData->hDC, lpPoint);
}
inline int CDC::SetMapMode(int nMapMode) const
// Sets the mapping mode of the specified device context.
{
assert(m_pData->hDC);
return ::SetMapMode(m_pData->hDC, nMapMode);
}
inline BOOL CDC::SetViewportOrgEx(int x, int y, LPPOINT lpPoint /* = NULL */) const
// Specifies which device point maps to the window origin (0,0).
{
assert(m_pData->hDC);
return ::SetViewportOrgEx(m_pData->hDC, x, y, lpPoint);
}
inline BOOL CDC::SetViewportOrgEx(POINT point, LPPOINT lpPointRet /* = NULL */) const
// Specifies which device point maps to the window origin (0,0).
{
assert(m_pData->hDC);
return SetViewportOrgEx(point.x, point.y, lpPointRet);
}
inline BOOL CDC::OffsetViewportOrgEx(int nWidth, int nHeight, LPPOINT lpPoint /* = NULL */) const
// Modifies the viewport origin for the device context using the specified horizontal and vertical offsets.
{
assert(m_pData->hDC);
return ::OffsetViewportOrgEx(m_pData->hDC, nWidth, nHeight, lpPoint);
}
inline BOOL CDC::GetViewportExtEx(LPSIZE lpSize) const
// Retrieves the x-extent and y-extent of the current viewport for the device context.
{
assert(m_pData->hDC);
return ::GetViewportExtEx(m_pData->hDC, lpSize);
}
inline BOOL CDC::SetViewportExtEx(int x, int y, LPSIZE lpSize ) const
// Sets the horizontal and vertical extents of the viewport for the device context by using the specified values.
{
assert(m_pData->hDC);
return ::SetViewportExtEx(m_pData->hDC, x, y, lpSize);
}
inline BOOL CDC::SetViewportExtEx(SIZE size, LPSIZE lpSizeRet ) const
// Sets the horizontal and vertical extents of the viewport for the device context by using the specified values.
{
assert(m_pData->hDC);
return SetViewportExtEx(size.cx, size.cy, lpSizeRet);
}
inline BOOL CDC::ScaleViewportExtEx(int xNum, int xDenom, int yNum, int yDenom, LPSIZE lpSize ) const
// Modifies the viewport for the device context using the ratios formed by the specified multiplicands and divisors.
{
assert(m_pData->hDC);
return ::ScaleViewportExtEx(m_pData->hDC, xNum, xDenom, yNum, yDenom, lpSize);
}
inline BOOL CDC::GetWindowOrgEx(LPPOINT lpPoint) const
// Retrieves the x-coordinates and y-coordinates of the window origin for the device context.
{
assert(m_pData->hDC);
return ::GetWindowOrgEx(m_pData->hDC, lpPoint);
}
inline BOOL CDC::SetWindowOrgEx(int x, int y, LPPOINT lpPoint ) const
// Specifies which window point maps to the viewport origin (0,0).
{
assert(m_pData->hDC);
return ::SetWindowOrgEx(m_pData->hDC, x, y, lpPoint);
}
inline BOOL CDC::SetWindowOrgEx(POINT point, LPPOINT lpPointRet ) const
// Specifies which window point maps to the viewport origin (0,0).
{
assert(m_pData->hDC);
return SetWindowOrgEx(point.x, point.y, lpPointRet);
}
inline BOOL CDC::OffsetWindowOrgEx(int nWidth, int nHeight, LPPOINT lpPoint ) const
// Modifies the window origin for the device context using the specified horizontal and vertical offsets.
{
assert(m_pData->hDC);
return ::OffsetWindowOrgEx(m_pData->hDC, nWidth, nHeight, lpPoint);
}
inline BOOL CDC::GetWindowExtEx(LPSIZE lpSize) const
// Retrieves the x-extent and y-extent of the window for the device context.
{
assert(m_pData->hDC);
return ::GetWindowExtEx(m_pData->hDC, lpSize);
}
inline BOOL CDC::SetWindowExtEx(int x, int y, LPSIZE lpSize ) const
// Sets the horizontal and vertical extents of the window for the device context by using the specified values.
{
assert(m_pData->hDC);
return ::SetWindowExtEx(m_pData->hDC, x, y, lpSize);
}
inline BOOL CDC::SetWindowExtEx(SIZE size, LPSIZE lpSizeRet) const
// Sets the horizontal and vertical extents of the window for the device context by using the specified values.
{
assert(m_pData->hDC);
return SetWindowExtEx(size.cx, size.cy, lpSizeRet);
}
inline BOOL CDC::ScaleWindowExtEx(int xNum, int xDenom, int yNum, int yDenom, LPSIZE lpSize) const
// Modifies the window for the device context using the ratios formed by the specified multiplicands and divisors.
{
assert(m_pData->hDC);
return ::ScaleWindowExtEx(m_pData->hDC, xNum, xDenom, yNum, yDenom, lpSize);
}
#endif
// Printer Functions
inline int CDC::StartDoc(LPDOCINFO lpDocInfo) const
// Starts a print job.
{
assert(m_pData->hDC);
return ::StartDoc(m_pData->hDC, lpDocInfo);
}
inline int CDC::EndDoc() const
// Ends a print job.
{
assert(m_pData->hDC);
return ::EndDoc(m_pData->hDC);
}
inline int CDC::StartPage() const
// Prepares the printer driver to accept data.
{
assert(m_pData->hDC);
return ::StartPage(m_pData->hDC);
}
inline int CDC::EndPage() const
// Notifies the device that the application has finished writing to a page.
{
assert(m_pData->hDC);
return ::EndPage(m_pData->hDC);
}
inline int CDC::AbortDoc() const
// Stops the current print job and erases everything drawn since the last call to the StartDoc function.
{
assert(m_pData->hDC);
return ::AbortDoc(m_pData->hDC);
}
inline int CDC::SetAbortProc(BOOL (CALLBACK* lpfn)(HDC, int)) const
// Sets the application-defined abort function that allows a print job to be canceled during spooling.
{
assert(m_pData->hDC);
return ::SetAbortProc(m_pData->hDC, lpfn);
}
// Text Functions
inline BOOL CDC::ExtTextOut(int x, int y, UINT nOptions, LPCRECT lprc, LPCTSTR lpszString, int nCount /*= -1*/, LPINT lpDxWidths /*=NULL*/) const
// Draws text using the currently selected font, background color, and text color
{
assert(m_pData->hDC);
if (nCount == -1)
nCount = lstrlen (lpszString);
return ::ExtTextOut(m_pData->hDC, x, y, nOptions, lprc, lpszString, nCount, lpDxWidths );
}
inline int CDC::DrawText(LPCTSTR lpszString, int nCount, LPRECT lprc, UINT nFormat) const
// Draws formatted text in the specified rectangle
{
assert(m_pData->hDC);
return ::DrawText(m_pData->hDC, lpszString, nCount, lprc, nFormat );
}
inline UINT CDC::GetTextAlign() const
// Retrieves the text-alignment setting
// Values: TA_BASELINE, TA_BOTTOM, TA_TOP, TA_CENTER, TA_LEFT, TA_RIGHT, TA_RTLREADING, TA_NOUPDATECP, TA_UPDATECP
{
assert(m_pData->hDC);
return ::GetTextAlign(m_pData->hDC);
}
inline UINT CDC::SetTextAlign(UINT nFlags) const
// Sets the text-alignment setting
// Values: TA_BASELINE, TA_BOTTOM, TA_TOP, TA_CENTER, TA_LEFT, TA_RIGHT, TA_RTLREADING, TA_NOUPDATECP, TA_UPDATECP
{
assert(m_pData->hDC);
return ::SetTextAlign(m_pData->hDC, nFlags);
}
inline int CDC::GetTextFace(int nCount, LPTSTR lpszFacename) const
// Retrieves the typeface name of the font that is selected into the device context
{
assert(m_pData->hDC);
return ::GetTextFace(m_pData->hDC, nCount, lpszFacename);
}
inline BOOL CDC::GetTextMetrics(TEXTMETRIC& Metrics) const
// Fills the specified buffer with the metrics for the currently selected font
{
assert(m_pData->hDC);
return ::GetTextMetrics(m_pData->hDC, &Metrics);
}
inline COLORREF CDC::GetBkColor() const
// Returns the current background color
{
assert(m_pData->hDC);
return ::GetBkColor(m_pData->hDC);
}
inline COLORREF CDC::SetBkColor(COLORREF crColor) const
// Sets the current background color to the specified color value
{
assert(m_pData->hDC);
return ::SetBkColor(m_pData->hDC, crColor);
}
inline COLORREF CDC::GetTextColor() const
// Retrieves the current text color
{
assert(m_pData->hDC);
return ::GetTextColor(m_pData->hDC);
}
inline COLORREF CDC::SetTextColor(COLORREF crColor) const
// Sets the current text color
{
assert(m_pData->hDC);
return ::SetTextColor(m_pData->hDC, crColor);
}
inline int CDC::GetBkMode() const
// returns the current background mix mode (OPAQUE or TRANSPARENT)
{
assert(m_pData->hDC);
return ::GetBkMode(m_pData->hDC);
}
inline int CDC::SetBkMode(int iBkMode) const
// Sets the current background mix mode (OPAQUE or TRANSPARENT)
{
assert(m_pData->hDC);
return ::SetBkMode(m_pData->hDC, iBkMode);
}
#ifndef _WIN32_WCE
inline int CDC::DrawTextEx(LPTSTR lpszString, int nCount, LPRECT lprc, UINT nFormat, LPDRAWTEXTPARAMS lpDTParams) const
// Draws formatted text in the specified rectangle with more formatting options
{
assert(m_pData->hDC);
return ::DrawTextEx(m_pData->hDC, lpszString, nCount, lprc, nFormat, lpDTParams);
}
inline CSize CDC::GetTextExtentPoint32(LPCTSTR lpszString, int nCount) const
// Computes the width and height of the specified string of text
{
assert(m_pData->hDC);
CSize sz;
::GetTextExtentPoint32(m_pData->hDC, lpszString, nCount, &sz);
return sz;
}
inline CSize CDC::GetTabbedTextExtent(LPCTSTR lpszString, int nCount, int nTabPositions, LPINT lpnTabStopPositions) const
// Computes the width and height of a character string
{
assert(m_pData->hDC);
DWORD dwSize = ::GetTabbedTextExtent(m_pData->hDC, lpszString, nCount, nTabPositions, lpnTabStopPositions );
CSize sz(dwSize);
return sz;
}
inline BOOL CDC::GrayString(CBrush* pBrush, GRAYSTRINGPROC lpOutputFunc, LPARAM lpData, int nCount, int x, int y, int nWidth, int nHeight) const
// Draws gray text at the specified location
{
assert(m_pData->hDC);
assert(pBrush);
return ::GrayString(m_pData->hDC, *pBrush, lpOutputFunc, lpData, nCount, x, y, nWidth, nHeight);
}
inline int CDC::SetTextJustification(int nBreakExtra, int nBreakCount) const
// Specifies the amount of space the system should add to the break characters in a string of text
{
assert(m_pData->hDC);
return ::SetTextJustification(m_pData->hDC, nBreakExtra, nBreakCount);
}
inline int CDC::GetTextCharacterExtra() const
// Retrieves the current intercharacter spacing for the device context
{
assert(m_pData->hDC);
return ::GetTextCharacterExtra(m_pData->hDC);
}
inline int CDC::SetTextCharacterExtra(int nCharExtra) const
// Sets the intercharacter spacing
{
assert(m_pData->hDC);
return ::SetTextCharacterExtra(m_pData->hDC, nCharExtra);
}
inline CSize CDC::TabbedTextOut(int x, int y, LPCTSTR lpszString, int nCount, int nTabPositions, LPINT lpnTabStopPositions, int nTabOrigin) const
// Writes a character string at a specified location, expanding tabs to the values specified in an array of tab-stop positions
{
assert(m_pData->hDC);
DWORD dwSize = ::TabbedTextOut(m_pData->hDC, x, y, lpszString, nCount, nTabPositions, lpnTabStopPositions, nTabOrigin );
CSize sz(dwSize);
return sz;
}
inline BOOL CDC::TextOut(int x, int y, LPCTSTR lpszString, int nCount/* = -1*/) const
// Writes a character string at the specified location
{
assert(m_pData->hDC);
if (nCount == -1)
nCount = lstrlen (lpszString);
return ::TextOut(m_pData->hDC, x, y, lpszString, nCount);
}
#endif
/////////////////////////////////////////////////////////////////
// Definitions for some global functions in the Win32xx namespace
//
#ifndef _WIN32_WCE
inline void TintBitmap (CBitmap* pbmSource, int cRed, int cGreen, int cBlue)
// Modifies the colour of the supplied Device Dependant Bitmap, by the colour
// correction values specified. The correction values can range from -255 to +255.
// This function gains its speed by accessing the bitmap colour information
// directly, rather than using GetPixel/SetPixel.
{
// Create our LPBITMAPINFO object
CBitmapInfoPtr pbmi(pbmSource);
pbmi->bmiHeader.biBitCount = 24;
// Create the reference DC for GetDIBits to use
CMemDC MemDC(NULL);
// Use GetDIBits to create a DIB from our DDB, and extract the colour data
MemDC.GetDIBits(pbmSource, 0, pbmi->bmiHeader.biHeight, NULL, pbmi, DIB_RGB_COLORS);
std::vector<byte> vBits(pbmi->bmiHeader.biSizeImage, 0);
byte* pByteArray = &vBits[0];
MemDC.GetDIBits(pbmSource, 0, pbmi->bmiHeader.biHeight, pByteArray, pbmi, DIB_RGB_COLORS);
UINT nWidthBytes = pbmi->bmiHeader.biSizeImage/pbmi->bmiHeader.biHeight;
// Ensure sane colour correction values
cBlue = MIN(cBlue, 255);
cBlue = MAX(cBlue, -255);
cRed = MIN(cRed, 255);
cRed = MAX(cRed, -255);
cGreen = MIN(cGreen, 255);
cGreen = MAX(cGreen, -255);
// Pre-calculate the RGB modification values
int b1 = 256 - cBlue;
int g1 = 256 - cGreen;
int r1 = 256 - cRed;
int b2 = 256 + cBlue;
int g2 = 256 + cGreen;
int r2 = 256 + cRed;
// Modify the colour
int yOffset = 0;
int xOffset;
int Index;
for (int Row=0; Row < pbmi->bmiHeader.biHeight; Row++)
{
xOffset = 0;
for (int Column=0; Column < pbmi->bmiHeader.biWidth; Column++)
{
// Calculate Index
Index = yOffset + xOffset;
// Adjust the colour values
if (cBlue > 0)
pByteArray[Index] = (BYTE)(cBlue + (((pByteArray[Index] *b1)) >>8));
else if (cBlue < 0)
pByteArray[Index] = (BYTE)((pByteArray[Index] *b2) >>8);
if (cGreen > 0)
pByteArray[Index+1] = (BYTE)(cGreen + (((pByteArray[Index+1] *g1)) >>8));
else if (cGreen < 0)
pByteArray[Index+1] = (BYTE)((pByteArray[Index+1] *g2) >>8);
if (cRed > 0)
pByteArray[Index+2] = (BYTE)(cRed + (((pByteArray[Index+2] *r1)) >>8));
else if (cRed < 0)
pByteArray[Index+2] = (BYTE)((pByteArray[Index+2] *r2) >>8);
// Increment the horizontal offset
xOffset += pbmi->bmiHeader.biBitCount >> 3;
}
// Increment vertical offset
yOffset += nWidthBytes;
}
// Save the modified colour back into our source DDB
MemDC.SetDIBits(pbmSource, 0, pbmi->bmiHeader.biHeight, pByteArray, pbmi, DIB_RGB_COLORS);
}
inline void GrayScaleBitmap(CBitmap* pbmSource)
{
// Create our LPBITMAPINFO object
CBitmapInfoPtr pbmi(pbmSource);
// Create the reference DC for GetDIBits to use
CMemDC MemDC(NULL);
// Use GetDIBits to create a DIB from our DDB, and extract the colour data
MemDC.GetDIBits(pbmSource, 0, pbmi->bmiHeader.biHeight, NULL, pbmi, DIB_RGB_COLORS);
std::vector<byte> vBits(pbmi->bmiHeader.biSizeImage, 0);
byte* pByteArray = &vBits[0];
MemDC.GetDIBits(pbmSource, 0, pbmi->bmiHeader.biHeight, pByteArray, pbmi, DIB_RGB_COLORS);
UINT nWidthBytes = pbmi->bmiHeader.biSizeImage/pbmi->bmiHeader.biHeight;
int yOffset = 0;
int xOffset;
int Index;
for (int Row=0; Row < pbmi->bmiHeader.biHeight; Row++)
{
xOffset = 0;
for (int Column=0; Column < pbmi->bmiHeader.biWidth; Column++)
{
// Calculate Index
Index = yOffset + xOffset;
BYTE byGray = (BYTE) ((pByteArray[Index] + pByteArray[Index+1]*6 + pByteArray[Index+2] *3)/10);
pByteArray[Index] = byGray;
pByteArray[Index+1] = byGray;
pByteArray[Index+2] = byGray;
// Increment the horizontal offset
xOffset += pbmi->bmiHeader.biBitCount >> 3;
}
// Increment vertical offset
yOffset += nWidthBytes;
}
// Save the modified colour back into our source DDB
MemDC.SetDIBits(pbmSource, 0, pbmi->bmiHeader.biHeight, pByteArray, pbmi, DIB_RGB_COLORS);
}
inline HIMAGELIST CreateDisabledImageList(HIMAGELIST himlNormal)
// Returns a greyed image list, created from hImageList
{
int cx, cy;
int nCount = ImageList_GetImageCount(himlNormal);
if (0 == nCount)
return NULL;
ImageList_GetIconSize(himlNormal, &cx, &cy);
// Create the disabled ImageList
HIMAGELIST himlDisabled = ImageList_Create(cx, cy, ILC_COLOR24 | ILC_MASK, nCount, 0);
// Process each image in the ImageList
for (int i = 0 ; i < nCount; ++i)
{
CClientDC DesktopDC(NULL);
CMemDC MemDC(NULL);
CBitmap* pOldBitmap = MemDC.CreateCompatibleBitmap(&DesktopDC, cx, cx);
CRect rc;
rc.SetRect(0, 0, cx, cx);
// Set the mask color to grey for the new ImageList
COLORREF crMask = RGB(200, 199, 200);
if ( GetDeviceCaps(DesktopDC, BITSPIXEL) < 24)
{
HPALETTE hPal = (HPALETTE)GetCurrentObject(DesktopDC, OBJ_PAL);
UINT Index = GetNearestPaletteIndex(hPal, crMask);
if (Index != CLR_INVALID) crMask = PALETTEINDEX(Index);
}
MemDC.SolidFill(crMask, rc);
// Draw the image on the memory DC
ImageList_SetBkColor(himlNormal, crMask);
ImageList_Draw(himlNormal, i, MemDC, 0, 0, ILD_NORMAL);
// Convert colored pixels to gray
for (int x = 0 ; x < cx; ++x)
{
for (int y = 0; y < cy; ++y)
{
COLORREF clr = ::GetPixel(MemDC, x, y);
if (clr != crMask)
{
BYTE byGray = (BYTE) (95 + (GetRValue(clr) *3 + GetGValue(clr)*6 + GetBValue(clr))/20);
MemDC.SetPixel(x, y, RGB(byGray, byGray, byGray));
}
}
}
// Detach the bitmap so we can use it.
CBitmap* pBitmap = MemDC.SelectObject(pOldBitmap);
ImageList_AddMasked(himlDisabled, *pBitmap, crMask);
}
return himlDisabled;
}
#endif
////////////////////////////////////////////
// Global Function Definitions
//
inline CDC* FromHandle(HDC hDC)
// Returns the CDC object associated with the device context handle
// If a CDC object doesn't already exist, a temporary CDC object is created.
// The HDC belonging to a temporary CDC is not released or destroyed when the
// temporary CDC is deconstructed.
{
assert( GetApp() );
CDC* pDC = GetApp()->GetCDCFromMap(hDC);
if (hDC != 0 && pDC == 0)
{
pDC = new CDC;
GetApp()->AddTmpDC(pDC);
pDC->m_pData->hDC = hDC;
pDC->m_pData->bRemoveHDC = FALSE;
}
return pDC;
}
inline CBitmap* FromHandle(HBITMAP hBitmap)
// Returns the CBitmap associated with the Bitmap handle
// If a CBitmap object doesn't already exist, a temporary CBitmap object is created.
// The HBITMAP belonging to a temporary CBitmap is not released or destroyed
// when the temporary CBitmap is deconstructed.
{
assert( GetApp() );
CBitmap* pBitmap = (CBitmap*)GetApp()->GetCGDIObjectFromMap(hBitmap);
if (hBitmap != 0 && pBitmap == 0)
{
pBitmap = new CBitmap;
GetApp()->AddTmpGDI(pBitmap);
pBitmap->m_pData->hGDIObject = hBitmap;
pBitmap->m_pData->bRemoveObject = FALSE;
}
return pBitmap;
}
inline CBrush* FromHandle(HBRUSH hBrush)
// Returns the CBrush associated with the Brush handle
// If a CBrush object doesn't already exist, a temporary CBrush object is created.
// The HBRUSH belonging to a temporary CBrush is not released or destroyed
// when the temporary CBrush is deconstructed.
{
assert( GetApp() );
CBrush* pBrush = (CBrush*)GetApp()->GetCGDIObjectFromMap(hBrush);
if (hBrush != 0 && pBrush == 0)
{
pBrush = new CBrush;
GetApp()->AddTmpGDI(pBrush);
pBrush->m_pData->hGDIObject = hBrush;
pBrush->m_pData->bRemoveObject = FALSE;
}
return pBrush;
}
inline CFont* FromHandle(HFONT hFont)
// Returns the CFont associated with the Font handle
// If a CFont object doesn't already exist, a temporary CFont object is created.
// The HFONT belonging to a temporary CFont is not released or destroyed
// when the temporary CFont is deconstructed.
{
assert( GetApp() );
CFont* pFont = (CFont*)GetApp()->GetCGDIObjectFromMap(hFont);
if (hFont != 0 && pFont == 0)
{
pFont = new CFont;
GetApp()->AddTmpGDI(pFont);
pFont->m_pData->hGDIObject = hFont;
pFont->m_pData->bRemoveObject = FALSE;
}
return pFont;
}
inline CPalette* FromHandle(HPALETTE hPalette)
// Returns the CPalette associated with the palette handle
// If a CPalette object doesn't already exist, a temporary CPalette object is created.
// The HPALETTE belonging to a temporary CPalette is not released or destroyed
// when the temporary CPalette is deconstructed.
{
assert( GetApp() );
CPalette* pPalette = (CPalette*)GetApp()->GetCGDIObjectFromMap(hPalette);
if (hPalette != 0 && pPalette == 0)
{
pPalette = new CPalette;
GetApp()->AddTmpGDI(pPalette);
pPalette->m_pData->hGDIObject = hPalette;
pPalette->m_pData->bRemoveObject = FALSE;
}
return pPalette;
}
inline CPen* FromHandle(HPEN hPen)
// Returns the CPen associated with the HPEN.
// If a CPen object doesn't already exist, a temporary CPen object is created.
// The HPEN belonging to a temporary CPen is not released or destroyed
// when the temporary CPen is deconstructed.
{
assert( GetApp() );
CPen* pPen = (CPen*)GetApp()->GetCGDIObjectFromMap(hPen);
if (hPen != 0 && pPen == 0)
{
pPen = new CPen;
GetApp()->AddTmpGDI(pPen);
pPen->m_pData->hGDIObject = hPen;
pPen->m_pData->bRemoveObject = FALSE;
}
return pPen;
}
inline CRgn* FromHandle(HRGN hRgn)
// Returns the CRgn associated with the HRGN.
// If a CRgn object doesn't already exist, a temporary CRgn object is created.
// The HRGN belonging to a temporary CRgn is not released or destroyed
// when the temporary CRgn is deconstructed.
{
assert( GetApp() );
CRgn* pRgn = (CRgn*)GetApp()->GetCGDIObjectFromMap(hRgn);
if (hRgn != 0 && pRgn == 0)
{
pRgn = new CRgn;
GetApp()->AddTmpGDI(pRgn);
pRgn->m_pData->hGDIObject = hRgn;
pRgn->m_pData->bRemoveObject = FALSE;
}
return pRgn;
}
} // namespace Win32xx
#endif // _WIN32XX_GDI_H_
|