summaryrefslogtreecommitdiffstats
path: root/mmc_updater/depends/win32cpp/docking.h
blob: 9e7c4486a013f1fab65210ad3cf2113a8a254da1 (plain)
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
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
// 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.
//
////////////////////////////////////////////////////////


///////////////////////////////////////////////////////
// docking.h
//  Declaration of the CDocker class

#ifndef _WIN32XX_DOCKING_H_
#define _WIN32XX_DOCKING_H_


#include "wincore.h"
#include "gdi.h"
#include "toolbar.h"
#include "tab.h"
#include "frame.h"
#include "default_resource.h"


// Docking Styles
#define DS_DOCKED_LEFT			0x0001  // Dock the child left
#define DS_DOCKED_RIGHT			0x0002  // Dock the child right
#define DS_DOCKED_TOP			0x0004  // Dock the child top
#define DS_DOCKED_BOTTOM		0x0008  // Dock the child bottom
#define DS_NO_DOCKCHILD_LEFT	0x0010  // Prevent a child docking left
#define DS_NO_DOCKCHILD_RIGHT	0x0020  // Prevent a child docking right
#define DS_NO_DOCKCHILD_TOP		0x0040  // Prevent a child docking at the top
#define DS_NO_DOCKCHILD_BOTTOM	0x0080  // Prevent a child docking at the bottom
#define DS_NO_RESIZE			0x0100  // Prevent resizing
#define DS_NO_CAPTION			0x0200  // Prevent display of caption when docked
#define DS_NO_CLOSE				0x0400	// Prevent closing of a docker while docked
#define DS_NO_UNDOCK			0x0800  // Prevent undocking and dock closing
#define DS_CLIENTEDGE			0x1000  // Has a 3D border when docked
#define DS_FIXED_RESIZE			0x2000	// Perfomed a fixed resize instead of a proportional resize on dock children
#define DS_DOCKED_CONTAINER		0x4000  // Dock a container within a container
#define DS_DOCKED_LEFTMOST      0x10000 // Leftmost outer docking
#define DS_DOCKED_RIGHTMOST     0x20000 // Rightmost outer docking
#define DS_DOCKED_TOPMOST		0x40000 // Topmost outer docking
#define DS_DOCKED_BOTTOMMOST	0x80000 // Bottommost outer docking

// Required for Dev-C++
#ifndef TME_NONCLIENT
  #define TME_NONCLIENT 0x00000010
#endif
#ifndef TME_LEAVE
  #define TME_LEAVE 0x000000002
#endif
#ifndef WM_NCMOUSELEAVE
  #define WM_NCMOUSELEAVE 0x000002A2
#endif

namespace Win32xx
{
	// Class declarations
	class CDockContainer;
	class CDocker;

	typedef Shared_Ptr<CDocker> DockPtr;

	struct ContainerInfo
	{
		TCHAR szTitle[MAX_MENU_STRING];
		int iImage;
		CDockContainer* pContainer;
	};

	///////////////////////////////////////
	// Declaration of the CDockContainer class
	//  A CDockContainer is a CTab window. A CTab has a view window, and optionally a toolbar control.
	//  A top level CDockContainer can contain other CDockContainers. The view for each container
	//  (including the top level container) along with possibly its toolbar, is displayed
	//  within the container parent's view page.
	class CDockContainer : public CTab
	{
	public:

		// Nested class. This is the Wnd for the window displayed over the client area
		// of the tab control.  The toolbar and view window are child windows of the
		// viewpage window. Only the ViewPage of the parent CDockContainer is displayed. It's
		// contents are updated with the view window of the relevant container whenever
		// a different tab is selected.
		class CViewPage : public CWnd
		{

		public:
			CViewPage() : m_pView(NULL), m_pTab(NULL) {}
			virtual ~CViewPage() {}
			virtual CToolBar& GetToolBar() const {return (CToolBar&)m_ToolBar;}
			virtual CWnd* GetView() const	{return m_pView;}
			virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
			virtual void OnCreate();
			virtual LRESULT OnNotify(WPARAM wParam, LPARAM lParam);
			virtual void PreRegisterClass(WNDCLASS &wc);
			virtual void RecalcLayout();
			virtual void SetView(CWnd& wndView);
			virtual LRESULT WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam);

			CWnd* GetTabCtrl() const { return m_pTab;}

		private:
			CToolBar m_ToolBar;
			tString m_tsTooltip;
			CWnd* m_pView;
			CWnd* m_pTab;
		};

	public:
		CDockContainer();
		virtual ~CDockContainer();
		virtual void AddContainer(CDockContainer* pContainer);
		virtual void AddToolBarButton(UINT nID, BOOL bEnabled = TRUE);
		virtual CDockContainer* GetContainerFromIndex(UINT nPage);
		virtual CDockContainer* GetContainerFromView(CWnd* pView) const;
		virtual int GetContainerIndex(CDockContainer* pContainer);
		virtual SIZE GetMaxTabTextSize();
		virtual CViewPage& GetViewPage() const	{ return (CViewPage&)m_ViewPage; }
		virtual void RecalcLayout();
		virtual void RemoveContainer(CDockContainer* pWnd);
		virtual void SelectPage(int nPage);
		virtual void SetTabSize();
		virtual void SetupToolBar();

		// Attributes
		CDockContainer* GetActiveContainer() const {return GetContainerFromView(GetActiveView());}
		CWnd* GetActiveView() const;
		std::vector<ContainerInfo>& GetAllContainers() const {return m_pContainerParent->m_vContainerInfo;}
		CDockContainer* GetContainerParent() const { return m_pContainerParent; }
		CString& GetDockCaption() const	{ return (CString&)m_csCaption; }
		HICON GetTabIcon() const		{ return m_hTabIcon; }
		LPCTSTR GetTabText() const		{ return m_tsTabText.c_str(); }
		virtual CToolBar& GetToolBar() const	{ return GetViewPage().GetToolBar(); }
		CWnd* GetView() const			{ return GetViewPage().GetView(); }
		void SetActiveContainer(CDockContainer* pContainer);
		void SetDockCaption(LPCTSTR szCaption) { m_csCaption = szCaption; }
		void SetTabIcon(HICON hTabIcon) { m_hTabIcon = hTabIcon; }
		void SetTabIcon(UINT nID_Icon);
		void SetTabIcon(int i, HICON hIcon) { CTab::SetTabIcon(i, hIcon); }
		void SetTabText(LPCTSTR szText) { m_tsTabText = szText; }
		void SetTabText(UINT nTab, LPCTSTR szText);
		void SetView(CWnd& Wnd);

	protected:
		virtual void OnCreate();
		virtual void OnLButtonDown(WPARAM wParam, LPARAM lParam);
		virtual void OnLButtonUp(WPARAM wParam, LPARAM lParam);
		virtual void OnMouseLeave(WPARAM wParam, LPARAM lParam);
		virtual LRESULT OnNotifyReflect(WPARAM wParam, LPARAM lParam);
		virtual void PreCreate(CREATESTRUCT &cs);
		virtual LRESULT WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam);

	private:
		std::vector<ContainerInfo> m_vContainerInfo;
		tString m_tsTabText;
		CString m_csCaption;
		CViewPage m_ViewPage;
		int m_iCurrentPage;
		CDockContainer* m_pContainerParent;
		HICON m_hTabIcon;
		int m_nTabPressed;

	};

	typedef struct DRAGPOS
	{
		NMHDR hdr;
		POINT ptPos;
		UINT DockZone;
	} *LPDRAGPOS;


	/////////////////////////////////////////
	// Declaration of the CDocker class
	//  A CDocker window allows other CDocker windows to be "docked" inside it.
	//  A CDocker can dock on the top, left, right or bottom side of a parent CDocker.
	//  There is no theoretical limit to the number of CDockers within CDockers.
	class CDocker : public CWnd
	{
	public:
		//  A nested class for the splitter bar that seperates the docked panes.
		class CDockBar : public CWnd
		{
		public:
			CDockBar();
			virtual ~CDockBar();
			virtual void OnDraw(CDC* pDC);
			virtual void PreCreate(CREATESTRUCT &cs);
			virtual void PreRegisterClass(WNDCLASS& wc);
			virtual void SendNotify(UINT nMessageID);
			virtual void SetColor(COLORREF color);
			virtual LRESULT WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam);

			CDocker* GetDock()				{return m_pDock;}
			int GetWidth()					{return m_DockBarWidth;}
			void SetDock(CDocker* pDock)	{m_pDock = pDock;}
			void SetWidth(int nWidth)		{m_DockBarWidth = nWidth;}

		private:
			CDockBar(const CDockBar&);				// Disable copy construction
			CDockBar& operator = (const CDockBar&); // Disable assignment operator

			CDocker* m_pDock;
			DRAGPOS m_DragPos;
			CBrush m_brBackground;
			int m_DockBarWidth;
		};

		//  A nested class for the window inside a CDocker which includes all of this docked client.
		//  It's the remaining part of the CDocker that doesn't belong to the CDocker's children.
		//  The Docker's view window is a child window of CDockClient.
		class CDockClient : public CWnd
		{
		public:
			CDockClient();
			virtual ~CDockClient() {}
			virtual void Draw3DBorder(RECT& Rect);
			virtual void DrawCaption(WPARAM wParam);
			virtual void DrawCloseButton(CDC& DrawDC, BOOL bFocus);
			virtual CRect GetCloseRect();
			virtual void SendNotify(UINT nMessageID);

			CString& GetCaption() const		{ return (CString&)m_csCaption; }
			CWnd* GetView() const			{ return m_pView; }
			void SetDock(CDocker* pDock)	{ m_pDock = pDock;}
			void SetCaption(LPCTSTR szCaption) { m_csCaption = szCaption; }
			void SetCaptionColors(COLORREF Foregnd1, COLORREF Backgnd1, COLORREF ForeGnd2, COLORREF BackGnd2);
			void SetClosePressed()			{ m_IsClosePressed = TRUE; }
			void SetView(CWnd& Wnd)			{ m_pView = &Wnd; }

		protected:
			virtual void    OnLButtonDown(WPARAM wParam, LPARAM lParam);
			virtual void OnLButtonUp(WPARAM wParam, LPARAM lParam);
			virtual void    OnMouseActivate(WPARAM wParam, LPARAM lParam);
			virtual void    OnMouseMove(WPARAM wParam, LPARAM lParam);
			virtual void    OnNCCalcSize(WPARAM& wParam, LPARAM& lParam);
			virtual LRESULT OnNCHitTest(WPARAM wParam, LPARAM lParam);
			virtual LRESULT OnNCLButtonDown(WPARAM wParam, LPARAM lParam);
			virtual void    OnNCMouseLeave(WPARAM wParam, LPARAM lParam);
			virtual LRESULT OnNCMouseMove(WPARAM wParam, LPARAM lParam);
			virtual LRESULT OnNCPaint(WPARAM wParam, LPARAM lParam);
			virtual void    OnWindowPosChanged(WPARAM wParam, LPARAM lParam);
			virtual void    PreRegisterClass(WNDCLASS& wc);
			virtual void    PreCreate(CREATESTRUCT& cs);
			virtual LRESULT WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam);

		private:
			CDockClient(const CDockClient&);				// Disable copy construction
			CDockClient& operator = (const CDockClient&); // Disable assignment operator

			CString m_csCaption;
			CPoint m_Oldpt;
			CDocker* m_pDock;
			CWnd* m_pView;
			BOOL m_IsClosePressed;
			BOOL m_bOldFocus;
			BOOL m_bCaptionPressed;
			BOOL m_IsTracking;
			COLORREF m_Foregnd1;
			COLORREF m_Backgnd1;
			COLORREF m_Foregnd2;
			COLORREF m_Backgnd2;
		};

		//  This nested class is used to indicate where a window could dock by
		//  displaying a blue tinted window.
		class CDockHint : public CWnd
		{
		public:
			CDockHint();
			virtual ~CDockHint();
			virtual RECT CalcHintRectContainer(CDocker* pDockTarget);
			virtual RECT CalcHintRectInner(CDocker* pDockTarget, CDocker* pDockDrag, UINT uDockSide);
			virtual RECT CalcHintRectOuter(CDocker* pDockDrag, UINT uDockSide);
			virtual void DisplayHint(CDocker* pDockTarget, CDocker* pDockDrag, UINT uDockSide);
			virtual void OnDraw(CDC* pDC);
			virtual void PreCreate(CREATESTRUCT &cs);
			virtual void ShowHintWindow(CDocker* pDockTarget, CRect rcHint);

		private:
			CDockHint(const CDockHint&);				// Disable copy construction
			CDockHint& operator = (const CDockHint&); // Disable assignment operator

			CBitmap m_bmBlueTint;
			UINT m_uDockSideOld;
		};

		class CTarget : public CWnd
		{
		public:
			CTarget() {}
			virtual ~CTarget();
			virtual void OnDraw(CDC* pDC);
			virtual void PreCreate(CREATESTRUCT &cs);

		protected:
			CBitmap m_bmImage;

		private:
			CTarget(const CTarget&);				// Disable copy construction
			CTarget& operator = (const CTarget&); // Disable assignment operator
		};

		class CTargetCentre : public CTarget
		{
		public:
			CTargetCentre();
			virtual ~CTargetCentre();
			virtual void OnDraw(CDC* pDC);
			virtual void OnCreate();
			virtual BOOL CheckTarget(LPDRAGPOS pDragPos);
			BOOL IsOverContainer() { return m_bIsOverContainer; }

		private:
			CTargetCentre(const CTargetCentre&);				// Disable copy construction
			CTargetCentre& operator = (const CTargetCentre&); // Disable assignment operator

			BOOL m_bIsOverContainer;
			CDocker* m_pOldDockTarget;
		};

		class CTargetLeft : public CTarget
		{
		public:
			CTargetLeft() {m_bmImage.LoadImage(IDW_SDLEFT,0,0,0);}
			virtual BOOL CheckTarget(LPDRAGPOS pDragPos);

		private:
			CTargetLeft(const CTargetLeft&);				// Disable copy construction
			CTargetLeft& operator = (const CTargetLeft&); // Disable assignment operator
		};

		class CTargetTop : public CTarget
		{
		public:
			CTargetTop() {m_bmImage.LoadImage(IDW_SDTOP,0,0,0);}
			virtual BOOL CheckTarget(LPDRAGPOS pDragPos);
		private:
			CTargetTop(const CTargetTop&);				// Disable copy construction
			CTargetTop& operator = (const CTargetTop&); // Disable assignment operator
		};

		class CTargetRight : public CTarget
		{
		public:
			CTargetRight() {m_bmImage.LoadImage(IDW_SDRIGHT,0,0,0);}
			virtual BOOL CheckTarget(LPDRAGPOS pDragPos);

		private:
			CTargetRight(const CTargetRight&);				// Disable copy construction
			CTargetRight& operator = (const CTargetRight&); // Disable assignment operator
		};

		class CTargetBottom : public CTarget
		{
		public:
			CTargetBottom() {m_bmImage.LoadImage(IDW_SDBOTTOM,0,0,0);}
			virtual BOOL CheckTarget(LPDRAGPOS pDragPos);
		};

		friend class CTargetCentre;
		friend class CTargetLeft;
		friend class CTargetTop;
		friend class CTargetRight;
		friend class CTargetBottom;
		friend class CDockClient;
		friend class CDockContainer;

	public:
		// Operations
		CDocker();
		virtual ~CDocker();
		virtual CDocker* AddDockedChild(CDocker* pDocker, DWORD dwDockStyle, int DockSize, int nDockID = 0);
		virtual CDocker* AddUndockedChild(CDocker* pDocker, DWORD dwDockStyle, int DockSize, RECT rc, int nDockID = 0);
		virtual void Close();
		virtual void CloseAllDockers();
		virtual void Dock(CDocker* pDocker, UINT uDockSide);
		virtual void DockInContainer(CDocker* pDock, DWORD dwDockStyle);
		virtual CDockContainer* GetContainer() const;
		virtual CDocker* GetActiveDocker() const;
		virtual CDocker* GetDockAncestor() const;
		virtual CDocker* GetDockFromID(int n_DockID) const;
		virtual CDocker* GetDockFromPoint(POINT pt) const;
		virtual CDocker* GetDockFromView(CWnd* pView) const;
		virtual CDocker* GetTopmostDocker() const;
		virtual int GetDockSize() const;
		virtual CTabbedMDI* GetTabbedMDI() const;
		virtual int GetTextHeight();
		virtual void Hide();
		virtual BOOL LoadRegistrySettings(tString tsRegistryKeyName);
		virtual void RecalcDockLayout();
		virtual BOOL SaveRegistrySettings(tString tsRegistryKeyName);
		virtual void Undock(CPoint pt, BOOL bShowUndocked = TRUE);
		virtual void UndockContainer(CDockContainer* pContainer, CPoint pt, BOOL bShowUndocked);
		virtual BOOL VerifyDockers();

		// Attributes
		virtual CDockBar& GetDockBar() const {return (CDockBar&)m_DockBar;}
		virtual CDockClient& GetDockClient() const {return (CDockClient&)m_DockClient;}
		virtual CDockHint& GetDockHint() const {return m_pDockAncestor->m_DockHint;}


		std::vector <DockPtr> & GetAllDockers() const {return GetDockAncestor()->m_vAllDockers;}
		int GetBarWidth() const {return GetDockBar().GetWidth();}
		CString& GetCaption() const {return GetDockClient().GetCaption();}
		std::vector <CDocker*> & GetDockChildren() const {return (std::vector <CDocker*> &)m_vDockChildren;}
		int GetDockID() const {return m_nDockID;}
		CDocker* GetDockParent() const {return m_pDockParent;}
		DWORD GetDockStyle() const {return m_DockStyle;}
		CWnd* GetView() const {return GetDockClient().GetView();}
		BOOL IsChildOfDocker(CWnd* pWnd) const;
		BOOL IsDocked() const;
		BOOL IsDragAutoResize();
		BOOL IsRelated(CWnd* pWnd) const;
		BOOL IsUndocked() const;
		void SetBarColor(COLORREF color) {GetDockBar().SetColor(color);}
		void SetBarWidth(int nWidth) {GetDockBar().SetWidth(nWidth);}
		void SetCaption(LPCTSTR szCaption);
		void SetCaptionColors(COLORREF Foregnd1, COLORREF Backgnd1, COLORREF ForeGnd2, COLORREF BackGnd2);
		void SetCaptionHeight(int nHeight);
		void SetDockStyle(DWORD dwDockStyle);
		void SetDockSize(int DockSize);
		void SetDragAutoResize(BOOL bAutoResize);
		void SetView(CWnd& wndView);

	protected:
		virtual CDocker* NewDockerFromID(int idDock);
		virtual void OnActivate(WPARAM wParam, LPARAM lParam);
		virtual void OnCaptionTimer(WPARAM wParam, LPARAM lParam);
		virtual void OnCreate();
		virtual void OnDestroy(WPARAM wParam, LPARAM lParam);
		virtual void OnDockDestroyed(WPARAM wParam, LPARAM lParam);
		virtual void OnExitSizeMove(WPARAM wParam, LPARAM lParam);
		virtual LRESULT OnNotify(WPARAM wParam, LPARAM lParam);
		virtual void OnSetFocus(WPARAM wParam, LPARAM lParam);
		virtual void OnSysColorChange(WPARAM wParam, LPARAM lParam);
		virtual LRESULT OnSysCommand(WPARAM wParam, LPARAM lParam);
		virtual LRESULT OnWindowPosChanging(WPARAM wParam, LPARAM lParam);
		virtual void OnWindowPosChanged(WPARAM wParam, LPARAM lParam);
		virtual void PreCreate(CREATESTRUCT &cs);
		virtual void PreRegisterClass(WNDCLASS &wc);
		virtual LRESULT WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam);

	private:
		CDocker(const CDocker&);				// Disable copy construction
		CDocker& operator = (const CDocker&);	// Disable assignment operator
		void CheckAllTargets(LPDRAGPOS pDragPos);
		void CloseAllTargets();
		void DockOuter(CDocker* pDocker, DWORD dwDockStyle);
		void DrawAllCaptions();
		void DrawHashBar(HWND hBar, POINT Pos);
		void ConvertToChild(HWND hWndParent);
		void ConvertToPopup(RECT rc);
		void MoveDockChildren(CDocker* pDockTarget);
		void PromoteFirstChild();
		void RecalcDockChildLayout(CRect rc);
		void ResizeDockers(LPDRAGPOS pdp);
		CDocker* SeparateFromDock();
		void SendNotify(UINT nMessageID);
		void SetUndockPosition(CPoint pt);
		std::vector<CDocker*> SortDockers();

		CDockBar		m_DockBar;
		CDockHint		m_DockHint;
		CDockClient		m_DockClient;
		CTargetCentre	m_TargetCentre;
		CTargetLeft		m_TargetLeft;
		CTargetTop		m_TargetTop;
		CTargetRight	m_TargetRight;
		CPoint			m_OldPoint;
		CTargetBottom	m_TargetBottom;
		CDocker*		m_pDockParent;
		CDocker*		m_pDockAncestor;
		CDocker*		m_pDockActive;

		std::vector <CDocker*> m_vDockChildren;
		std::vector <DockPtr> m_vAllDockers;	// Only used in DockAncestor

		CRect m_rcBar;
		CRect m_rcChild;

		BOOL m_BlockMove;
		BOOL m_Undocking;
		BOOL m_bIsClosing;
		BOOL m_bIsDragging;
		BOOL m_bDragAutoResize;
		int m_DockStartSize;
		int m_nDockID;
		int m_nTimerCount;
		int m_NCHeight;
		DWORD m_dwDockZone;
		double m_DockSizeRatio;
		DWORD m_DockStyle;
		HWND m_hOldFocus;

	}; // class CDocker

	struct DockInfo
	{
		DWORD DockStyle;
		int DockSize;
		int DockID;
		int DockParentID;
		RECT Rect;
	};

}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

namespace Win32xx
{

	/////////////////////////////////////////////////////////////
	// Definitions for the CDockBar class nested within CDocker
	//
	inline CDocker::CDockBar::CDockBar() : m_pDock(NULL), m_DockBarWidth(4)
	{
		m_brBackground.CreateSolidBrush(RGB(192,192,192));
	}

	inline CDocker::CDockBar::~CDockBar()
	{
	}

	inline void CDocker::CDockBar::OnDraw(CDC* pDC)
	{
		CRect rcClient = GetClientRect();
		pDC->SelectObject(&m_brBackground);
		pDC->PatBlt(0, 0, rcClient.Width(), rcClient.Height(), PATCOPY);
	}

	inline void CDocker::CDockBar::PreCreate(CREATESTRUCT &cs)
	{
		// Create a child window, initially hidden
		cs.style = WS_CHILD;
	}

	inline void CDocker::CDockBar::PreRegisterClass(WNDCLASS& wc)
	{
		wc.lpszClassName = _T("Win32++ Bar");
		wc.hbrBackground = m_brBackground;
	}

	inline void CDocker::CDockBar::SendNotify(UINT nMessageID)
	{
		// Send a splitter bar notification to the parent
		m_DragPos.hdr.code = nMessageID;
		m_DragPos.hdr.hwndFrom = m_hWnd;
		m_DragPos.ptPos = GetCursorPos();
		m_DragPos.ptPos.x += 1;
		GetParent()->SendMessage(WM_NOTIFY, 0L, (LPARAM)&m_DragPos);
	}

	inline void CDocker::CDockBar::SetColor(COLORREF color)
	{
		// Useful colors:
		// GetSysColor(COLOR_BTNFACE)	// Default Grey
		// RGB(196, 215, 250)			// Default Blue

		m_brBackground.CreateSolidBrush(color);
	}

	inline LRESULT CDocker::CDockBar::WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam)
	{
		{
			switch (uMsg)
			{
			case WM_SETCURSOR:
				{
					if (!(m_pDock->GetDockStyle() & DS_NO_RESIZE))
					{
						HCURSOR hCursor;
						DWORD dwSide = GetDock()->GetDockStyle() & 0xF;
						if ((dwSide == DS_DOCKED_LEFT) || (dwSide == DS_DOCKED_RIGHT))
							hCursor = LoadCursor(GetApp()->GetResourceHandle(), MAKEINTRESOURCE(IDW_SPLITH));
						else
							hCursor = LoadCursor(GetApp()->GetResourceHandle(), MAKEINTRESOURCE(IDW_SPLITV));

						if (hCursor) SetCursor(hCursor);
						else TRACE(_T("**WARNING** Missing cursor resource for slider bar\n"));

						return TRUE;
					}
					else
						SetCursor(LoadCursor(NULL, IDC_ARROW));
				}
				break;

			case WM_ERASEBKGND:
				return 0;

			case WM_LBUTTONDOWN:
				{
					if (!(m_pDock->GetDockStyle() & DS_NO_RESIZE))
					{
						SendNotify(UWM_BAR_START);
						SetCapture();
					}
				}
				break;

			case WM_LBUTTONUP:
				if (!(m_pDock->GetDockStyle() & DS_NO_RESIZE) && (GetCapture() == this))
				{
					SendNotify(UWM_BAR_END);
					ReleaseCapture();
				}
				break;

			case WM_MOUSEMOVE:
				if (!(m_pDock->GetDockStyle() & DS_NO_RESIZE) && (GetCapture() == this))
				{
					SendNotify(UWM_BAR_MOVE);
				}
				break;
			}
		}

		// pass unhandled messages on for default processing
		return CWnd::WndProcDefault(uMsg, wParam, lParam);
	}


	////////////////////////////////////////////////////////////////
	// Definitions for the CDockClient class nested within CDocker
	//
	inline CDocker::CDockClient::CDockClient() : m_pView(0), m_IsClosePressed(FALSE),
						m_bOldFocus(FALSE), m_bCaptionPressed(FALSE), m_IsTracking(FALSE)
	{
		m_Foregnd1 = RGB(32,32,32);
		m_Backgnd1 = RGB(190,207,227);
		m_Foregnd2 =  GetSysColor(COLOR_BTNTEXT);
		m_Backgnd2 = GetSysColor(COLOR_BTNFACE);
	}

	inline void CDocker::CDockClient::Draw3DBorder(RECT& Rect)
	{
		// Imitates the drawing of the WS_EX_CLIENTEDGE extended style
		// This draws a 2 pixel border around the specified Rect
		CWindowDC dc(this);
		CRect rcw = Rect;
		dc.CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
		dc.MoveTo(0, rcw.Height());
		dc.LineTo(0, 0);
		dc.LineTo(rcw.Width(), 0);
		dc.CreatePen(PS_SOLID,1, GetSysColor(COLOR_3DDKSHADOW));
		dc.MoveTo(1, rcw.Height()-2);
		dc.LineTo(1, 1);
		dc.LineTo(rcw.Width()-2, 1);
		dc.CreatePen(PS_SOLID,1, GetSysColor(COLOR_3DHILIGHT));
		dc.MoveTo(rcw.Width()-1, 0);
		dc.LineTo(rcw.Width()-1, rcw.Height()-1);
		dc.LineTo(0, rcw.Height()-1);
		dc.CreatePen(PS_SOLID,1, GetSysColor(COLOR_3DLIGHT));
		dc.MoveTo(rcw.Width()-2, 1);
		dc.LineTo(rcw.Width()-2, rcw.Height()-2);
		dc.LineTo(1, rcw.Height()-2);
	}

	inline CRect CDocker::CDockClient::GetCloseRect()
	{
		// Calculate the close rect position in screen co-ordinates
		CRect rcClose;

		int gap = 4;
		CRect rc = GetWindowRect();
		int cx = GetSystemMetrics(SM_CXSMICON);
		int cy = GetSystemMetrics(SM_CYSMICON);

		rcClose.top = 2 + rc.top + m_pDock->m_NCHeight/2 - cy/2;
		rcClose.bottom = 2 + rc.top + m_pDock->m_NCHeight/2 + cy/2;
		rcClose.right = rc.right - gap;
		rcClose.left = rcClose.right - cx;

#if defined(WINVER) && defined (WS_EX_LAYOUTRTL) && (WINVER >= 0x0500)
		if (GetWindowLongPtr(GWL_EXSTYLE) & WS_EX_LAYOUTRTL)
		{
			rcClose.left = rc.left + gap;
			rcClose.right = rcClose.left + cx;
		}
#endif


		return rcClose;
	}

	inline void CDocker::CDockClient::DrawCaption(WPARAM wParam)
	{
		if (IsWindow() && m_pDock->IsDocked() && !(m_pDock->GetDockStyle() & DS_NO_CAPTION))
		{
			BOOL bFocus = m_pDock->IsChildOfDocker(GetFocus());
			m_bOldFocus = FALSE;

			// Acquire the DC for our NonClient painting
			CDC* pDC;
			if ((wParam != 1) && (bFocus == m_bOldFocus))
				pDC = GetDCEx((HRGN)wParam, DCX_WINDOW|DCX_INTERSECTRGN|DCX_PARENTCLIP);
			else
				pDC	= GetWindowDC();

			// Create and set up our memory DC
			CRect rc = GetWindowRect();
			CMemDC dcMem(pDC);
			int rcAdjust = (GetWindowLongPtr(GWL_EXSTYLE) & WS_EX_CLIENTEDGE)? 2 : 0;
			int Width = MAX(rc.Width() -rcAdjust, 0);
			int Height = m_pDock->m_NCHeight + rcAdjust;
			dcMem.CreateCompatibleBitmap(pDC, Width, Height);
			m_bOldFocus = bFocus;

			// Set the font for the title
			NONCLIENTMETRICS info = {0};
			info.cbSize = GetSizeofNonClientMetrics();
			SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(info), &info, 0);
			dcMem.CreateFontIndirect(&info.lfStatusFont);

			// Set the Colours
			if (bFocus)
			{
				dcMem.SetTextColor(m_Foregnd1);
				dcMem.CreateSolidBrush(m_Backgnd1);
				dcMem.SetBkColor(m_Backgnd1);
			}
			else
			{
				dcMem.SetTextColor(m_Foregnd2);
				dcMem.CreateSolidBrush(m_Backgnd2);
				dcMem.SetBkColor(m_Backgnd2);
			}

			// Draw the rectangle
			dcMem.CreatePen(PS_SOLID, 1, RGB(160, 150, 140));
			dcMem.Rectangle(rcAdjust, rcAdjust, rc.Width() -rcAdjust, m_pDock->m_NCHeight +rcAdjust);

			// Display the caption
			int cx = (m_pDock->GetDockStyle() & DS_NO_CLOSE)? 0 : GetSystemMetrics(SM_CXSMICON);
			CRect rcText(4 +rcAdjust, rcAdjust, rc.Width() -4 - cx -rcAdjust, m_pDock->m_NCHeight +rcAdjust);
			dcMem.DrawText(m_csCaption, m_csCaption.GetLength(), rcText, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS);

			// Draw the close button
			if ((0 != m_pDock) && !(m_pDock->GetDockStyle() & DS_NO_CLOSE))
				DrawCloseButton(dcMem, bFocus);

			// Draw the 3D border
			if (GetWindowLongPtr(GWL_EXSTYLE) & WS_EX_CLIENTEDGE)
				Draw3DBorder(rc);

			// Copy the Memory DC to the window's DC
			pDC->BitBlt(rcAdjust, rcAdjust, Width, Height, &dcMem, rcAdjust, rcAdjust, SRCCOPY);

			// Required for Win98/WinME
			pDC->Destroy();
		}
	}

	inline void CDocker::CDockClient::DrawCloseButton(CDC& DrawDC, BOOL bFocus)
	{
		// The close button isn't displayed on Win95
		if (GetWinVersion() == 1400)  return;

		if (m_pDock->IsDocked() && !(m_pDock->GetDockStyle() & DS_NO_CAPTION))
		{
			// Determine the close button's drawing position relative to the window
			CRect rcClose = GetCloseRect();
			UINT uState = GetCloseRect().PtInRect(GetCursorPos())? m_IsClosePressed && IsLeftButtonDown()? 2 : 1 : 0;
			ScreenToClient(rcClose);

			if (GetWindowLongPtr(GWL_EXSTYLE) & WS_EX_CLIENTEDGE)
			{
				rcClose.OffsetRect(2, m_pDock->m_NCHeight+2);
				if (GetWindowRect().Height() < (m_pDock->m_NCHeight+4))
					rcClose.OffsetRect(-2, -2);
			}
			else
				rcClose.OffsetRect(0, m_pDock->m_NCHeight-2);

			// Draw the outer highlight for the close button
			if (!IsRectEmpty(&rcClose))
			{
				switch (uState)
				{
				case 0:
					{
						// Normal button
						DrawDC.CreatePen(PS_SOLID, 1, RGB(232, 228, 220));
						DrawDC.MoveTo(rcClose.left, rcClose.bottom);
						DrawDC.LineTo(rcClose.right, rcClose.bottom);
						DrawDC.LineTo(rcClose.right, rcClose.top);
						DrawDC.LineTo(rcClose.left, rcClose.top);
						DrawDC.LineTo(rcClose.left, rcClose.bottom);
						break;
					}

				case 1:
					{
						// Popped up button
						// Draw outline, white at top, black on bottom
						DrawDC.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
						DrawDC.MoveTo(rcClose.left, rcClose.bottom);
						DrawDC.LineTo(rcClose.right, rcClose.bottom);
						DrawDC.LineTo(rcClose.right, rcClose.top);
						DrawDC.CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
						DrawDC.LineTo(rcClose.left, rcClose.top);
						DrawDC.LineTo(rcClose.left, rcClose.bottom);
					}

					break;
				case 2:
					{
						// Pressed button
						// Draw outline, black on top, white on bottom
						DrawDC.CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
						DrawDC.MoveTo(rcClose.left, rcClose.bottom);
						DrawDC.LineTo(rcClose.right, rcClose.bottom);
						DrawDC.LineTo(rcClose.right, rcClose.top);
						DrawDC.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
						DrawDC.LineTo(rcClose.left, rcClose.top);
						DrawDC.LineTo(rcClose.left, rcClose.bottom);
					}
					break;
				}

				// Manually Draw Close Button
				if (bFocus)
					DrawDC.CreatePen(PS_SOLID, 1, m_Foregnd1);
				else
					DrawDC.CreatePen(PS_SOLID, 1, m_Foregnd2);

				DrawDC.MoveTo(rcClose.left + 3, rcClose.top +3);
				DrawDC.LineTo(rcClose.right - 2, rcClose.bottom -2);

				DrawDC.MoveTo(rcClose.left + 4, rcClose.top +3);
				DrawDC.LineTo(rcClose.right - 2, rcClose.bottom -3);

				DrawDC.MoveTo(rcClose.left + 3, rcClose.top +4);
				DrawDC.LineTo(rcClose.right - 3, rcClose.bottom -2);

				DrawDC.MoveTo(rcClose.right -3, rcClose.top +3);
				DrawDC.LineTo(rcClose.left + 2, rcClose.bottom -2);

				DrawDC.MoveTo(rcClose.right -3, rcClose.top +4);
				DrawDC.LineTo(rcClose.left + 3, rcClose.bottom -2);

				DrawDC.MoveTo(rcClose.right -4, rcClose.top +3);
				DrawDC.LineTo(rcClose.left + 2, rcClose.bottom -3);
			}
		}
	}

	inline void CDocker::CDockClient::OnNCCalcSize(WPARAM& wParam, LPARAM& lParam)
	{
		// Sets the non-client area (and hence sets the client area)
		// This function modifies lParam

		UNREFERENCED_PARAMETER(wParam);

		if ((0 != m_pDock) && !(m_pDock->GetDockStyle() & DS_NO_CAPTION))
		{
			if (m_pDock->IsDocked())
			{
				LPRECT rc = (LPRECT)lParam;
				rc->top += m_pDock->m_NCHeight;
			}
		}
	}

	inline LRESULT CDocker::CDockClient::OnNCHitTest(WPARAM wParam, LPARAM lParam)
	{
		// Identify which part of the non-client area the cursor is over
		if ((0 != m_pDock) && !(m_pDock->GetDockStyle() & DS_NO_CAPTION))
		{
			if (m_pDock->IsDocked())
			{
				CPoint pt(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));

				// Indicate if the point is in the close button (except for Win95)
				if ((GetWinVersion() > 1400) && (GetCloseRect().PtInRect(pt)))
					return HTCLOSE;

				ScreenToClient(pt);

				// Indicate if the point is in the caption
				if (pt.y < 0)
					return HTCAPTION;
			}
		}
		return CWnd::WndProcDefault(WM_NCHITTEST, wParam, lParam);
	}

	inline LRESULT CDocker::CDockClient::OnNCLButtonDown(WPARAM wParam, LPARAM lParam)
	{
		if ((0 != m_pDock) && !(m_pDock->GetDockStyle() & DS_NO_CAPTION))
		{
			if ((HTCLOSE == wParam) && !(m_pDock->GetDockStyle() & DS_NO_CLOSE))
			{
				m_IsClosePressed = TRUE;
				SetCapture();
			}

			m_bCaptionPressed = TRUE;
			m_Oldpt.x = GET_X_LPARAM(lParam);
			m_Oldpt.y = GET_Y_LPARAM(lParam);
			if (m_pDock->IsDocked())
			{
				CPoint pt(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
				ScreenToClient(pt);
				m_pView->SetFocus();

				// Update the close button
				if ((0 != m_pDock) && !(m_pDock->GetDockStyle() & DS_NO_CLOSE))
				{
					CWindowDC dc(this);
					DrawCloseButton(dc, m_bOldFocus);
				}

				return 0L;
			}
		}
		return CWnd::WndProcDefault(WM_NCLBUTTONDOWN, wParam, lParam);
	}

	inline void CDocker::CDockClient::OnLButtonUp(WPARAM wParam, LPARAM lParam)
	{
		UNREFERENCED_PARAMETER(wParam);
		UNREFERENCED_PARAMETER(lParam);

		if ((0 != m_pDock) && !(m_pDock->GetDockStyle() & (DS_NO_CAPTION|DS_NO_CLOSE)))
		{
			m_bCaptionPressed = FALSE;
			if (m_IsClosePressed && GetCloseRect().PtInRect(GetCursorPos()))
			{
				// Destroy the docker
				if (dynamic_cast<CDockContainer*>(m_pDock->GetView()))
				{
					CDockContainer* pContainer = ((CDockContainer*)m_pDock->GetView())->GetActiveContainer();
					CDocker* pDock = m_pDock->GetDockFromView(pContainer);
					pDock->GetDockClient().SetClosePressed();
					m_pDock->UndockContainer(pContainer, GetCursorPos(), FALSE);
					pDock->Destroy();
				}
				else
				{
					m_pDock->Hide();
					m_pDock->Destroy();
				}
			}
		}
	}

	inline void CDocker::CDockClient::OnLButtonDown(WPARAM wParam, LPARAM lParam)
	{
		UNREFERENCED_PARAMETER(wParam);
		UNREFERENCED_PARAMETER(lParam);

		m_IsClosePressed = FALSE;
		ReleaseCapture();
		CWindowDC dc(this);
		DrawCloseButton(dc, m_bOldFocus);
	}

	inline void CDocker::CDockClient::OnMouseActivate(WPARAM wParam, LPARAM lParam)
	// Focus changed, so redraw the captions
	{
		UNREFERENCED_PARAMETER(wParam);
		UNREFERENCED_PARAMETER(lParam);

		if ((0 != m_pDock) && !(m_pDock->GetDockStyle() & DS_NO_CAPTION))
		{
			m_pDock->GetDockAncestor()->PostMessage(UWM_DOCK_ACTIVATED, 0, 0);
		}
	}

	inline void CDocker::CDockClient::OnMouseMove(WPARAM wParam, LPARAM lParam)
	{
		OnNCMouseMove(wParam, lParam);
	}

	inline void CDocker::CDockClient::OnNCMouseLeave(WPARAM wParam, LPARAM lParam)
	{
		UNREFERENCED_PARAMETER(wParam);
		UNREFERENCED_PARAMETER(lParam);

		m_IsTracking = FALSE;
		CWindowDC dc(this);
		if ((0 != m_pDock) && !(m_pDock->GetDockStyle() & (DS_NO_CAPTION|DS_NO_CLOSE)) && m_pDock->IsDocked())
			DrawCloseButton(dc, m_bOldFocus);

		m_IsTracking = FALSE;
	}

	inline LRESULT CDocker::CDockClient::OnNCMouseMove(WPARAM wParam, LPARAM lParam)
	{
		if (!m_IsTracking)
		{
			TRACKMOUSEEVENT TrackMouseEventStruct = {0};
			TrackMouseEventStruct.cbSize = sizeof(TrackMouseEventStruct);
			TrackMouseEventStruct.dwFlags = TME_LEAVE|TME_NONCLIENT;
			TrackMouseEventStruct.hwndTrack = m_hWnd;
			_TrackMouseEvent(&TrackMouseEventStruct);
			m_IsTracking = TRUE;
		}

		if ((0 != m_pDock) && !(m_pDock->GetDockStyle() & DS_NO_CAPTION))
		{
			if (m_pDock->IsDocked())
			{
				// Discard phantom mouse move messages
				if ( (m_Oldpt.x == GET_X_LPARAM(lParam) ) && (m_Oldpt.y == GET_Y_LPARAM(lParam)))
					return 0L;

				if (IsLeftButtonDown() && (wParam == HTCAPTION)  && (m_bCaptionPressed))
				{
					CDocker* pDock = (CDocker*)GetParent();
					if (pDock)
						pDock->Undock(GetCursorPos());
				}

				// Update the close button
				if ((0 != m_pDock) && !(m_pDock->GetDockStyle() & DS_NO_CLOSE))
				{
					CWindowDC dc(this);
					DrawCloseButton(dc, m_bOldFocus);
				}
			}

			m_bCaptionPressed = FALSE;
		}
		return CWnd::WndProcDefault(WM_MOUSEMOVE, wParam, lParam);
	}

	inline LRESULT CDocker::CDockClient::OnNCPaint(WPARAM wParam, LPARAM lParam)
	{
		if ((0 != m_pDock) && !(m_pDock->GetDockStyle() & DS_NO_CAPTION))
		{
			if (m_pDock->IsDocked())
			{
				DefWindowProc(WM_NCPAINT, wParam, lParam);
				DrawCaption(wParam);
				return 0;
			}
		}
		return CWnd::WndProcDefault(WM_NCPAINT, wParam, lParam);
	}

	inline void CDocker::CDockClient::OnWindowPosChanged(WPARAM wParam, LPARAM lParam)
	{
		UNREFERENCED_PARAMETER(wParam);
		UNREFERENCED_PARAMETER(lParam);

		// Reposition the View window to cover the DockClient's client area
		CRect rc = GetClientRect();
		m_pView->SetWindowPos(NULL, rc, SWP_SHOWWINDOW);
	}

	inline void CDocker::CDockClient::PreRegisterClass(WNDCLASS& wc)
	{
		wc.lpszClassName = _T("Win32++ DockClient");
		wc.hCursor = ::LoadCursor(NULL, IDC_ARROW);
	}

	inline void CDocker::CDockClient::PreCreate(CREATESTRUCT& cs)
	{
		DWORD dwStyle = m_pDock->GetDockStyle();
		if (dwStyle & DS_CLIENTEDGE)
			cs.dwExStyle = WS_EX_CLIENTEDGE;

#if defined(WINVER) && defined (WS_EX_LAYOUTRTL) && (WINVER >= 0x0500)
		if (m_pDock->GetWindowLongPtr(GWL_EXSTYLE) & WS_EX_LAYOUTRTL)
			cs.dwExStyle |= WS_EX_LAYOUTRTL;
#endif

	}

	inline void CDocker::CDockClient::SendNotify(UINT nMessageID)
	{
		// Fill the DragPos structure with data
		DRAGPOS DragPos;
		DragPos.hdr.code = nMessageID;
		DragPos.hdr.hwndFrom = m_hWnd;
		DragPos.ptPos = GetCursorPos();

		// Send a DragPos notification to the docker
		GetParent()->SendMessage(WM_NOTIFY, 0L, (LPARAM)&DragPos);
	}

	inline void CDocker::CDockClient::SetCaptionColors(COLORREF Foregnd1, COLORREF Backgnd1, COLORREF Foregnd2, COLORREF Backgnd2)
	{
		// Set the colors used when drawing the caption
		// m_Foregnd1 Foreground colour (focused).  m_Backgnd1 Background colour (focused)
		// m_Foregnd2 Foreground colour (not focused). m_Backgnd2 Foreground colour (not focused)
		m_Foregnd1 = Foregnd1;
		m_Backgnd1 = Backgnd1;
		m_Foregnd2 = Foregnd2;
		m_Backgnd2 = Backgnd2;
	}

	inline LRESULT CDocker::CDockClient::WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam)
	{
		switch (uMsg)
		{
		case WM_LBUTTONUP:
			{
				ReleaseCapture();
				if ((0 != m_pDock) && !(m_pDock->GetDockStyle() & DS_NO_CLOSE))
				{
					CWindowDC dc(this);
					DrawCloseButton(dc, m_bOldFocus);
					OnLButtonUp(wParam, lParam);
				}
			}
			break;

		case WM_MOUSEACTIVATE:
			OnMouseActivate(wParam, lParam);
			break;

		case WM_MOUSEMOVE:
			OnMouseMove(wParam, lParam);
			break;

		case WM_NCCALCSIZE:
			OnNCCalcSize(wParam, lParam);
			break;

		case WM_NCHITTEST:
			return OnNCHitTest(wParam, lParam);

		case WM_NCLBUTTONDOWN:
			return OnNCLButtonDown(wParam, lParam);

		case WM_NCMOUSEMOVE:
			return OnNCMouseMove(wParam, lParam);

		case WM_NCPAINT:
			return OnNCPaint(wParam, lParam);

		case WM_NCMOUSELEAVE:
			OnNCMouseLeave(wParam, lParam);
			break;

		case WM_WINDOWPOSCHANGED:
			OnWindowPosChanged(wParam, lParam);
			break;
		}

		return CWnd::WndProcDefault(uMsg, wParam, lParam);
	}


	//////////////////////////////////////////////////////////////
	// Definitions for the CDockHint class nested within CDocker
	//
	inline CDocker::CDockHint::CDockHint() : m_uDockSideOld(0)
	{
	}

	inline CDocker::CDockHint::~CDockHint()
	{
	}

	inline RECT CDocker::CDockHint::CalcHintRectContainer(CDocker* pDockTarget)
	{
		// Calculate the hint window's position for container docking
		CRect rcHint = pDockTarget->GetDockClient().GetWindowRect();
		if (pDockTarget->GetDockClient().GetWindowLongPtr(GWL_EXSTYLE) & WS_EX_CLIENTEDGE)
			rcHint.InflateRect(-2, -2);
		pDockTarget->ScreenToClient(rcHint);

		return rcHint;
	}

	inline RECT CDocker::CDockHint::CalcHintRectInner(CDocker* pDockTarget, CDocker* pDockDrag, UINT uDockSide)
	{
		// Calculate the hint window's position for inner docking
		CRect rcHint = pDockTarget->GetDockClient().GetWindowRect();
		if (pDockTarget->GetDockClient().GetWindowLongPtr(GWL_EXSTYLE) & WS_EX_CLIENTEDGE)
			rcHint.InflateRect(-2, -2);
		pDockTarget->ScreenToClient(rcHint);

		int Width;
		CRect rcDockDrag = pDockDrag->GetWindowRect();
		CRect rcDockTarget = pDockTarget->GetDockClient().GetWindowRect();
		if ((uDockSide  == DS_DOCKED_LEFT) || (uDockSide  == DS_DOCKED_RIGHT))
		{
			Width = rcDockDrag.Width();
			if (Width >= (rcDockTarget.Width() - pDockDrag->GetBarWidth()))
				Width = MAX(rcDockTarget.Width()/2 - pDockDrag->GetBarWidth(), pDockDrag->GetBarWidth());
		}
		else
		{
			Width = rcDockDrag.Height();
			if (Width >= (rcDockTarget.Height() - pDockDrag->GetBarWidth()))
				Width = MAX(rcDockTarget.Height()/2 - pDockDrag->GetBarWidth(), pDockDrag->GetBarWidth());
		}
		switch (uDockSide)
		{
		case DS_DOCKED_LEFT:
			rcHint.right = rcHint.left + Width;
			break;
		case DS_DOCKED_RIGHT:
			rcHint.left = rcHint.right - Width;
			break;
		case DS_DOCKED_TOP:
			rcHint.bottom = rcHint.top + Width;
			break;
		case DS_DOCKED_BOTTOM:
			rcHint.top = rcHint.bottom - Width;
			break;
		}

		return rcHint;
	}

	inline RECT CDocker::CDockHint::CalcHintRectOuter(CDocker* pDockDrag, UINT uDockSide)
	{
		// Calculate the hint window's position for outer docking
		CDocker* pDockTarget = pDockDrag->GetDockAncestor();
		CRect rcHint = pDockTarget->GetClientRect();
		if (pDockTarget->GetDockClient().GetWindowLongPtr(GWL_EXSTYLE) & WS_EX_CLIENTEDGE)
			rcHint.InflateRect(-2, -2);

		int Width;
		CRect rcDockDrag = pDockDrag->GetWindowRect();
		CRect rcDockTarget = pDockTarget->GetDockClient().GetWindowRect();

		// Limit the docked size to half the parent's size if it won't fit inside parent
		if ((uDockSide == DS_DOCKED_LEFTMOST) || (uDockSide  == DS_DOCKED_RIGHTMOST))
		{
			Width = rcDockDrag.Width();
			int BarWidth = pDockDrag->GetBarWidth();
			if (Width >= pDockTarget->GetDockClient().GetClientRect().Width() - pDockDrag->GetBarWidth())
				Width = MAX(pDockTarget->GetDockClient().GetClientRect().Width()/2 - BarWidth, BarWidth);
		}
		else
		{
			Width = rcDockDrag.Height();
			int BarWidth = pDockDrag->GetBarWidth();
			if (Width >= pDockTarget->GetDockClient().GetClientRect().Height() - pDockDrag->GetBarWidth())
				Width = MAX(pDockTarget->GetDockClient().GetClientRect().Height()/2 - BarWidth, BarWidth);
		}
		switch (uDockSide)
		{
		case DS_DOCKED_LEFTMOST:
			rcHint.right = rcHint.left + Width;
			break;
		case DS_DOCKED_RIGHTMOST:
			rcHint.left = rcHint.right - Width;
			break;
		case DS_DOCKED_TOPMOST:
			rcHint.bottom = rcHint.top + Width;
			break;
		case DS_DOCKED_BOTTOMMOST:
			rcHint.top = rcHint.bottom - Width;
			break;
		}

		return rcHint;
	}

	inline void CDocker::CDockHint::DisplayHint(CDocker* pDockTarget, CDocker* pDockDrag, UINT uDockSide)
	{
		// Ensure a new hint window is created if dock side changes
		if (uDockSide != m_uDockSideOld)
		{
			Destroy();
			pDockTarget->RedrawWindow( NULL, NULL, RDW_NOERASE | RDW_UPDATENOW );
			pDockDrag->RedrawWindow();
		}
		m_uDockSideOld = uDockSide;

		if (!IsWindow())
		{
			CRect rcHint;

			if (uDockSide & 0xF)
				rcHint = CalcHintRectInner(pDockTarget, pDockDrag, uDockSide);
			else if (uDockSide & 0xF0000)
				rcHint = CalcHintRectOuter(pDockDrag, uDockSide);
			else if (uDockSide & DS_DOCKED_CONTAINER)
				rcHint = CalcHintRectContainer(pDockTarget);
			else
				return;

			ShowHintWindow(pDockTarget, rcHint);
		}
	}

	inline void CDocker::CDockHint::OnDraw(CDC* pDC)
	{
		// Display the blue tinted bitmap
		CRect rc = GetClientRect();
		CMemDC MemDC(pDC);
		MemDC.SelectObject(&m_bmBlueTint);
		pDC->BitBlt(0, 0, rc.Width(), rc.Height(), &MemDC, 0, 0, SRCCOPY);
	}

	inline void CDocker::CDockHint::PreCreate(CREATESTRUCT &cs)
	{
		cs.style = WS_POPUP;

		// WS_EX_TOOLWINDOW prevents the window being displayed on the taskbar
		cs.dwExStyle = WS_EX_TOOLWINDOW;

		cs.lpszClass = _T("Win32++ DockHint");
	}

	inline void CDocker::CDockHint::ShowHintWindow(CDocker* pDockTarget, CRect rcHint)
	{
		// Save the Dock window's blue tinted bitmap
		CClientDC dcDesktop(NULL);
		CMemDC dcMem(&dcDesktop);
		CRect rcBitmap = rcHint;
		CRect rcTarget = rcHint;
		pDockTarget->ClientToScreen(rcTarget);

		m_bmBlueTint.CreateCompatibleBitmap(&dcDesktop, rcBitmap.Width(), rcBitmap.Height());
		CBitmap* pOldBitmap = dcMem.SelectObject(&m_bmBlueTint);
		dcMem.BitBlt(0, 0, rcBitmap.Width(), rcBitmap.Height(), &dcDesktop, rcTarget.left, rcTarget.top, SRCCOPY);
		dcMem.SelectObject(pOldBitmap); 
		TintBitmap(&m_bmBlueTint, -64, -24, +128);

		// Create the Hint window
		if (!IsWindow())
		{
			Create(pDockTarget);
		}

		pDockTarget->ClientToScreen(rcHint);
		SetWindowPos(NULL, rcHint, SWP_SHOWWINDOW|SWP_NOZORDER|SWP_NOACTIVATE);
	}


	////////////////////////////////////////////////////////////////
	// Definitions for the CTargetCentre class nested within CDocker
	//
	inline CDocker::CTargetCentre::CTargetCentre() : m_bIsOverContainer(FALSE), m_pOldDockTarget(0)
	{
	}

	inline CDocker::CTargetCentre::~CTargetCentre()
	{
	}

	inline void CDocker::CTargetCentre::OnDraw(CDC* pDC)
	{
		CBitmap bmCentre(IDW_SDCENTER);
		CBitmap bmLeft(IDW_SDLEFT);
		CBitmap bmRight(IDW_SDRIGHT);
		CBitmap bmTop(IDW_SDTOP);
		CBitmap bmBottom(IDW_SDBOTTOM);

		if (bmCentre.GetHandle())	pDC->DrawBitmap(0, 0, 88, 88, bmCentre, RGB(255,0,255));
		else TRACE(_T("Missing docking resource: Target Centre\n"));

		if (bmLeft.GetHandle()) pDC->DrawBitmap(0, 29, 31, 29, bmLeft, RGB(255,0,255));
		else TRACE(_T("Missing docking resource: Target Left\n"));

		if (bmTop.GetHandle()) pDC->DrawBitmap(29, 0, 29, 31, bmTop, RGB(255,0,255));
		else TRACE(_T("Missing docking resource: Target Top\n"));

		if (bmRight.GetHandle()) pDC->DrawBitmap(55, 29, 31, 29, bmRight, RGB(255,0,255));
		else TRACE(_T("Missing docking resource: Target Right\n"));

		if (bmBottom.GetHandle()) pDC->DrawBitmap(29, 55, 29, 31, bmBottom, RGB(255,0,255));
		else TRACE(_T("Missing docking resource: Target Bottom\n"));

		if (IsOverContainer())
		{
			CBitmap bmMiddle(IDW_SDMIDDLE);
			pDC->DrawBitmap(31, 31, 25, 26, bmMiddle, RGB(255,0,255));
		}
	}

	inline void CDocker::CTargetCentre::OnCreate()
	{
		// Use a region to create an irregularly shapped window
		POINT ptArray[16] = { {0,29}, {22, 29}, {29, 22}, {29, 0},
		                      {58, 0}, {58, 22}, {64, 29}, {87, 29},
		                      {87, 58}, {64, 58}, {58, 64}, {58, 87},
		                      {29, 87}, {29, 64}, {23, 58}, {0, 58} };

		CRgn rgnPoly;
		rgnPoly.CreatePolygonRgn(ptArray, 16, WINDING);
		SetWindowRgn(&rgnPoly, FALSE);
	}

	inline BOOL CDocker::CTargetCentre::CheckTarget(LPDRAGPOS pDragPos)
	{
		CDocker* pDockDrag = (CDocker*)FromHandle(pDragPos->hdr.hwndFrom);
		if (NULL == pDockDrag) return FALSE;

		CDocker* pDockTarget = pDockDrag->GetDockFromPoint(pDragPos->ptPos);
		if (NULL == pDockTarget) return FALSE;

		if (!IsWindow())	Create();
		m_bIsOverContainer = (dynamic_cast<CDockContainer*>(pDockTarget->GetView()) != NULL);

		// Redraw the target if the dock target changes
		if (m_pOldDockTarget != pDockTarget)	Invalidate();
		m_pOldDockTarget = pDockTarget;

		int cxImage = 88;
		int cyImage = 88;

		CRect rcTarget = pDockTarget->GetDockClient().GetWindowRect();
		int xMid = rcTarget.left + (rcTarget.Width() - cxImage)/2;
		int yMid = rcTarget.top + (rcTarget.Height() - cyImage)/2;
		SetWindowPos(HWND_TOPMOST, xMid, yMid, cxImage, cyImage, SWP_NOACTIVATE|SWP_SHOWWINDOW);

		// Create the docking zone rectangles
		CPoint pt = pDragPos->ptPos;
		ScreenToClient(pt);
		CRect rcLeft(0, 29, 31, 58);
		CRect rcTop(29, 0, 58, 31);
		CRect rcRight(55, 29, 87, 58);
		CRect rcBottom(29, 55, 58, 87);
		CRect rcMiddle(31, 31, 56, 57);

		// Test if our cursor is in one of the docking zones
		if ((rcLeft.PtInRect(pt)) && !(pDockTarget->GetDockStyle() & DS_NO_DOCKCHILD_LEFT))
		{
			pDockDrag->m_BlockMove = TRUE;
			pDockTarget->GetDockHint().DisplayHint(pDockTarget, pDockDrag, DS_DOCKED_LEFT);
			pDockDrag->m_dwDockZone = DS_DOCKED_LEFT;
			return TRUE;
		}
		else if ((rcTop.PtInRect(pt)) && !(pDockTarget->GetDockStyle() & DS_NO_DOCKCHILD_TOP))
		{
			pDockDrag->m_BlockMove = TRUE;
			pDockTarget->GetDockHint().DisplayHint(pDockTarget, pDockDrag, DS_DOCKED_TOP);
			pDockDrag->m_dwDockZone = DS_DOCKED_TOP;
			return TRUE;
		}
		else if ((rcRight.PtInRect(pt)) && !(pDockTarget->GetDockStyle() & DS_NO_DOCKCHILD_RIGHT))
		{
			pDockDrag->m_BlockMove = TRUE;
			pDockTarget->GetDockHint().DisplayHint(pDockTarget, pDockDrag, DS_DOCKED_RIGHT);
			pDockDrag->m_dwDockZone = DS_DOCKED_RIGHT;
			return TRUE;
		}
		else if ((rcBottom.PtInRect(pt)) && !(pDockTarget->GetDockStyle() & DS_NO_DOCKCHILD_BOTTOM))
		{
			pDockDrag->m_BlockMove = TRUE;
			pDockTarget->GetDockHint().DisplayHint(pDockTarget, pDockDrag, DS_DOCKED_BOTTOM);
			pDockDrag->m_dwDockZone = DS_DOCKED_BOTTOM;
			return TRUE;
		}
		else if ((rcMiddle.PtInRect(pt)) && (IsOverContainer()))
		{
			pDockDrag->m_BlockMove = TRUE;
			pDockTarget->GetDockHint().DisplayHint(pDockTarget, pDockDrag, DS_DOCKED_CONTAINER);
			pDockDrag->m_dwDockZone = DS_DOCKED_CONTAINER;
			return TRUE;
		}
		else
			return FALSE;
	}

	////////////////////////////////////////////////////////////////
	// Definitions for the CTarget class nested within CDocker
	// CTarget is the base class for a number of CTargetXXX classes
	inline CDocker::CTarget::~CTarget()
	{
	}

	inline void CDocker::CTarget::OnDraw(CDC* pDC)
	{
		BITMAP bm = m_bmImage.GetBitmapData();
		int cxImage = bm.bmWidth;
		int cyImage = bm.bmHeight;

		if (m_bmImage) 
			pDC->DrawBitmap(0, 0, cxImage, cyImage, m_bmImage, RGB(255,0,255));
		else 
			TRACE(_T("Missing docking resource\n"));
	}

	inline void CDocker::CTarget::PreCreate(CREATESTRUCT &cs)
	{
		cs.style = WS_POPUP;
		cs.dwExStyle = WS_EX_TOPMOST|WS_EX_TOOLWINDOW;
		cs.lpszClass = _T("Win32++ DockTargeting");
	}


	////////////////////////////////////////////////////////////////
	// Definitions for the CTargetLeft class nested within CDocker
	//
	inline BOOL CDocker::CTargetLeft::CheckTarget(LPDRAGPOS pDragPos)
	{
		CDocker* pDockDrag = (CDocker*)FromHandle(pDragPos->hdr.hwndFrom);
		if (NULL == pDockDrag) return FALSE;

		CPoint pt = pDragPos->ptPos;
		CDocker* pDockTarget = pDockDrag->GetDockFromPoint(pt)->GetTopmostDocker();
		if (pDockTarget != pDockDrag->GetDockAncestor())
		{
			Destroy();
			return FALSE;
		}

		BITMAP bm = m_bmImage.GetBitmapData();
		int cxImage = bm.bmWidth;
		int cyImage = bm.bmHeight;

		if (!IsWindow())
		{
			Create();
			CRect rc = pDockTarget->GetWindowRect();
			int yMid = rc.top + (rc.Height() - cyImage)/2;
			SetWindowPos(HWND_TOPMOST, rc.left + 10, yMid, cxImage, cyImage, SWP_NOACTIVATE|SWP_SHOWWINDOW);
		}

		CRect rcLeft(0, 0, cxImage, cyImage);
		ScreenToClient(pt);

		// Test if our cursor is in one of the docking zones
		if ((rcLeft.PtInRect(pt)) && !(pDockTarget->GetDockStyle() & DS_NO_DOCKCHILD_LEFT))
		{
			pDockDrag->m_BlockMove = TRUE;
			pDockTarget->GetDockHint().DisplayHint(pDockTarget, pDockDrag, DS_DOCKED_LEFTMOST);
			pDockDrag->m_dwDockZone = DS_DOCKED_LEFTMOST;
			return TRUE;
		}

		return FALSE;
	}


	////////////////////////////////////////////////////////////////
	// Definitions for the CTargetTop class nested within CDocker
	//
	inline BOOL CDocker::CTargetTop::CheckTarget(LPDRAGPOS pDragPos)
	{
		CDocker* pDockDrag = (CDocker*)FromHandle(pDragPos->hdr.hwndFrom);
		if (NULL == pDockDrag) return FALSE;

		CPoint pt = pDragPos->ptPos;
		CDocker* pDockTarget = pDockDrag->GetDockFromPoint(pt)->GetTopmostDocker();
		if (pDockTarget != pDockDrag->GetDockAncestor())
		{
			Destroy();
			return FALSE;
		}

		BITMAP bm = m_bmImage.GetBitmapData();
		int cxImage = bm.bmWidth;
		int cyImage = bm.bmHeight;

		if (!IsWindow())
		{
			Create();
			CRect rc = pDockTarget->GetWindowRect();
			int xMid = rc.left + (rc.Width() - cxImage)/2;
			SetWindowPos(HWND_TOPMOST, xMid, rc.top + 10, cxImage, cyImage, SWP_NOACTIVATE|SWP_SHOWWINDOW);
		}

		CRect rcTop(0, 0, cxImage, cyImage);
		ScreenToClient(pt);

		// Test if our cursor is in one of the docking zones
		if ((rcTop.PtInRect(pt)) && !(pDockTarget->GetDockStyle() & DS_NO_DOCKCHILD_TOP))
		{
			pDockDrag->m_BlockMove = TRUE;
			pDockTarget->GetDockHint().DisplayHint(pDockTarget, pDockDrag, DS_DOCKED_TOPMOST);
			pDockDrag->m_dwDockZone = DS_DOCKED_TOPMOST;
			return TRUE;
		}

		return FALSE;
	}


	////////////////////////////////////////////////////////////////
	// Definitions for the CTargetRight class nested within CDocker
	//
	inline BOOL CDocker::CTargetRight::CheckTarget(LPDRAGPOS pDragPos)
	{
		CDocker* pDockDrag = (CDocker*)FromHandle(pDragPos->hdr.hwndFrom);
		if (NULL == pDockDrag) return FALSE;

		CPoint pt = pDragPos->ptPos;
		CDocker* pDockTarget = pDockDrag->GetDockFromPoint(pt)->GetTopmostDocker();
		if (pDockTarget != pDockDrag->GetDockAncestor())
		{
			Destroy();
			return FALSE;
		}

		BITMAP bm = m_bmImage.GetBitmapData();
		int cxImage = bm.bmWidth;
		int cyImage = bm.bmHeight;

		if (!IsWindow())
		{
			Create();
			CRect rc = pDockTarget->GetWindowRect();
			int yMid = rc.top + (rc.Height() - cyImage)/2;
			SetWindowPos(HWND_TOPMOST, rc.right - 10 - cxImage, yMid, cxImage, cyImage, SWP_NOACTIVATE|SWP_SHOWWINDOW);
		}

		CRect rcRight(0, 0, cxImage, cyImage);
		ScreenToClient(pt);

		// Test if our cursor is in one of the docking zones
		if ((rcRight.PtInRect(pt)) && !(pDockTarget->GetDockStyle() & DS_NO_DOCKCHILD_RIGHT))
		{
			pDockDrag->m_BlockMove = TRUE;
			pDockTarget->GetDockHint().DisplayHint(pDockTarget, pDockDrag, DS_DOCKED_RIGHTMOST);
			pDockDrag->m_dwDockZone = DS_DOCKED_RIGHTMOST;
			return TRUE;
		}

		return FALSE;
	}


	////////////////////////////////////////////////////////////////
	// Definitions for the CTargetBottom class nested within CDocker
	//
	inline BOOL CDocker::CTargetBottom::CheckTarget(LPDRAGPOS pDragPos)
	{
		CDocker* pDockDrag = (CDocker*)FromHandle(pDragPos->hdr.hwndFrom);
		if (NULL == pDockDrag) return FALSE;

		CPoint pt = pDragPos->ptPos;
		CDocker* pDockTarget = pDockDrag->GetDockFromPoint(pt)->GetTopmostDocker();
		if (pDockTarget != pDockDrag->GetDockAncestor())
		{
			Destroy();
			return FALSE;
		}

		BITMAP bm = m_bmImage.GetBitmapData();
		int cxImage = bm.bmWidth;
		int cyImage = bm.bmHeight;

		if (!IsWindow())
		{
			Create();
			CRect rc = pDockTarget->GetWindowRect();
			int xMid = rc.left + (rc.Width() - cxImage)/2;
			SetWindowPos(HWND_TOPMOST, xMid, rc.bottom - 10 - cyImage, cxImage, cyImage, SWP_NOACTIVATE|SWP_SHOWWINDOW);
		}
		CRect rcBottom(0, 0, cxImage, cyImage);
		ScreenToClient(pt);

		// Test if our cursor is in one of the docking zones
		if ((rcBottom.PtInRect(pt)) && !(pDockTarget->GetDockStyle() & DS_NO_DOCKCHILD_BOTTOM))
		{
			pDockDrag->m_BlockMove = TRUE;
			pDockTarget->GetDockHint().DisplayHint(pDockTarget, pDockDrag, DS_DOCKED_BOTTOMMOST);
			pDockDrag->m_dwDockZone = DS_DOCKED_BOTTOMMOST;
			return TRUE;
		}

		return FALSE;
	}


	/////////////////////////////////////////
	// Definitions for the CDocker class
	//
	inline CDocker::CDocker() : m_pDockParent(NULL), m_pDockActive(NULL), m_BlockMove(FALSE), m_Undocking(FALSE),
		            m_bIsClosing(FALSE), m_bIsDragging(FALSE), m_bDragAutoResize(TRUE), m_DockStartSize(0), m_nDockID(0),
		            m_nTimerCount(0), m_NCHeight(0), m_dwDockZone(0), m_DockSizeRatio(1.0), m_DockStyle(0), m_hOldFocus(0)
	{
		// Assume this docker is the DockAncestor for now.
		m_pDockAncestor = this;
	}

	inline CDocker::~CDocker()
	{
		GetDockBar().Destroy();

		std::vector <DockPtr>::iterator iter;
		if (GetDockAncestor() == this)
		{
			// Destroy all dock descendants of this dock ancestor
			for (iter = GetAllDockers().begin(); iter < GetAllDockers().end(); ++iter)
			{
				(*iter)->Destroy();
			}
		}
	}

	inline CDocker* CDocker::AddDockedChild(CDocker* pDocker, DWORD dwDockStyle, int DockSize, int nDockID /* = 0*/)
	// This function creates the docker, and adds it to the docker heirachy as docked
	{
		// Create the docker window as a child of the frame window.
		// This pernamently sets the frame window as the docker window's owner,
		// even when its parent is subsequently changed.

		assert(pDocker);

		// Store the Docker's pointer in the DockAncestor's vector for later deletion
		GetDockAncestor()->m_vAllDockers.push_back(DockPtr(pDocker));

		pDocker->SetDockStyle(dwDockStyle);
		pDocker->m_nDockID = nDockID;
		pDocker->m_pDockAncestor = GetDockAncestor();
		pDocker->m_pDockParent = this;
		pDocker->SetDockSize(DockSize);
		CWnd* pFrame = GetDockAncestor()->GetAncestor();
		pDocker->Create(pFrame);
		pDocker->SetParent(this);

		// Dock the docker window
		if (dwDockStyle & DS_DOCKED_CONTAINER)
			DockInContainer(pDocker, dwDockStyle);
		else
			Dock(pDocker, dwDockStyle);

		// Issue TRACE warnings for any missing resources
		HMODULE hMod= GetApp()->GetResourceHandle();

		if (!(dwDockStyle & DS_NO_RESIZE))
		{
			if (!FindResource(hMod, MAKEINTRESOURCE(IDW_SPLITH), RT_GROUP_CURSOR))
				TRACE(_T("**WARNING** Horizontal cursor resource missing\n"));
			if (!FindResource(hMod, MAKEINTRESOURCE(IDW_SPLITV), RT_GROUP_CURSOR))
				TRACE(_T("**WARNING** Vertical cursor resource missing\n"));
		}

		if (!(dwDockStyle & DS_NO_UNDOCK))
		{
			if (!FindResource(hMod, MAKEINTRESOURCE(IDW_SDCENTER), RT_BITMAP))
				TRACE(_T("**WARNING** Docking center bitmap resource missing\n"));
			if (!FindResource(hMod, MAKEINTRESOURCE(IDW_SDLEFT), RT_BITMAP))
				TRACE(_T("**WARNING** Docking left bitmap resource missing\n"));
			if (!FindResource(hMod, MAKEINTRESOURCE(IDW_SDRIGHT), RT_BITMAP))
				TRACE(_T("**WARNING** Docking right bitmap resource missing\n"));
			if (!FindResource(hMod, MAKEINTRESOURCE(IDW_SDTOP), RT_BITMAP))
				TRACE(_T("**WARNING** Docking top bitmap resource missing\n"));
			if (!FindResource(hMod, MAKEINTRESOURCE(IDW_SDBOTTOM), RT_BITMAP))
				TRACE(_T("**WARNING** Docking center bottom resource missing\n"));
		}

		if (dwDockStyle & DS_DOCKED_CONTAINER)
		{
			if (!FindResource(hMod, MAKEINTRESOURCE(IDW_SDMIDDLE), RT_BITMAP))
				TRACE(_T("**WARNING** Docking container bitmap resource missing\n"));
		}

		return pDocker;
	}

	inline CDocker* CDocker::AddUndockedChild(CDocker* pDocker, DWORD dwDockStyle, int DockSize, RECT rc, int nDockID /* = 0*/)
	// This function creates the docker, and adds it to the docker heirachy as undocked
	{
		assert(pDocker);

		// Store the Docker's pointer in the DockAncestor's vector for later deletion
		GetDockAncestor()->m_vAllDockers.push_back(DockPtr(pDocker));

		pDocker->SetDockSize(DockSize);
		pDocker->SetDockStyle(dwDockStyle & 0XFFFFFF0);
		pDocker->m_nDockID = nDockID;
		pDocker->m_pDockAncestor = GetDockAncestor();

		// Initially create the as a child window of the frame
		// This makes the frame window the owner of our docker
		CWnd* pFrame = GetDockAncestor()->GetAncestor();
		pDocker->Create(pFrame);
		pDocker->SetParent(this);

		// Change the Docker to a POPUP window
		DWORD dwStyle = WS_POPUP| WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_VISIBLE;
		pDocker->SetWindowLongPtr(GWL_STYLE, dwStyle);
		pDocker->SetRedraw(FALSE);
		pDocker->SetParent(0);
		pDocker->SetWindowPos(HWND_TOP, rc, SWP_SHOWWINDOW|SWP_FRAMECHANGED);
		pDocker->SetRedraw(TRUE);
		pDocker->RedrawWindow(0, 0, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE|RDW_ALLCHILDREN);
		pDocker->SetWindowText(pDocker->GetCaption().c_str());

		return pDocker;
	}

	inline void CDocker::CheckAllTargets(LPDRAGPOS pDragPos)
	// Calls CheckTarget for each possible target zone
	{
		if (!GetDockAncestor()->m_TargetCentre.CheckTarget(pDragPos))
		{
			if (!GetDockAncestor()->m_TargetLeft.CheckTarget(pDragPos))
			{
				if(!GetDockAncestor()->m_TargetTop.CheckTarget(pDragPos))
				{
					if(!GetDockAncestor()->m_TargetRight.CheckTarget(pDragPos))
					{
						if(!GetDockAncestor()->m_TargetBottom.CheckTarget(pDragPos))
						{
							// Not in a docking zone, so clean up
							NMHDR nmhdr = pDragPos->hdr;
							CDocker* pDockDrag = (CDocker*)FromHandle(nmhdr.hwndFrom);
							if (pDockDrag)
							{
								if (pDockDrag->m_BlockMove)
									pDockDrag->RedrawWindow(0, 0, RDW_FRAME|RDW_INVALIDATE);

								GetDockHint().Destroy();
								pDockDrag->m_dwDockZone = 0;
								pDockDrag->m_BlockMove = FALSE;
							}
						}
					}
				}
			}
		}
	}

	inline BOOL CDocker::VerifyDockers()
	// A diagnostic routine which verifies the integrity of the docking layout
	{
		BOOL bResult = TRUE;

		// Check dock ancestor
		std::vector<DockPtr>::iterator iter;

		for (iter = GetAllDockers().begin(); iter != GetAllDockers().end(); ++iter)
		{
			if (GetDockAncestor() != (*iter)->m_pDockAncestor)
			{
				TRACE(_T("Invalid Dock Ancestor\n"));
				bResult = FALSE;
			}
		}

		// Check presence of dock parent
		for (iter = GetAllDockers().begin(); iter != GetAllDockers().end(); ++iter)
		{
			if ((*iter)->IsUndocked() && (*iter)->m_pDockParent != 0)
			{
				TRACE(_T("Error: Undocked dockers should not have a dock parent\n"));
					bResult = FALSE;
			}

			if ((*iter)->IsDocked() && (*iter)->m_pDockParent == 0)
			{
				TRACE(_T("Error: Docked dockers should have a dock parent\n"));
					bResult = FALSE;
			}
		}

		// Check dock parent/child relationship
		for (iter = GetAllDockers().begin(); iter != GetAllDockers().end(); ++iter)
		{
			std::vector<CDocker*>::iterator iterChild;
			for (iterChild = (*iter)->GetDockChildren().begin(); iterChild != (*iter)->GetDockChildren().end(); ++iterChild)
			{
				if ((*iterChild)->m_pDockParent != (*iter).get())
				{
					TRACE(_T("Error: Docking parent/Child information mismatch\n"));
					bResult = FALSE;
				}
				if ((*iterChild)->GetParent() != (*iter).get())
				{
					TRACE(_T("Error: Incorrect windows child parent relationship\n"));
					bResult = FALSE;
				}
			}
		}

		// Check dock parent chain
		for (iter = GetAllDockers().begin(); iter != GetAllDockers().end(); ++iter)
		{
			CDocker* pDockTopLevel = (*iter)->GetTopmostDocker();
			if (pDockTopLevel->IsDocked())
				TRACE(_T("Error: Top level parent should be undocked\n"));
		}

		return bResult;
	}

	inline void CDocker::Close()
	{
		// Destroy the docker
		Hide();
		Destroy();
	}

	inline void CDocker::CloseAllDockers()
	{
		assert(this == GetDockAncestor());	// Must call CloseAllDockers from the DockAncestor

		std::vector <DockPtr>::iterator v;

		SetRedraw(FALSE);
		std::vector<DockPtr> AllDockers = GetAllDockers();
		for (v = AllDockers.begin(); v != AllDockers.end(); ++v)
		{
			// The CDocker is destroyed when the window is destroyed
			(*v)->m_bIsClosing = TRUE;
			(*v)->Destroy();	// Destroy the window
		}

		GetDockChildren().clear();
		SetRedraw(TRUE);
		RecalcDockLayout();
	}

	inline void CDocker::CloseAllTargets()
	{
		GetDockAncestor()->m_TargetCentre.Destroy();
		GetDockAncestor()->m_TargetLeft.Destroy();
		GetDockAncestor()->m_TargetTop.Destroy();
		GetDockAncestor()->m_TargetRight.Destroy();
		GetDockAncestor()->m_TargetBottom.Destroy();
	}

	inline void CDocker::Dock(CDocker* pDocker, UINT DockStyle)
	// Docks the specified docker inside this docker
	{
		assert(pDocker);

		pDocker->m_pDockParent = this;
		pDocker->m_BlockMove = FALSE;
		pDocker->SetDockStyle(DockStyle);
		m_vDockChildren.push_back(pDocker);
		pDocker->ConvertToChild(m_hWnd);

		// Limit the docked size to half the parent's size if it won't fit inside parent
		if (((DockStyle & 0xF)  == DS_DOCKED_LEFT) || ((DockStyle &0xF)  == DS_DOCKED_RIGHT))
		{
			int Width = GetDockClient().GetWindowRect().Width();
			int BarWidth = pDocker->GetBarWidth();
			if (pDocker->m_DockStartSize >= (Width - BarWidth))
				pDocker->SetDockSize(MAX(Width/2 - BarWidth, BarWidth));

			pDocker->m_DockSizeRatio = ((double)pDocker->m_DockStartSize) / (double)GetWindowRect().Width();
		}
		else
		{
			int Height = GetDockClient().GetWindowRect().Height();
			int BarWidth = pDocker->GetBarWidth();
			if (pDocker->m_DockStartSize >= (Height - BarWidth))
				pDocker->SetDockSize(MAX(Height/2 - BarWidth, BarWidth));

			pDocker->m_DockSizeRatio = ((double)pDocker->m_DockStartSize) / (double)GetWindowRect().Height();
		}

		// Redraw the docked windows
		GetAncestor()->SetForegroundWindow();
		GetTopmostDocker()->m_hOldFocus = pDocker->GetView()->GetHwnd();
		pDocker->GetView()->SetFocus();

		GetTopmostDocker()->SetRedraw(FALSE);
		RecalcDockLayout();
		GetTopmostDocker()->SetRedraw(TRUE);
		GetTopmostDocker()->RedrawWindow();
	}

	inline void CDocker::DockInContainer(CDocker* pDock, DWORD dwDockStyle)
	// Add a container to an existing container
	{
		if ((dwDockStyle & DS_DOCKED_CONTAINER) && (dynamic_cast<CDockContainer*>(pDock->GetView())))
		{
			// Transfer any dock children to this docker
			pDock->MoveDockChildren(this);

			// Transfer container children to the target container
			CDockContainer* pContainer = (CDockContainer*)GetView();
			CDockContainer* pContainerSource = (CDockContainer*)pDock->GetView();

			if (pContainerSource->GetAllContainers().size() > 1)
			{
				// The container we're about to add has children, so transfer those first
				std::vector<ContainerInfo>::reverse_iterator riter;
				std::vector<ContainerInfo> AllContainers = pContainerSource->GetAllContainers();
				for ( riter = AllContainers.rbegin() ; riter < AllContainers.rend() -1; ++riter )
				{
					// Remove child container from pContainerSource
					CDockContainer* pContainerChild = (*riter).pContainer;
					pContainerChild->ShowWindow(SW_HIDE);
					pContainerSource->RemoveContainer(pContainerChild);

					// Add child container to this container
					pContainer->AddContainer(pContainerChild);

					CDocker* pDockChild = GetDockFromView(pContainerChild);
					pDockChild->SetParent(this);
					pDockChild->m_pDockParent = this;
				}
			}

			pContainer->AddContainer((CDockContainer*)pDock->GetView());
			pDock->m_pDockParent = this;
			pDock->m_BlockMove = FALSE;
			pDock->ShowWindow(SW_HIDE);
			pDock->SetWindowLongPtr(GWL_STYLE, WS_CHILD);
			pDock->SetDockStyle(dwDockStyle);
			pDock->SetParent(this);
		}
	}

	inline void CDocker::DockOuter(CDocker* pDocker, DWORD dwDockStyle)
	// Docks the specified docker inside the dock ancestor
	{
		assert(pDocker);

		pDocker->m_pDockParent = GetDockAncestor();

		DWORD OuterDocking = dwDockStyle & 0xF0000;
		DWORD DockSide = OuterDocking / 0x10000;
		dwDockStyle &= 0xFFF0FFFF;
		dwDockStyle |= DockSide;

		// Set the dock styles
		DWORD dwStyle = WS_CHILD | WS_VISIBLE;
		pDocker->m_BlockMove = FALSE;
		pDocker->SetWindowLongPtr(GWL_STYLE, dwStyle);
		pDocker->ShowWindow(SW_HIDE);
		pDocker->SetDockStyle(dwDockStyle);

		// Set the docking relationships
		std::vector<CDocker*>::iterator iter = GetDockAncestor()->m_vDockChildren.begin();
		GetDockAncestor()->m_vDockChildren.insert(iter, pDocker);
		pDocker->SetParent(GetDockAncestor());
		pDocker->GetDockBar().SetParent(GetDockAncestor());

		// Limit the docked size to half the parent's size if it won't fit inside parent
		if (((dwDockStyle & 0xF)  == DS_DOCKED_LEFT) || ((dwDockStyle &0xF)  == DS_DOCKED_RIGHT))
		{
			int Width = GetDockAncestor()->GetDockClient().GetWindowRect().Width();
			int BarWidth = pDocker->GetBarWidth();
			if (pDocker->m_DockStartSize >= (Width - BarWidth))
				pDocker->SetDockSize(MAX(Width/2 - BarWidth, BarWidth));

			pDocker->m_DockSizeRatio = ((double)pDocker->m_DockStartSize) / (double)GetDockAncestor()->GetWindowRect().Width();
		}
		else
		{
			int Height = GetDockAncestor()->GetDockClient().GetWindowRect().Height();
			int BarWidth = pDocker->GetBarWidth();
			if (pDocker->m_DockStartSize >= (Height - BarWidth))
				pDocker->SetDockSize(MAX(Height/2 - BarWidth, BarWidth));

			pDocker->m_DockSizeRatio = ((double)pDocker->m_DockStartSize) / (double)GetDockAncestor()->GetWindowRect().Height();
		}

		// Redraw the docked windows
		GetAncestor()->SetFocus();
		pDocker->GetView()->SetFocus();
		RecalcDockLayout();
	}

	inline void CDocker::DrawAllCaptions()
	{
		std::vector<DockPtr>::iterator iter;
		for (iter = GetAllDockers().begin(); iter != GetAllDockers().end(); iter++)
		{
			if ((*iter)->IsDocked())
				(*iter)->GetDockClient().DrawCaption((WPARAM)1);
		}
	}

	inline void CDocker::DrawHashBar(HWND hBar, POINT Pos)
	// Draws a hashed bar while the splitter bar is being dragged
	{
		CDocker* pDock = ((CDockBar*)FromHandle(hBar))->GetDock();
		if (NULL == pDock) return;

		BOOL bVertical = ((pDock->GetDockStyle() & 0xF) == DS_DOCKED_LEFT) || ((pDock->GetDockStyle() & 0xF) == DS_DOCKED_RIGHT);

		CClientDC dcBar(this);

		WORD HashPattern[] = {0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA};
		CBitmap bmHash;
		CBrush brDithered;
		bmHash.CreateBitmap(8, 8, 1, 1, HashPattern);
		brDithered.CreatePatternBrush(&bmHash);
		dcBar.SelectObject(&brDithered);

		CRect rc = FromHandle(hBar)->GetWindowRect();
		ScreenToClient(rc);
		int cx = rc.Width();
		int cy = rc.Height();
		int BarWidth = pDock->GetDockBar().GetWidth();

		if (bVertical)
			dcBar.PatBlt(Pos.x - BarWidth/2, rc.top, BarWidth, cy, PATINVERT);
		else
			dcBar.PatBlt(rc.left, Pos.y - BarWidth/2, cx, BarWidth, PATINVERT);
	}
	
	inline CDockContainer* CDocker::GetContainer() const
	{
		CDockContainer* pContainer = NULL;
		if (dynamic_cast<CDockContainer*>(GetView()))
			pContainer = (CDockContainer*)GetView();

		return pContainer;
	}

	inline CDocker* CDocker::GetActiveDocker() const
	// Returns the docker whose child window has focus
	{
		CWnd* pWnd = GetFocus();
		CDocker* pDock= NULL;
		while (pWnd && (pDock == NULL))
		{
			if (IsRelated(pWnd))
				pDock = (CDocker*)pWnd;

			pWnd = pWnd->GetParent();
		}

		return pDock;
	}

	inline CDocker* CDocker::GetDockAncestor() const
	// The GetDockAncestor function retrieves the pointer to the
	//  ancestor (root docker parent) of the Docker.
	{
		return m_pDockAncestor;
	}

	inline CDocker* CDocker::GetDockFromPoint(POINT pt) const
	// Retrieves the Docker whose view window contains the specified point
	{
		// Step 1: Find the top level Docker the point is over
		CDocker* pDockTop = NULL;
		CWnd* pAncestor = GetDockAncestor()->GetAncestor();

		// Iterate through all top level windows
		CWnd* pWnd = GetWindow(GW_HWNDFIRST);
		while(pWnd)
		{
			if (IsRelated(pWnd) || pWnd == pAncestor)
			{
				CDocker* pDockTest;
				if (pWnd == pAncestor)
					pDockTest = GetDockAncestor();
				else
					pDockTest = (CDocker*)pWnd;

				CRect rc = pDockTest->GetClientRect();
				pDockTest->ClientToScreen(rc);
				if ((this != pDockTest) && rc.PtInRect(pt))
				{
					pDockTop = pDockTest;
					break;
				}
			}

			pWnd = pWnd->GetWindow(GW_HWNDNEXT);
		}

		// Step 2: Find the docker child whose view window has the point
		CDocker* pDockTarget = NULL;
		if (pDockTop)
		{
			CDocker* pDockParent = pDockTop;
			CDocker* pDockTest = pDockParent;

			while (IsRelated(pDockTest))
			{
				pDockParent = pDockTest;
				CPoint ptLocal = pt;
				pDockParent->ScreenToClient(ptLocal);
				pDockTest = (CDocker*)pDockParent->ChildWindowFromPoint(ptLocal);
				assert (pDockTest != pDockParent);
			}

			CRect rc = pDockParent->GetDockClient().GetWindowRect();
			if (rc.PtInRect(pt)) pDockTarget = pDockParent;
		}

		return pDockTarget;
	}

	inline CDocker* CDocker::GetDockFromID(int n_DockID) const
	{
		std::vector <DockPtr>::iterator v;

		if (GetDockAncestor())
		{
			for (v = GetDockAncestor()->m_vAllDockers.begin(); v != GetDockAncestor()->m_vAllDockers.end(); v++)
			{
				if (n_DockID == (*v)->GetDockID())
					return (*v).get();
			}
		}

		return 0;
	}

	inline CDocker* CDocker::GetDockFromView(CWnd* pView) const
	{
		CDocker* pDock = 0;
		std::vector<DockPtr>::iterator iter;
		std::vector<DockPtr> AllDockers = GetAllDockers();
		for (iter = AllDockers.begin(); iter != AllDockers.end(); ++iter)
		{
			if ((*iter)->GetView() == pView)
				pDock = (*iter).get();
		}

		return pDock;
	}

	inline int CDocker::GetDockSize() const
	{
		// Returns the size of the docker to be used if it is redocked
		// Note: This function returns 0 if the docker has the DS_DOCKED_CONTAINER style

		CRect rcParent;
		if (GetDockParent())
			rcParent = GetDockParent()->GetWindowRect();
		else
			rcParent = GetDockAncestor()->GetWindowRect();

		double DockSize = 0;
		if ((GetDockStyle() & DS_DOCKED_LEFT) || (GetDockStyle() & DS_DOCKED_RIGHT))
			DockSize = (double)(rcParent.Width()*m_DockSizeRatio);
		else if ((GetDockStyle() & DS_DOCKED_TOP) || (GetDockStyle() & DS_DOCKED_BOTTOM))
			DockSize = (double)(rcParent.Height()*m_DockSizeRatio);
		else if ((GetDockStyle() & DS_DOCKED_CONTAINER))
			DockSize = 0;

		return (int)DockSize;
	}

	inline CDocker* CDocker::GetTopmostDocker() const
	// Returns the docker's parent at the top of the Z order.
	// Could be the dock ancestor or an undocked docker.
	{
		CDocker* pDockTopLevel = (CDocker* const)this;

		while(pDockTopLevel->GetDockParent())
		{
			assert (pDockTopLevel != pDockTopLevel->GetDockParent());
			pDockTopLevel = pDockTopLevel->GetDockParent();
		}

		return pDockTopLevel;
	}

	inline CTabbedMDI* CDocker::GetTabbedMDI() const
	{
		CTabbedMDI* pTabbedMDI = NULL;
		if (dynamic_cast<CTabbedMDI*>(GetView()))
			pTabbedMDI = (CTabbedMDI*)GetView();

		return pTabbedMDI;
	}

	inline int CDocker::GetTextHeight()
	{
		NONCLIENTMETRICS nm = {0};
		nm.cbSize = GetSizeofNonClientMetrics();
		SystemParametersInfo (SPI_GETNONCLIENTMETRICS, 0, &nm, 0);
		LOGFONT lf = nm.lfStatusFont;

		CClientDC dc(this);
		dc.CreateFontIndirect(&lf);
		CSize szText = dc.GetTextExtentPoint32(_T("Text"), lstrlen(_T("Text")));
		return szText.cy;
	}

	inline void CDocker::Hide()
	{
		// Undocks a docker (if needed) and hides it.
		// Do unhide the docker, dock it.

		if (IsDocked())
		{
			if (dynamic_cast<CDockContainer*>(GetView()))
			{
				CDockContainer* pContainer = GetContainer();
				CDocker* pDock = GetDockFromView(pContainer->GetContainerParent());
				pDock->UndockContainer(pContainer, GetCursorPos(), FALSE);
			}
			else
			{
				CDocker* pDockUndockedFrom = SeparateFromDock();
				pDockUndockedFrom->RecalcDockLayout();
			}
		}

		ShowWindow(SW_HIDE);
	}

	inline BOOL CDocker::IsChildOfDocker(CWnd* pWnd) const
	// returns true if the specified window is a child of this docker
	{
		while ((pWnd != NULL) && (pWnd != GetDockAncestor()))
		{
			if (pWnd == (CWnd*)this) return TRUE;
			if (IsRelated(pWnd)) break;
			pWnd = pWnd->GetParent();
		}

		return FALSE;
	}

	inline BOOL CDocker::IsDocked() const
	{
		return (((m_DockStyle&0xF) || (m_DockStyle & DS_DOCKED_CONTAINER)) && !m_Undocking); // Boolean expression
	}

	inline BOOL CDocker::IsDragAutoResize()
	{
		return m_bDragAutoResize;
	}

	inline BOOL CDocker::IsRelated(CWnd* pWnd) const
	// Returns TRUE if the hWnd is a docker within this dock family
	{
		if (GetDockAncestor() == pWnd) return TRUE;

		std::vector<DockPtr>::iterator iter;
		for (iter = GetAllDockers().begin(); iter < GetAllDockers().end(); ++iter)
		{
			if ((*iter).get() == pWnd) return TRUE;
		}

		return FALSE;
	}

	inline BOOL CDocker::IsUndocked() const
	{
		return (!((m_DockStyle&0xF)|| (m_DockStyle & DS_DOCKED_CONTAINER)) && !m_Undocking); // Boolean expression
	}

	inline BOOL CDocker::LoadRegistrySettings(tString tsRegistryKeyName)
	// Recreates the docker layout based on information stored in the registry.
	// Assumes the DockAncestor window is already created.
	{
		BOOL bResult = FALSE;

		if (0 != tsRegistryKeyName.size())
		{
			std::vector<DockInfo> vDockList;
			std::vector<int> vActiveContainers;
			tString tsKey = _T("Software\\") + tsRegistryKeyName + _T("\\Dock Windows");
			HKEY hKey = 0;
			RegOpenKeyEx(HKEY_CURRENT_USER, tsKey.c_str(), 0, KEY_READ, &hKey);
			if (hKey)
			{
				DWORD dwType = REG_BINARY;
				DWORD BufferSize = sizeof(DockInfo);
				DockInfo di;
				int i = 0;
				TCHAR szNumber[20];
				tString tsSubKey = _T("DockChild");
				tsSubKey += _itot(i, szNumber, 10);

				// Fill the DockList vector from the registry
				while (0 == RegQueryValueEx(hKey, tsSubKey.c_str(), NULL, &dwType, (LPBYTE)&di, &BufferSize))
				{
					vDockList.push_back(di);
					i++;
					tsSubKey = _T("DockChild");
					tsSubKey += _itot(i, szNumber, 10);
				}

				dwType = REG_DWORD;
				BufferSize = sizeof(int);
				int nID;
				i = 0;
				tsSubKey = _T("ActiveContainer");
				tsSubKey += _itot(i, szNumber, 10);
				// Fill the DockList vector from the registry
				while (0 == RegQueryValueEx(hKey, tsSubKey.c_str(), NULL, &dwType, (LPBYTE)&nID, &BufferSize))
				{
					vActiveContainers.push_back(nID);
					i++;
					tsSubKey = _T("ActiveContainer");
					tsSubKey += _itot(i, szNumber, 10);
				}

				RegCloseKey(hKey);
				if (vDockList.size() > 0) bResult = TRUE;
			}

			// Add dockers without parents first
			std::vector<DockInfo>::iterator iter;
			for (iter = vDockList.begin(); iter < vDockList.end() ; ++iter)
			{
				DockInfo di = (*iter);
				if (di.DockParentID == 0)
				{
					CDocker* pDocker = NewDockerFromID(di.DockID);
					if (pDocker)
					{
						if (di.DockStyle & 0xF)
							AddDockedChild(pDocker, di.DockStyle, di.DockSize, di.DockID);
						else
							AddUndockedChild(pDocker, di.DockStyle, di.DockSize, di.Rect, di.DockID);
					}
					else
					{
						TRACE(_T("Failed to add dockers without parents from registry"));
						bResult = FALSE;
					}
				}
			}

			// Remove dockers without parents from vDockList
			for (UINT n = (UINT)vDockList.size(); n > 0; --n)
			{
				iter = vDockList.begin() + n-1;
				if ((*iter).DockParentID == 0)
					vDockList.erase(iter);
			}

			// Add remaining dockers
			while (vDockList.size() > 0)
			{
				bool bFound = false;
				std::vector<DockInfo>::iterator iter;
				for (iter = vDockList.begin(); iter < vDockList.end(); ++iter)
				{
					DockInfo di = *iter;
					CDocker* pDockParent = GetDockFromID(di.DockParentID);

					if (pDockParent != 0)
					{
						CDocker* pDock = NewDockerFromID(di.DockID);
						if(pDock)
						{
							pDockParent->AddDockedChild(pDock, di.DockStyle, di.DockSize, di.DockID);
							bFound = true;
						}
						else
						{
							TRACE(_T("Failed to add dockers with parents from registry"));
							bResult = FALSE;
						}

						vDockList.erase(iter);
						break;
					}
				}

				if (!bFound)
				{
					TRACE(_T("Orphaned dockers stored in registry "));
					bResult = FALSE;
					break;
				}
			}

			std::vector<int>::iterator iterID;
			for (iterID = vActiveContainers.begin(); iterID < vActiveContainers.end(); ++iterID)
			{
				CDocker* pDocker = GetDockFromID(*iterID);
				if (pDocker)
				{
					CDockContainer* pContainer = pDocker->GetContainer();
					if (pContainer)
					{
						int nPage = pContainer->GetContainerIndex(pContainer);
						if (nPage >= 0)
							pContainer->SelectPage(nPage);
					}
				}
			}
		}

		if (!bResult) CloseAllDockers();
		return bResult;
	}

	inline void CDocker::MoveDockChildren(CDocker* pDockTarget)
	// Used internally by Dock and Undock
	{
		assert(pDockTarget);

		// Transfer any dock children from the current docker to the target docker
		std::vector<CDocker*>::iterator iter;
		for (iter = GetDockChildren().begin(); iter < GetDockChildren().end(); ++iter)
		{
			pDockTarget->GetDockChildren().push_back(*iter);
			(*iter)->m_pDockParent = pDockTarget;
			(*iter)->SetParent(pDockTarget);
			(*iter)->GetDockBar().SetParent(pDockTarget);
		}
		GetDockChildren().clear();
	}

	inline CDocker* CDocker::NewDockerFromID(int nID)
	// Used in LoadRegistrySettings. Creates a new Docker from the specified ID
	{
		UNREFERENCED_PARAMETER(nID);

		// Override this function to create the Docker objects as shown below

		CDocker* pDock = NULL;
	/*	switch(nID)
		{
		case ID_CLASSES:
			pDock = new CDockClasses;
			break;
		case ID_FILES:
			pDock = new CDockFiles;
			break;
		default:
			TRACE(_T("Unknown Dock ID\n"));
			break;
		} */

		return pDock;
	}

	inline void CDocker::OnActivate(WPARAM wParam, LPARAM lParam)
	{
		UNREFERENCED_PARAMETER(lParam);

		// Only top level undocked dockers get this message
		if (LOWORD(wParam) == WA_INACTIVE)
		{
			GetTopmostDocker()->m_hOldFocus = ::GetFocus();

			// Send a notification of focus lost
			int idCtrl = ::GetDlgCtrlID(m_hOldFocus);
			NMHDR nhdr={0};
			nhdr.hwndFrom = m_hOldFocus;
			nhdr.idFrom = idCtrl;
			nhdr.code = UWM_FRAMELOSTFOCUS;
			SendMessage(WM_NOTIFY, (WPARAM)idCtrl, (LPARAM)&nhdr);
		}
	}

	inline void CDocker::OnCaptionTimer(WPARAM wParam, LPARAM lParam)
	{
		UNREFERENCED_PARAMETER(lParam);

		if (this == GetDockAncestor())
		{
			if (wParam == 1)
			{
				DrawAllCaptions();
				m_nTimerCount++;
				if (m_nTimerCount == 10)
				{
					KillTimer(wParam);
					m_nTimerCount = 0;
				}
			}
		}
	}

	inline void CDocker::OnCreate()
	{

#if defined(WINVER) && defined (WS_EX_LAYOUTRTL) && (WINVER >= 0x0500)
		if (GetParent()->GetWindowLongPtr(GWL_EXSTYLE) & WS_EX_LAYOUTRTL)
		{
			DWORD dwExStyle = GetWindowLongPtr(GWL_EXSTYLE);
			SetWindowLongPtr(GWL_EXSTYLE, dwExStyle | WS_EX_LAYOUTRTL);
		}
#endif

		// Create the various child windows
		GetDockClient().SetDock(this);
		GetDockClient().Create(this);

		assert(GetView());			// Use SetView in CMainFrame's constructor to set the view window
		GetView()->Create(&GetDockClient());

		// Create the slider bar belonging to this docker
		GetDockBar().SetDock(this);
		if (GetDockAncestor() != this)
			GetDockBar().Create(GetParent());

		// Now remove the WS_POPUP style. It was required to allow this window
		// to be owned by the frame window.
		SetWindowLongPtr(GWL_STYLE, WS_CHILD);
		SetParent(GetParent());		// Reinstate the window's parent

		// Set the default colour for the splitter bar
		COLORREF rgbColour = GetSysColor(COLOR_BTNFACE);
		CWnd* pFrame = GetDockAncestor()->GetAncestor();
		ReBarTheme* pTheme = (ReBarTheme*)pFrame->SendMessage(UWM_GETREBARTHEME, 0, 0);

		if (pTheme && pTheme->UseThemes && pTheme->clrBkgnd2 != 0)
				rgbColour =pTheme->clrBkgnd2;

		SetBarColor(rgbColour);

		// Set the caption height based on text height
		m_NCHeight = MAX(20, GetTextHeight() + 5);
	}

	inline void CDocker::OnDestroy(WPARAM wParam, LPARAM lParam)
	{
		UNREFERENCED_PARAMETER(wParam);
		UNREFERENCED_PARAMETER(lParam);

		// Destroy any dock children first
		std::vector<CDocker*>::iterator iter;
		for (iter = GetDockChildren().begin(); iter < GetDockChildren().end(); ++iter)
		{
			(*iter)->Destroy();
		}

		if (dynamic_cast<CDockContainer*>(GetView()) && IsUndocked())
		{
			CDockContainer* pContainer = (CDockContainer*)GetView();
			if (pContainer->GetAllContainers().size() > 1)
			{
				// This container has children, so destroy them now
				std::vector<ContainerInfo> AllContainers = pContainer->GetAllContainers();
				std::vector<ContainerInfo>::iterator iter;
				for (iter = AllContainers.begin(); iter < AllContainers.end(); ++iter)
				{
					if ((*iter).pContainer != pContainer)
					{
						// Reset container parent before destroying the dock window
						CDocker* pDock = GetDockFromView((*iter).pContainer);
						if (pContainer->IsWindow())
							pContainer->SetParent(&pDock->GetDockClient());

						pDock->Destroy();
					}
				}
			}
		}

		GetDockBar().Destroy();

		// Post a destroy docker message
		if ( GetDockAncestor()->IsWindow() )
			GetDockAncestor()->PostMessage(UWM_DOCK_DESTROYED, (WPARAM)this, 0L);
	}

	inline void CDocker::OnDockDestroyed(WPARAM wParam, LPARAM lParam)
	{
		UNREFERENCED_PARAMETER(lParam);

		CDocker* pDock = (CDocker*)wParam;

		assert( this == GetDockAncestor() );
		std::vector<DockPtr>::iterator iter;
		for (iter = GetAllDockers().begin(); iter < GetAllDockers().end(); ++iter)
		{
			if ((*iter).get() == pDock)
			{
				GetAllDockers().erase(iter);
				break;
			}
		}
	}

	inline void CDocker::OnExitSizeMove(WPARAM wParam, LPARAM lParam)
	{
		UNREFERENCED_PARAMETER(wParam);
		UNREFERENCED_PARAMETER(lParam);

		m_BlockMove = FALSE;
		m_bIsDragging = FALSE;
		SendNotify(UWM_DOCK_END);
	}

	inline LRESULT CDocker::OnNotify(WPARAM wParam, LPARAM lParam)
	{
		UNREFERENCED_PARAMETER(wParam);
		LPDRAGPOS pdp = (LPDRAGPOS)lParam;

		switch (((LPNMHDR)lParam)->code)
		{
		case UWM_DOCK_START:
			{
				if (IsDocked())
				{
					Undock(GetCursorPos());
					SendMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(pdp->ptPos.x, pdp->ptPos.y));
				}
			}
			break;

		case UWM_DOCK_MOVE:
			{
				CheckAllTargets((LPDRAGPOS)lParam);
			}
			break;

		case UWM_DOCK_END:
			{
				CDocker* pDock = (CDocker*)FromHandle(pdp->hdr.hwndFrom);
				if (NULL == pDock) break;

				UINT DockZone = pdp->DockZone;
				CRect rc = pDock->GetWindowRect();

				switch(DockZone)
				{
				case DS_DOCKED_LEFT:
				case DS_DOCKED_RIGHT:
					pDock->SetDockSize(rc.Width());
					Dock(pDock, pDock->GetDockStyle() | DockZone);
					break;
				case DS_DOCKED_TOP:
				case DS_DOCKED_BOTTOM:
					pDock->SetDockSize(rc.Height());
					Dock(pDock, pDock->GetDockStyle() | DockZone);
					break;
				case DS_DOCKED_CONTAINER:
					{
						DockInContainer(pDock, pDock->GetDockStyle() | DockZone);
						CDockContainer* pContainer = (CDockContainer*)GetView();
						int nPage = pContainer->GetContainerIndex((CDockContainer*)pDock->GetView());
						pContainer->SelectPage(nPage);
					}
					break;
				case DS_DOCKED_LEFTMOST:
				case DS_DOCKED_RIGHTMOST:
					pDock->SetDockSize(rc.Width());
					DockOuter(pDock, pDock->GetDockStyle() | DockZone);
					break;
				case DS_DOCKED_TOPMOST:
				case DS_DOCKED_BOTTOMMOST:
					pDock->SetDockSize(rc.Height());
					DockOuter(pDock, pDock->GetDockStyle() | DockZone);
					break;
				}

				GetDockHint().Destroy();
				CloseAllTargets();
			}
			break;

		case UWM_BAR_START:
			{
				CPoint pt = pdp->ptPos;
				ScreenToClient(pt);
				if (!IsDragAutoResize())
					DrawHashBar(pdp->hdr.hwndFrom, pt);
				m_OldPoint = pt;
			}
			break;

		case UWM_BAR_MOVE:
			{
				CPoint pt = pdp->ptPos;
				ScreenToClient(pt);

				if (pt != m_OldPoint)
				{
					if (IsDragAutoResize())
						ResizeDockers(pdp);
					else
					{
						DrawHashBar(pdp->hdr.hwndFrom, m_OldPoint);
						DrawHashBar(pdp->hdr.hwndFrom, pt);
					}

					m_OldPoint = pt;
				}
			}
			break;

		case UWM_BAR_END:
			{
				POINT pt = pdp->ptPos;
				ScreenToClient(pt);

				if (!IsDragAutoResize())
					DrawHashBar(pdp->hdr.hwndFrom, pt);

				ResizeDockers(pdp);
			}
			break;
		case NM_SETFOCUS:
			if (GetDockAncestor()->IsWindow())
				GetDockAncestor()->PostMessage(UWM_DOCK_ACTIVATED, 0, 0);
			break;
		case UWM_FRAMEGOTFOCUS:
			if (GetDockAncestor()->IsWindow())
				GetDockAncestor()->PostMessage(UWM_DOCK_ACTIVATED, 0, 0);
			if (GetView()->IsWindow())
				GetView()->SendMessage(WM_NOTIFY, wParam, lParam);
			break;
		case UWM_FRAMELOSTFOCUS:
			if (GetDockAncestor()->IsWindow())
				GetDockAncestor()->PostMessage(UWM_DOCK_ACTIVATED, 0, 0);
			if (GetView()->IsWindow())
				GetView()->SendMessage(WM_NOTIFY, wParam, lParam);
			break;
		}
		return 0L;
	}

	inline void CDocker::ResizeDockers(LPDRAGPOS pdp)
	// Called when the docker's splitter bar is dragged
	{
		assert(pdp);

		POINT pt = pdp->ptPos;
		ScreenToClient(pt);

		CDocker* pDock = ((CDockBar*)FromHandle(pdp->hdr.hwndFrom))->GetDock();
		if (NULL == pDock) return;

		RECT rcDock = pDock->GetWindowRect();
		ScreenToClient(rcDock);

		double dBarWidth = pDock->GetDockBar().GetWidth();
		int iBarWidth    = pDock->GetDockBar().GetWidth();
		int DockSize;

		switch (pDock->GetDockStyle() & 0xF)
		{
		case DS_DOCKED_LEFT:
			DockSize = MAX(pt.x, iBarWidth/2) - rcDock.left - (int)(.5* dBarWidth);
			DockSize = MAX(-iBarWidth, DockSize);
			pDock->SetDockSize(DockSize);
			pDock->m_DockSizeRatio = ((double)pDock->m_DockStartSize)/((double)pDock->m_pDockParent->GetWindowRect().Width());
			break;
		case DS_DOCKED_RIGHT:
			DockSize = rcDock.right - MAX(pt.x, iBarWidth/2) - (int)(.5* dBarWidth);
			DockSize = MAX(-iBarWidth, DockSize);
			pDock->SetDockSize(DockSize);
			pDock->m_DockSizeRatio = ((double)pDock->m_DockStartSize)/((double)pDock->m_pDockParent->GetWindowRect().Width());
			break;
		case DS_DOCKED_TOP:
			DockSize = MAX(pt.y, iBarWidth/2) - rcDock.top - (int)(.5* dBarWidth);
			DockSize = MAX(-iBarWidth, DockSize);
			pDock->SetDockSize(DockSize);
			pDock->m_DockSizeRatio = ((double)pDock->m_DockStartSize)/((double)pDock->m_pDockParent->GetWindowRect().Height());
			break;
		case DS_DOCKED_BOTTOM:
			DockSize = rcDock.bottom - MAX(pt.y, iBarWidth/2) - (int)(.5* dBarWidth);
			DockSize = MAX(-iBarWidth, DockSize);
			pDock->SetDockSize(DockSize);
			pDock->m_DockSizeRatio = ((double)pDock->m_DockStartSize)/((double)pDock->m_pDockParent->GetWindowRect().Height());
			break;
		}

		RecalcDockLayout();
	}

	inline void CDocker::OnSetFocus(WPARAM wParam, LPARAM lParam)
	{
		UNREFERENCED_PARAMETER(wParam);
		UNREFERENCED_PARAMETER(lParam);

		if (IsUndocked() && m_hOldFocus)
			::SetFocus(m_hOldFocus);
		else
			// Pass focus on the the view window
			GetView()->SetFocus();

		if ((this == GetTopmostDocker()) && (this != GetDockAncestor()))
		{
			// Send a notification to top level window
			int idCtrl = ::GetDlgCtrlID(m_hOldFocus);
			NMHDR nhdr={0};
			nhdr.hwndFrom = m_hOldFocus;
			nhdr.idFrom = idCtrl;
			nhdr.code = NM_SETFOCUS;
			SendMessage(WM_NOTIFY, (WPARAM)idCtrl, (LPARAM)&nhdr);
		}
	}

	inline void CDocker::OnSysColorChange(WPARAM wParam, LPARAM lParam)
	{
		UNREFERENCED_PARAMETER(wParam);
		UNREFERENCED_PARAMETER(lParam);

		if (this == GetDockAncestor())
		{
			COLORREF rgbColour = GetSysColor(COLOR_BTNFACE);
			CWnd* pFrame = GetDockAncestor()->GetAncestor();
			ReBarTheme* pTheme = (ReBarTheme*)pFrame->SendMessage(UWM_GETREBARTHEME, 0, 0);

			if (pTheme && pTheme->UseThemes && pTheme->clrBand2 != 0)
				rgbColour = pTheme->clrBkgnd2;
			else
				rgbColour = GetSysColor(COLOR_BTNFACE);

			// Set the splitter bar colour for each docker decendant
			std::vector<DockPtr>::iterator iter;
			for (iter = GetAllDockers().begin(); iter < GetAllDockers().end(); ++iter)
				(*iter)->SetBarColor(rgbColour);

			// Set the splitter bar colour for the docker ancestor
			SetBarColor(rgbColour);
		}
	}

	inline LRESULT CDocker::OnSysCommand(WPARAM wParam, LPARAM lParam)
	{
		switch(wParam&0xFFF0)
		{
		case SC_MOVE:
			// An undocked docker is being moved
			{
				BOOL bResult = FALSE;
				m_bIsDragging = TRUE;
				SetCursor(LoadCursor(NULL, IDC_ARROW));

				if (SystemParametersInfo(SPI_GETDRAGFULLWINDOWS, 0, &bResult, 0))
				{
					// Turn on DragFullWindows for this move
					SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, TRUE, 0, 0);

					// Process this message
					DefWindowProc(WM_SYSCOMMAND, wParam, lParam);

					// Return DragFullWindows to its previous state
					SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, bResult, 0, 0);
					return 0L;
				}
			}
			break;
		case SC_CLOSE:
			// The close button is pressed on an undocked docker
			m_bIsClosing = TRUE;
			break;
		}
		return CWnd::WndProcDefault(WM_SYSCOMMAND, wParam, lParam);
	}

	inline LRESULT CDocker::OnWindowPosChanging(WPARAM wParam, LPARAM lParam)
	{
		// Suspend dock drag moving while over dock zone
		if (m_BlockMove)
		{
        	LPWINDOWPOS pWndPos = (LPWINDOWPOS)lParam;
			pWndPos->flags |= SWP_NOMOVE|SWP_FRAMECHANGED;
			return 0;
		}

		return CWnd::WndProcDefault(WM_WINDOWPOSCHANGING, wParam, lParam);
	}

	inline void CDocker::OnWindowPosChanged(WPARAM wParam, LPARAM lParam)
	{
		UNREFERENCED_PARAMETER(wParam);

		if (m_bIsDragging)
		{
			// Send a Move notification to the parent
			if ( IsLeftButtonDown() )
			{
				LPWINDOWPOS wPos = (LPWINDOWPOS)lParam;
				if ((!(wPos->flags & SWP_NOMOVE)) || m_BlockMove)
					SendNotify(UWM_DOCK_MOVE);
			}
			else
			{
				CloseAllTargets();
				m_BlockMove = FALSE;
			}
		}
		else if (this == GetTopmostDocker())
		{
			// Reposition the dock children
			if (IsUndocked() && IsWindowVisible() && !m_bIsClosing) RecalcDockLayout();
		}
	}

	inline void CDocker::PreCreate(CREATESTRUCT &cs)
	{
		// Specify the WS_POPUP style to have this window owned
		if (this != GetDockAncestor())
			cs.style = WS_POPUP;

		cs.dwExStyle = WS_EX_TOOLWINDOW;
	}

	inline void CDocker::PreRegisterClass(WNDCLASS &wc)
	{
		wc.lpszClassName = _T("Win32++ Docker");
		wc.hCursor = ::LoadCursor(NULL, IDC_ARROW);
	}

	inline void CDocker::RecalcDockChildLayout(CRect rc)
	{
		// This function positions the Docker's dock children, the Dockers client area
		//  and draws the dockbar bars.

		// Notes:
		// 1) This function is called recursively.
		// 2) The client area and child dockers are positioned simultaneously with
		//      DeferWindowPos to avoid drawing errors in complex docker arrangements.
		// 3) The docker's client area contains the docker's caption (if any) and the docker's view window.

		// Note: All top level dockers are undocked, including the dock ancestor.
		if (IsDocked())
		{
			rc.OffsetRect(-rc.left, -rc.top);
		}

		HDWP hdwp = BeginDeferWindowPos((int)m_vDockChildren.size() +2);

		// Step 1: Calculate the position of each Docker child, DockBar, and Client window.
		//   The Client area = the docker rect minus the area of dock children and the dock bar (splitter bar).
		for (UINT u = 0; u < m_vDockChildren.size(); ++u)
		{
			CRect rcChild = rc;
			double DockSize = m_vDockChildren[u]->m_DockStartSize;;

			// Calculate the size of the Docker children
			switch (m_vDockChildren[u]->GetDockStyle() & 0xF)
			{
			case DS_DOCKED_LEFT:
				if (!(GetDockStyle() & DS_FIXED_RESIZE))
					DockSize = MIN(m_vDockChildren[u]->m_DockSizeRatio*(GetWindowRect().Width()), rcChild.Width());
				rcChild.right = rcChild.left + (int)DockSize;
				break;
			case DS_DOCKED_RIGHT:
				if (!(GetDockStyle() & DS_FIXED_RESIZE))
					DockSize = MIN(m_vDockChildren[u]->m_DockSizeRatio*(GetWindowRect().Width()), rcChild.Width());
				rcChild.left = rcChild.right - (int)DockSize;
				break;
			case DS_DOCKED_TOP:
				if (!(GetDockStyle() & DS_FIXED_RESIZE))
					DockSize = MIN(m_vDockChildren[u]->m_DockSizeRatio*(GetWindowRect().Height()), rcChild.Height());
				rcChild.bottom = rcChild.top + (int)DockSize;
				break;
			case DS_DOCKED_BOTTOM:
				if (!(GetDockStyle() & DS_FIXED_RESIZE))
					DockSize = MIN(m_vDockChildren[u]->m_DockSizeRatio*(GetWindowRect().Height()), rcChild.Height());
				rcChild.top = rcChild.bottom - (int)DockSize;
				break;
			}

			if (m_vDockChildren[u]->IsDocked())
			{
				// Position this docker's children
				hdwp = m_vDockChildren[u]->DeferWindowPos(hdwp, NULL, rcChild, SWP_SHOWWINDOW|SWP_FRAMECHANGED);
				m_vDockChildren[u]->m_rcChild = rcChild;

				rc.SubtractRect(rc, rcChild);

				// Calculate the dimensions of the splitter bar
				CRect rcBar = rc;
				DWORD DockSide = m_vDockChildren[u]->GetDockStyle() & 0xF;

				if (DS_DOCKED_LEFT   == DockSide) rcBar.right  = rcBar.left + m_vDockChildren[u]->GetBarWidth();
				if (DS_DOCKED_RIGHT  == DockSide) rcBar.left   = rcBar.right - m_vDockChildren[u]->GetBarWidth();
				if (DS_DOCKED_TOP    == DockSide) rcBar.bottom = rcBar.top + m_vDockChildren[u]->GetBarWidth();
				if (DS_DOCKED_BOTTOM == DockSide) rcBar.top    = rcBar.bottom - m_vDockChildren[u]->GetBarWidth();

				// Save the splitter bar position. We will reposition it later.
				m_vDockChildren[u]->m_rcBar = rcBar;
				rc.SubtractRect(rc, rcBar);
			}
		}

		// Step 2: Position the Dock client and dock bar
		hdwp = GetDockClient().DeferWindowPos(hdwp, NULL, rc, SWP_SHOWWINDOW |SWP_FRAMECHANGED);
		EndDeferWindowPos(hdwp);

		// Position the dockbar. Only docked dockers have a dock bar.
		if (IsDocked())
		{
			// The SWP_NOCOPYBITS forces a redraw of the dock bar.
			GetDockBar().SetWindowPos(NULL, m_rcBar, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS );
		}

		// Step 3: Now recurse through the docker's children. They might have children of their own.
		for (UINT v = 0; v < m_vDockChildren.size(); ++v)
		{
			m_vDockChildren[v]->RecalcDockChildLayout(m_vDockChildren[v]->m_rcChild);
		}
	}

	inline void CDocker::RecalcDockLayout()
	// Repositions the dock children of a top level docker
	{
		if (GetDockAncestor()->IsWindow())
		{
			CRect rc = GetTopmostDocker()->GetClientRect();
			GetTopmostDocker()->RecalcDockChildLayout(rc);
			GetTopmostDocker()->UpdateWindow();
		}
	}

	inline std::vector<CDocker*> CDocker::SortDockers()
	// Returns a vector of sorted dockers, used by SaveRegistrySettings.
	{
		std::vector<CDocker*> vSorted;
		std::vector<CDocker*>::iterator itSort;
		std::vector<DockPtr>::iterator itAll;

		// Add undocked top level dockers
		for (itAll = GetAllDockers().begin(); itAll <  GetAllDockers().end(); ++itAll)
		{
			if (!(*itAll)->GetDockParent())
				vSorted.push_back((*itAll).get());
		}

		// Add dock ancestor's children
		vSorted.insert(vSorted.end(), GetDockAncestor()->GetDockChildren().begin(), GetDockAncestor()->GetDockChildren().end());

		// Add other dock children
		int index = 0;
		itSort = vSorted.begin();
		while (itSort < vSorted.end())
		{
			vSorted.insert(vSorted.end(), (*itSort)->GetDockChildren().begin(), (*itSort)->GetDockChildren().end());
			itSort = vSorted.begin() + (++index);
		}

		// Add dockers docked in containers
		std::vector<CDocker*> vDockContainers;
		for (itSort = vSorted.begin(); itSort< vSorted.end(); ++itSort)
		{
			if ((*itSort)->GetContainer())
				vDockContainers.push_back(*itSort);
		}

		for (itSort = vDockContainers.begin(); itSort < vDockContainers.end(); ++itSort)
		{
			CDockContainer* pContainer = (*itSort)->GetContainer();

			for (UINT i = 1; i < pContainer->GetAllContainers().size(); ++i)
			{
				CDockContainer* pChild = pContainer->GetContainerFromIndex(i);
				CDocker* pDock = GetDockFromView(pChild);
				vSorted.push_back(pDock);
			}
		}

		return vSorted;
	}

	inline BOOL CDocker::SaveRegistrySettings(tString tsRegistryKeyName)
	// Stores the docking configuration in the registry
	// NOTE: This function assumes that each docker has a unique DockID
	{
		assert(VerifyDockers());

		std::vector<CDocker*> vSorted = SortDockers();
		std::vector<CDocker*>::iterator iter;
		std::vector<DockInfo> vDockInfo;

		if (0 != tsRegistryKeyName.size())
		{
			// Fill the DockInfo vector with the docking information
			for (iter = vSorted.begin(); iter <  vSorted.end(); ++iter)
			{
				DockInfo di	 = {0};
				di.DockID	 = (*iter)->GetDockID();
				di.DockStyle = (*iter)->GetDockStyle();
				di.DockSize  = (*iter)->GetDockSize();
				di.Rect		 = (*iter)->GetWindowRect();
				if ((*iter)->GetDockParent())
					di.DockParentID = (*iter)->GetDockParent()->GetDockID();

				vDockInfo.push_back(di);
			}

			tString tsKeyName = _T("Software\\") + tsRegistryKeyName;
			HKEY hKey = NULL;
			HKEY hKeyDock = NULL;

			try
			{
				if (ERROR_SUCCESS != RegCreateKeyEx(HKEY_CURRENT_USER, tsKeyName.c_str(), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL))
					throw (CWinException(_T("RegCreateKeyEx Failed")));

				RegDeleteKey(hKey, _T("Dock Windows"));
				if (ERROR_SUCCESS != RegCreateKeyEx(hKey, _T("Dock Windows"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKeyDock, NULL))
					throw (CWinException(_T("RegCreateKeyEx Failed")));

				// Add the Dock windows information to the registry
				for (UINT u = 0; u < vDockInfo.size(); ++u)
				{
					DockInfo di = vDockInfo[u];
					TCHAR szNumber[16];
					tString tsSubKey = _T("DockChild");
					tsSubKey += _itot((int)u, szNumber, 10);
					if(ERROR_SUCCESS != RegSetValueEx(hKeyDock, tsSubKey.c_str(), 0, REG_BINARY, (LPBYTE)&di, sizeof(DockInfo)))
						throw (CWinException(_T("RegSetValueEx failed")));
				}

				// Add Active Container to the registry
				int i = 0;
				for (iter = vSorted.begin(); iter <  vSorted.end(); ++iter)
				{
					CDockContainer* pContainer = (*iter)->GetContainer();

					if (pContainer && (pContainer == pContainer->GetActiveContainer()))
					{
						TCHAR szNumber[20];
						tString tsSubKey = _T("ActiveContainer");
						tsSubKey += _itot(i++, szNumber, 10);
						int nID = GetDockFromView(pContainer)->GetDockID();
						if(ERROR_SUCCESS != RegSetValueEx(hKeyDock, tsSubKey.c_str(), 0, REG_DWORD, (LPBYTE)&nID, sizeof(int)))
							throw (CWinException(_T("RegSetValueEx failed")));
					}
				}

				RegCloseKey(hKeyDock);
				RegCloseKey(hKey);
			}

			catch (const CWinException& e)
			{
				// Roll back the registry changes by deleting the subkeys
				if (hKey)
				{
					if (hKeyDock)
					{
						RegDeleteKey(hKeyDock, _T("Dock Windows"));
						RegCloseKey(hKeyDock);
					}

					RegDeleteKey(HKEY_CURRENT_USER ,tsKeyName.c_str());
					RegCloseKey(hKey);
				}

				e.what();
				return FALSE;
			}
		}

		return TRUE;
	}

	inline void CDocker::SendNotify(UINT nMessageID)
	// Sends a docking notification to the docker below the cursor
	{
		DRAGPOS DragPos;
		DragPos.hdr.code = nMessageID;
		DragPos.hdr.hwndFrom = m_hWnd;
		DragPos.ptPos = GetCursorPos();
		DragPos.DockZone = m_dwDockZone;
		m_dwDockZone = 0;

		CDocker* pDock = GetDockFromPoint(DragPos.ptPos);

		if (pDock)
			pDock->SendMessage(WM_NOTIFY, 0L, (LPARAM)&DragPos);
		else
		{
			if (GetDockHint().IsWindow())		GetDockHint().Destroy();
			CloseAllTargets();
			m_BlockMove = FALSE;
		}
	}

	inline void CDocker::SetDockStyle(DWORD dwDockStyle)
	{
		if (IsWindow())
		{
			if ((dwDockStyle & DS_CLIENTEDGE) != (m_DockStyle & DS_CLIENTEDGE))
			{
				if (dwDockStyle & DS_CLIENTEDGE)
				{
					DWORD dwExStyle = (DWORD)GetDockClient().GetWindowLongPtr(GWL_EXSTYLE)|WS_EX_CLIENTEDGE;
					GetDockClient().SetWindowLongPtr(GWL_EXSTYLE, dwExStyle);
					GetDockClient().RedrawWindow(0, 0, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE|RDW_FRAME);
				}
				else
				{
					DWORD dwExStyle = (DWORD)GetDockClient().GetWindowLongPtr(GWL_EXSTYLE);
					dwExStyle &= ~WS_EX_CLIENTEDGE;
					GetDockClient().SetWindowLongPtr(GWL_EXSTYLE, dwExStyle);
					GetDockClient().RedrawWindow(0, 0, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE|RDW_FRAME);
				}
			}

			RecalcDockLayout();
		}

		m_DockStyle = dwDockStyle;
	}

	inline void CDocker::SetCaption(LPCTSTR szCaption)
	// Sets the caption text
	{
		GetDockClient().SetCaption(szCaption);

		if (IsWindow())
			SetWindowText(szCaption);
	}

	inline void CDocker::SetCaptionColors(COLORREF Foregnd1, COLORREF Backgnd1, COLORREF ForeGnd2, COLORREF BackGnd2)
	{
		GetDockClient().SetCaptionColors(Foregnd1, Backgnd1, ForeGnd2, BackGnd2);
	}

	inline void CDocker::SetCaptionHeight(int nHeight)
	// Sets the height of the caption
	{
		m_NCHeight = nHeight;
		RedrawWindow();
		RecalcDockLayout();
	}

	inline void CDocker::SetDockSize(int DockSize)
	// Sets the size of a docked docker
	{
		if (IsDocked())
		{
			assert (m_pDockParent);
			switch (GetDockStyle() & 0xF)
			{
			case DS_DOCKED_LEFT:
				m_DockStartSize = MIN(DockSize,m_pDockParent->GetWindowRect().Width());
				m_DockSizeRatio = ((double)m_DockStartSize)/((double)m_pDockParent->GetWindowRect().Width());
				break;
			case DS_DOCKED_RIGHT:
				m_DockStartSize = MIN(DockSize,m_pDockParent->GetWindowRect().Width());
				m_DockSizeRatio = ((double)m_DockStartSize)/((double)m_pDockParent->GetWindowRect().Width());
				break;
			case DS_DOCKED_TOP:
				m_DockStartSize = MIN(DockSize,m_pDockParent->GetWindowRect().Height());
				m_DockSizeRatio = ((double)m_DockStartSize)/((double)m_pDockParent->GetWindowRect().Height());
				break;
			case DS_DOCKED_BOTTOM:
				m_DockStartSize = MIN(DockSize,m_pDockParent->GetWindowRect().Height());
				m_DockSizeRatio = ((double)m_DockStartSize)/((double)m_pDockParent->GetWindowRect().Height());
				break;
			}

			RecalcDockLayout();
		}
		else
		{
			m_DockStartSize = DockSize;
			m_DockSizeRatio = 1.0;
		}
	}

	inline void CDocker::SetDragAutoResize(BOOL bAutoResize)
	{
		m_bDragAutoResize = bAutoResize;
	}

	inline void CDocker::SetView(CWnd& wndView)
	// Assigns the view window to the docker
	{
		CWnd* pWnd = &wndView;
		GetDockClient().SetView(wndView);
		if (dynamic_cast<CDockContainer*>(pWnd))
		{
			CDockContainer* pContainer = (CDockContainer*)&wndView;
			SetCaption(pContainer->GetDockCaption().c_str());
		}
	}

	inline void CDocker::PromoteFirstChild()
	// One of the steps required for undocking
	{
		// Promote our first child to replace ourself
		if (m_pDockParent)
		{
			for (UINT u = 0 ; u < m_pDockParent->m_vDockChildren.size(); ++u)
			{
				if (m_pDockParent->m_vDockChildren[u] == this)
				{
					if (m_vDockChildren.size() > 0)
						// swap our first child for ourself as a child of the parent
						m_pDockParent->m_vDockChildren[u] = m_vDockChildren[0];
					else
						// remove ourself as a child of the parent
						m_pDockParent->m_vDockChildren.erase(m_pDockParent->m_vDockChildren.begin() + u);
					break;
				}
			}
		}

		// Transfer styles and data and children to the child docker
		CDocker* pDockFirstChild = NULL;
		if (m_vDockChildren.size() > 0)
		{
			pDockFirstChild = m_vDockChildren[0];
			pDockFirstChild->m_DockStyle = (pDockFirstChild->m_DockStyle & 0xFFFFFFF0 ) | (m_DockStyle & 0xF);
			pDockFirstChild->m_DockStartSize = m_DockStartSize;
			pDockFirstChild->m_DockSizeRatio = m_DockSizeRatio;

			if (m_pDockParent)
			{
				pDockFirstChild->m_pDockParent = m_pDockParent;
				pDockFirstChild->SetParent(m_pDockParent);
				pDockFirstChild->GetDockBar().SetParent(m_pDockParent);
			}
			else
			{
				std::vector<CDocker*>::iterator iter;
				for (iter = GetDockChildren().begin() + 1; iter < GetDockChildren().end(); ++iter)
					(*iter)->ShowWindow(SW_HIDE);

				pDockFirstChild->ConvertToPopup(GetWindowRect());
				pDockFirstChild->GetDockBar().ShowWindow(SW_HIDE);
			}

			m_vDockChildren.erase(m_vDockChildren.begin());
			MoveDockChildren(pDockFirstChild);
		}
	}

	inline void CDocker::ConvertToChild(HWND hWndParent)
	{
		DWORD dwStyle = WS_CHILD | WS_VISIBLE;
		SetWindowLongPtr(GWL_STYLE, dwStyle);
		SetParent(FromHandle(hWndParent));
		GetDockBar().SetParent(FromHandle(hWndParent));
	}

	inline void CDocker::ConvertToPopup(RECT rc)
	{
		// Change the window to an "undocked" style
		ShowWindow(SW_HIDE);
		DWORD dwStyle = WS_POPUP| WS_CAPTION | WS_SYSMENU | WS_THICKFRAME;
		SetWindowLongPtr(GWL_STYLE, dwStyle);

		// Change the window's parent and reposition it
		GetDockBar().ShowWindow(SW_HIDE);
		SetWindowPos(0, 0, 0, 0, 0, SWP_NOSENDCHANGING|SWP_HIDEWINDOW|SWP_NOREDRAW);
		m_pDockParent = 0;
		SetParent(0);
		SetWindowPos(NULL, rc, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOOWNERZORDER);
		GetDockClient().SetWindowPos(NULL, GetClientRect(), SWP_SHOWWINDOW);

		SetWindowText(GetCaption().c_str());
	}

	inline CDocker* CDocker::SeparateFromDock()
	{
		// This performs some of the tasks required for undocking.
		// It is also used when a docker is hidden.
		CDocker* pDockUndockedFrom = GetDockParent();
		if (!pDockUndockedFrom && (GetDockChildren().size() > 0))
			pDockUndockedFrom = GetDockChildren()[0];

		GetTopmostDocker()->m_hOldFocus = 0;
		PromoteFirstChild();
		m_pDockParent = 0;

		GetDockBar().ShowWindow(SW_HIDE);
		m_DockStyle = m_DockStyle & 0xFFFFFFF0;
		m_DockStyle &= ~DS_DOCKED_CONTAINER;

		return pDockUndockedFrom;
	}

	inline void CDocker::SetUndockPosition(CPoint pt)
	{
		m_Undocking = TRUE;
		CRect rc;
		rc = GetDockClient().GetWindowRect();
		CRect rcTest = rc;
		rcTest.bottom = MIN(rcTest.bottom, rcTest.top + m_NCHeight);
		if ( !rcTest.PtInRect(pt))
			rc.SetRect(pt.x - rc.Width()/2, pt.y - m_NCHeight/2, pt.x + rc.Width()/2, pt.y - m_NCHeight/2 + rc.Height());

		ConvertToPopup(rc);
		m_Undocking = FALSE;

		// Send the undock notification to the frame
		NMHDR nmhdr = {0};
		nmhdr.hwndFrom = m_hWnd;
		nmhdr.code = UWM_UNDOCKED;
		nmhdr.idFrom = m_nDockID;
		CWnd* pFrame = GetDockAncestor()->GetAncestor();
		pFrame->SendMessage(WM_NOTIFY, m_nDockID, (LPARAM)&nmhdr);

		// Initiate the window move
		SetCursorPos(pt.x, pt.y);
		ScreenToClient(pt);
		PostMessage(WM_SYSCOMMAND, (WPARAM)(SC_MOVE|0x0002), MAKELPARAM(pt.x, pt.y));
	}

	inline void CDocker::Undock(CPoint pt, BOOL bShowUndocked)
	{
		// Return if we shouldn't undock
		if (GetDockStyle() & DS_NO_UNDOCK) return;

		// Undocking isn't supported on Win95
		if (1400 == GetWinVersion()) return;

		CDocker* pDockUndockedFrom = SeparateFromDock();

		// Position and draw the undocked window, unless it is about to be closed
		if (bShowUndocked)
		{
			SetUndockPosition(pt);
		}

		RecalcDockLayout();
        if ((pDockUndockedFrom) && (pDockUndockedFrom->GetTopmostDocker() != GetTopmostDocker()))
			pDockUndockedFrom->RecalcDockLayout();
	}

	inline void CDocker::UndockContainer(CDockContainer* pContainer, CPoint pt, BOOL bShowUndocked)
	{
		assert(pContainer);
		assert(this == GetDockFromView(pContainer->GetContainerParent()));

		// Return if we shouldn't undock
		if (GetDockFromView(pContainer)->GetDockStyle() & DS_NO_UNDOCK) return;

		// Undocking isn't supported on Win95
		if (1400 == GetWinVersion()) return;

		GetTopmostDocker()->m_hOldFocus = 0;
		CDocker* pDockUndockedFrom = GetDockFromView(pContainer->GetContainerParent());
		pDockUndockedFrom->ShowWindow(SW_HIDE);
		if (GetView() == pContainer)
		{
			// The parent container is being undocked, so we need
			// to transfer our child containers to a different docker

			// Choose a new docker from among the dockers for child containers
			CDocker* pDockNew = 0;
			CDocker* pDockOld = GetDockFromView(pContainer);
			std::vector<ContainerInfo> AllContainers = pContainer->GetAllContainers();
			std::vector<ContainerInfo>::iterator iter = AllContainers.begin();
			while ((0 == pDockNew) && (iter < AllContainers.end()))
			{
				if ((*iter).pContainer != pContainer)
					pDockNew = (CDocker*)FromHandle(::GetParent((*iter).pContainer->GetParent()->GetHwnd()));

				++iter;
			}

			if (pDockNew)
			{
				// Move containers from the old docker to the new docker
				CDockContainer* pContainerNew = (CDockContainer*)pDockNew->GetView();
				for (iter = AllContainers.begin(); iter != AllContainers.end(); ++iter)
				{
					if ((*iter).pContainer != pContainer)
					{
						CDockContainer* pChildContainer = (CDockContainer*)(*iter).pContainer;
						pContainer->RemoveContainer(pChildContainer);
						if (pContainerNew != pChildContainer)
						{
							pContainerNew->AddContainer(pChildContainer);
							CDocker* pDock = GetDockFromView(pChildContainer);
							pDock->SetParent(pDockNew);
							pDock->m_pDockParent = pDockNew;
						}
					}
				}

				// Now transfer the old docker's settings to the new one.
				pDockUndockedFrom = pDockNew;
				pDockNew->m_DockStyle		= pDockOld->m_DockStyle;
				pDockNew->m_DockStartSize	= pDockOld->m_DockStartSize;
				pDockNew->m_DockSizeRatio	= pDockOld->m_DockSizeRatio;
				if (pDockOld->IsDocked())
				{
					pDockNew->m_pDockParent		= pDockOld->m_pDockParent;
					pDockNew->SetParent(pDockOld->GetParent());
				}
				else
				{
					CRect rc = pDockOld->GetWindowRect();
					pDockNew->ShowWindow(SW_HIDE);
					DWORD dwStyle = WS_POPUP| WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_VISIBLE;
					pDockNew->SetWindowLongPtr(GWL_STYLE, dwStyle);
					pDockNew->m_pDockParent = 0;
					pDockNew->SetParent(0);
					pDockNew->SetWindowPos(NULL, rc, SWP_SHOWWINDOW|SWP_FRAMECHANGED| SWP_NOOWNERZORDER);
				}
				pDockNew->GetDockBar().SetParent(pDockOld->GetParent());
				pDockNew->GetView()->SetFocus();

				// Transfer the Dock children to the new docker
				pDockOld->MoveDockChildren(pDockNew);

				// insert pDockNew into its DockParent's DockChildren vector
				if (pDockNew->m_pDockParent)
				{
					std::vector<CDocker*>::iterator p;
					for (p = pDockNew->m_pDockParent->m_vDockChildren.begin(); p != pDockNew->m_pDockParent->m_vDockChildren.end(); ++p)
					{
						if (*p == this)
						{
							pDockNew->m_pDockParent->m_vDockChildren.insert(p, pDockNew);
							break;
						}
					}
				}
			}
		}
		else
		{
			// This is a child container, so simply remove it from the parent
			CDockContainer* pContainerParent = (CDockContainer*)GetView();
			pContainerParent->RemoveContainer(pContainer);
			pContainerParent->SetTabSize();
			pContainerParent->SetFocus();
			pContainerParent->GetViewPage().SetParent(pContainerParent);
		}

		// Finally do the actual undocking
		CDocker* pDock = GetDockFromView(pContainer);
		CRect rc = GetDockClient().GetWindowRect();
		ScreenToClient(rc);
		pDock->GetDockClient().SetWindowPos(NULL, rc, SWP_SHOWWINDOW);
		pDock->Undock(pt, bShowUndocked);
		pDockUndockedFrom->ShowWindow();
		pDockUndockedFrom->RecalcDockLayout();
		pDock->BringWindowToTop();
	}

	inline LRESULT CDocker::WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam)
	{
		switch (uMsg)
		{
		case WM_ACTIVATE:
			OnActivate(wParam, lParam);
			break;
		case WM_SYSCOMMAND:
			return OnSysCommand(wParam, lParam);

		case WM_EXITSIZEMOVE:
			OnExitSizeMove(wParam, lParam);
			break;
		case WM_WINDOWPOSCHANGING:
			return OnWindowPosChanging(wParam, lParam);

		case WM_WINDOWPOSCHANGED:
			OnWindowPosChanged(wParam, lParam);
			break;
		case WM_DESTROY:
			OnDestroy(wParam, lParam);
			break;
		case WM_SETFOCUS:
			OnSetFocus(wParam, lParam);
			break;
		case WM_TIMER:
			OnCaptionTimer(wParam, lParam);
			break;
		case UWM_DOCK_DESTROYED:
			OnDockDestroyed(wParam, lParam);
			break;
		case UWM_DOCK_ACTIVATED:
			DrawAllCaptions();
			SetTimer(1, 100, NULL);
			break;
		case WM_SYSCOLORCHANGE:
			OnSysColorChange(wParam, lParam);
			break;
		case WM_NCLBUTTONDBLCLK :
			m_bIsDragging = FALSE;
			break;
		}

		return CWnd::WndProcDefault(uMsg, wParam, lParam);
	}


	//////////////////////////////////////
	// Declaration of the CDockContainer class
	inline CDockContainer::CDockContainer() : m_iCurrentPage(0), m_hTabIcon(0), m_nTabPressed(-1)
	{
		m_pContainerParent = this;
	}

	inline CDockContainer::~CDockContainer()
	{
		if (m_hTabIcon)
			DestroyIcon(m_hTabIcon);
	}

	inline void CDockContainer::AddContainer(CDockContainer* pContainer)
	{
		assert(pContainer);

		if (this == m_pContainerParent)
		{
			ContainerInfo ci = {0};
			ci.pContainer = pContainer;
			lstrcpy(ci.szTitle, pContainer->GetTabText());
			ci.iImage = ImageList_AddIcon(GetImageList(), pContainer->GetTabIcon());
			int iNewPage = (int)m_vContainerInfo.size();
			m_vContainerInfo.push_back(ci);

			if (m_hWnd)
			{
				TCITEM tie = {0};
				tie.mask = TCIF_TEXT | TCIF_IMAGE;
				tie.iImage = ci.iImage;
				tie.pszText = m_vContainerInfo[iNewPage].szTitle;
				TabCtrl_InsertItem(m_hWnd, iNewPage, &tie);

				SetTabSize();
			}

			pContainer->m_pContainerParent = this;
			if (pContainer->IsWindow())
			{
				// Set the parent container relationships
				pContainer->GetViewPage().SetParent(this);
				pContainer->GetViewPage().ShowWindow(SW_HIDE);
			}
		}
	}

	inline void CDockContainer::AddToolBarButton(UINT nID, BOOL bEnabled /* = TRUE */)
	// Adds Resource IDs to toolbar buttons.
	// A resource ID of 0 is a separator
	{
		GetToolBar().AddButton(nID, bEnabled);
	}

	inline CDockContainer* CDockContainer::GetContainerFromIndex(UINT nPage)
	{
		CDockContainer* pContainer = NULL;
		if (nPage < m_vContainerInfo.size())
			pContainer = (CDockContainer*)m_vContainerInfo[nPage].pContainer;

		return pContainer;
	}

	inline CWnd* CDockContainer::GetActiveView() const
	// Returns a pointer to the active view window, or NULL if there is no active veiw.
	{
		CWnd* pWnd = NULL;
		if (m_pContainerParent->m_vContainerInfo.size() > 0)
		{
			CDockContainer* pActiveContainer = m_pContainerParent->m_vContainerInfo[m_pContainerParent->m_iCurrentPage].pContainer;
			if (pActiveContainer->GetViewPage().GetView()->IsWindow())
				pWnd = pActiveContainer->GetViewPage().GetView();
		}

		return pWnd;
	}

	inline CDockContainer* CDockContainer::GetContainerFromView(CWnd* pView) const
	{
		assert(pView);

		std::vector<ContainerInfo>::iterator iter;
		CDockContainer* pViewContainer = 0;
		for (iter = GetAllContainers().begin(); iter != GetAllContainers().end(); ++iter)
		{
			CDockContainer* pContainer = (*iter).pContainer;
			if (pContainer->GetView() == pView)
				pViewContainer = pContainer;
		}

		return pViewContainer;
	}

	inline int CDockContainer::GetContainerIndex(CDockContainer* pContainer)
	{
		assert(pContainer);
		int iReturn = -1;

		for (int i = 0; i < (int)m_pContainerParent->m_vContainerInfo.size(); ++i)
		{
			if (m_pContainerParent->m_vContainerInfo[i].pContainer == pContainer)
				iReturn = i;
		}

		return iReturn;
	}

	inline SIZE CDockContainer::GetMaxTabTextSize()
	{
		CSize Size;

		// Allocate an iterator for the ContainerInfo vector
		std::vector<ContainerInfo>::iterator iter;

		for (iter = m_vContainerInfo.begin(); iter != m_vContainerInfo.end(); ++iter)
		{
			CSize TempSize;
			CClientDC dc(this);
			NONCLIENTMETRICS info = {0};
			info.cbSize = GetSizeofNonClientMetrics();
			SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(info), &info, 0);
			dc.CreateFontIndirect(&info.lfStatusFont);
			TempSize = dc.GetTextExtentPoint32(iter->szTitle, lstrlen(iter->szTitle));
			if (TempSize.cx > Size.cx)
				Size = TempSize;
		}

		return Size;
	}

	inline void CDockContainer::SetupToolBar()
	{
		// Use this function to set the Resource IDs for the toolbar(s).

/*		// Set the Resource IDs for the toolbar buttons
		AddToolBarButton( IDM_FILE_NEW   );
		AddToolBarButton( IDM_FILE_OPEN  );
		AddToolBarButton( IDM_FILE_SAVE  );
		AddToolBarButton( 0 );				// Separator
		AddToolBarButton( IDM_EDIT_CUT   );
		AddToolBarButton( IDM_EDIT_COPY  );
		AddToolBarButton( IDM_EDIT_PASTE );
		AddToolBarButton( 0 );				// Separator
		AddToolBarButton( IDM_FILE_PRINT );
		AddToolBarButton( 0 );				// Separator
		AddToolBarButton( IDM_HELP_ABOUT );
*/
	}

	inline void CDockContainer::OnCreate()
	{
		assert(GetView());			// Use SetView in CMainFrame's constructor to set the view window

		ContainerInfo ci = {0};
		ci.pContainer = this;
		lstrcpy(ci.szTitle, GetTabText());
		ci.iImage = ImageList_AddIcon(GetImageList(), GetTabIcon());
		m_vContainerInfo.push_back(ci);

		// Create the page window
		GetViewPage().Create(this);

		// Create the toolbar
		GetToolBar().Create(&GetViewPage());
		DWORD style = (DWORD)GetToolBar().GetWindowLongPtr(GWL_STYLE);
		style |= CCS_NODIVIDER ;
		GetToolBar().SetWindowLongPtr(GWL_STYLE, style);
		SetupToolBar();
		if (GetToolBar().GetToolBarData().size() > 0)
		{
			// Set the toolbar images
			// A mask of 192,192,192 is compatible with AddBitmap (for Win95)
			if (!GetToolBar().SendMessage(TB_GETIMAGELIST,  0L, 0L))
				GetToolBar().SetImages(RGB(192,192,192), IDW_MAIN, 0, 0);

			GetToolBar().SendMessage(TB_AUTOSIZE, 0L, 0L);
		}
		else
			GetToolBar().Destroy();

		SetFixedWidth(TRUE);
		SetOwnerDraw(TRUE);

		// Add tabs for each container.
		for (int i = 0; i < (int)m_vContainerInfo.size(); ++i)
		{
			// Add tabs for each view.
			TCITEM tie = {0};
			tie.mask = TCIF_TEXT | TCIF_IMAGE;
			tie.iImage = i;
			tie.pszText = m_vContainerInfo[i].szTitle;
			TabCtrl_InsertItem(m_hWnd, i, &tie);
		}
	}

	inline void CDockContainer::OnLButtonDown(WPARAM wParam, LPARAM lParam)
	{
		// Overrides CTab::OnLButtonDown

		UNREFERENCED_PARAMETER(wParam);

		CPoint pt((DWORD)lParam);
		TCHITTESTINFO info = {0};
		info.pt = pt;
		m_nTabPressed = HitTest(info);
	}

	inline void CDockContainer::OnLButtonUp(WPARAM wParam, LPARAM lParam)
	{
		// Overrides CTab::OnLButtonUp and takes no action

		UNREFERENCED_PARAMETER(wParam);
		UNREFERENCED_PARAMETER(lParam);
	}

	inline void CDockContainer::OnMouseLeave(WPARAM wParam, LPARAM lParam)
	{
		// Overrides CTab::OnMouseLeave

		if (IsLeftButtonDown() && (m_nTabPressed >= 0))
		{
			CDocker* pDock = (CDocker*)FromHandle(::GetParent(GetParent()->GetHwnd()));
			if (dynamic_cast<CDocker*>(pDock))
			{
				CDockContainer* pContainer = GetContainerFromIndex(m_iCurrentPage);
				pDock->UndockContainer(pContainer, GetCursorPos(), TRUE);
			}
		}

		m_nTabPressed = -1;
		CTab::OnMouseLeave(wParam, lParam);
	}

	inline LRESULT CDockContainer::OnNotifyReflect(WPARAM wParam, LPARAM lParam)
	{
		UNREFERENCED_PARAMETER(wParam);

		switch (((LPNMHDR)lParam)->code)
		{
		case TCN_SELCHANGE:
			{
				// Display the newly selected tab page
				int nPage = GetCurSel();
				SelectPage(nPage);
			}
			break;
		}

		return 0L;
	}

	inline void CDockContainer::PreCreate(CREATESTRUCT &cs)
	{
		// For Tabs on the bottom, add the TCS_BOTTOM style
		CTab::PreCreate(cs);
		cs.style |= TCS_BOTTOM;
	}

	inline void CDockContainer::RecalcLayout()
	{
		if (GetContainerParent() == this)
		{
			// Set the tab sizes
			SetTabSize();

			// Position the View over the tab control's display area
			CRect rc = GetClientRect();
			AdjustRect(FALSE, &rc);
			CDockContainer* pContainer = m_vContainerInfo[m_iCurrentPage].pContainer;
			pContainer->GetViewPage().SetWindowPos(HWND_TOP, rc, SWP_SHOWWINDOW);
		}
	}

	inline void CDockContainer::RemoveContainer(CDockContainer* pWnd)
	{
		assert(pWnd);

		// Remove the tab
		int iTab = GetContainerIndex(pWnd);
		if (iTab > 0)
		{
		//	DeleteItem(iTab);
			TabCtrl_DeleteItem(m_hWnd, iTab);
		}

		// Remove the ContainerInfo entry
		std::vector<ContainerInfo>::iterator iter;
		int iImage = -1;
		for (iter = m_vContainerInfo.begin(); iter != m_vContainerInfo.end(); ++iter)
		{
			if (iter->pContainer == pWnd)
			{
				iImage = (*iter).iImage;
				if (iImage >= 0)
					TabCtrl_RemoveImage(m_hWnd, iImage);

				m_vContainerInfo.erase(iter);
				break;
			}
		}

		// Set the parent container relationships
		pWnd->GetViewPage().SetParent(pWnd);
		pWnd->m_pContainerParent = pWnd;

		// Display the first page
		m_iCurrentPage = 0;
		if (IsWindow())
			SelectPage(0);
	}

	inline void CDockContainer::SelectPage(int nPage)
	{
		if (this != m_pContainerParent)
			m_pContainerParent->SelectPage(nPage);
		else
		{
			if ((nPage >= 0) && (nPage < (int)m_vContainerInfo.size() ))
			{
				if (GetCurSel() != nPage)
					SetCurSel(nPage);

				// Create the new container window if required
				if (!m_vContainerInfo[nPage].pContainer->IsWindow())
				{
					CDockContainer* pContainer = m_vContainerInfo[nPage].pContainer;
					pContainer->Create(GetParent());
					pContainer->GetViewPage().SetParent(this);
				}

				// Determine the size of the tab page's view area
				CRect rc = GetClientRect();
				AdjustRect(FALSE, &rc);

				// Swap the pages over
				CDockContainer* pOldContainer = m_vContainerInfo[m_iCurrentPage].pContainer;
				CDockContainer* pNewContainer = m_vContainerInfo[nPage].pContainer;
				pOldContainer->GetViewPage().ShowWindow(SW_HIDE);
				pNewContainer->GetViewPage().SetWindowPos(HWND_TOP, rc, SWP_SHOWWINDOW);
				pNewContainer->GetViewPage().GetView()->SetFocus();

				// Adjust the docking caption
				CDocker* pDock = (CDocker*)FromHandle(::GetParent(::GetParent(m_hWnd)));
				if (dynamic_cast<CDocker*>(pDock))
				{
					pDock->SetCaption(pNewContainer->GetDockCaption().c_str());
					pDock->RedrawWindow();
				}

				m_iCurrentPage = nPage;
			}
		}
	}

	inline void CDockContainer::SetActiveContainer(CDockContainer* pContainer)
	{
		int nPage = GetContainerIndex(pContainer);
		assert (0 <= nPage);
		SelectPage(nPage);
	}

	inline void CDockContainer::SetTabIcon(UINT nID_Icon)
	{
		HICON hIcon = (HICON)LoadImage(GetApp()->GetResourceHandle(), MAKEINTRESOURCE(nID_Icon), IMAGE_ICON, 0, 0, LR_SHARED);
		SetTabIcon(hIcon);
	}

	inline void CDockContainer::SetTabSize()
	{
		CRect rc = GetClientRect();
		AdjustRect(FALSE, &rc);
		if (rc.Width() < 0 )
			rc.SetRectEmpty();

		int nItemWidth = MIN(25 + GetMaxTabTextSize().cx, (rc.Width()-2)/(int)m_vContainerInfo.size());
		int nItemHeight = MAX(20, GetTextHeight() + 5);
		SendMessage(TCM_SETITEMSIZE, 0L, MAKELPARAM(nItemWidth, nItemHeight));
	}

	inline void CDockContainer::SetTabText(UINT nTab, LPCTSTR szText)
	{
		CDockContainer* pContainer = GetContainerParent()->GetContainerFromIndex(nTab);
		pContainer->SetTabText(szText);

		CTab::SetTabText(nTab, szText);
	}

	inline void CDockContainer::SetView(CWnd& Wnd)
	{
		GetViewPage().SetView(Wnd);
	}

	inline LRESULT CDockContainer::WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam)
	{
		switch (uMsg)
		{
		case WM_SIZE:
			RecalcLayout();
			return 0;

	// The following are called in CTab::WndProcDefault
	//	case WM_LBUTTONDOWN:
	//		OnLButtonDown(wParam, lParam);
	//		break;
	//	case WM_LBUTTONUP:
	//		OnLButtonUp(wParam, lParam);
	//		break;
	//	case WM_MOUSELEAVE:
	//		OnMouseLeave(wParam, lParam);
	//		break;

		case WM_SETFOCUS:
			{
				// Pass focus on to the current view
				GetActiveView()->SetFocus();
			}
			break;
		}

		// pass unhandled messages on to CTab for processing
		return CTab::WndProcDefault(uMsg, wParam, lParam);
	}


	///////////////////////////////////////////
	// Declaration of the nested CViewPage class
	inline BOOL CDockContainer::CViewPage::OnCommand(WPARAM wParam, LPARAM lParam)
	{
		CDockContainer* pContainer = (CDockContainer*)GetParent();
		BOOL bResult = FALSE;
		if (pContainer && pContainer->GetActiveContainer())
			bResult = (BOOL)pContainer->GetActiveContainer()->SendMessage(WM_COMMAND, wParam, lParam);

		return bResult;
	}

	inline void CDockContainer::CViewPage::OnCreate()
	{
		if (m_pView)
			m_pView->Create(this);
	}

	inline LRESULT CDockContainer::CViewPage::OnNotify(WPARAM wParam, LPARAM lParam)
	{
		UNREFERENCED_PARAMETER(wParam);

		switch (((LPNMHDR)lParam)->code)
		{

		// Display tooltips for the toolbar
		case TTN_GETDISPINFO:
			{
				int iIndex =  GetToolBar().HitTest();
				LPNMTTDISPINFO lpDispInfo = (LPNMTTDISPINFO)lParam;
				if (iIndex >= 0)
				{
					int nID = GetToolBar().GetCommandID(iIndex);
					if (nID > 0)
					{
						m_tsTooltip = LoadString(nID);
						lpDispInfo->lpszText = (LPTSTR)m_tsTooltip.c_str();
					}
					else
						m_tsTooltip = _T("");
				}
			}
			break;
		} // switch LPNMHDR

		return 0L;
	}

	inline void CDockContainer::CViewPage::PreRegisterClass(WNDCLASS &wc)
	{
		wc.lpszClassName = _T("Win32++ TabPage");
		wc.hCursor = ::LoadCursor(NULL, IDC_ARROW);
	}

	inline void CDockContainer::CViewPage::RecalcLayout()
	{
		CRect rc = GetClientRect();
		if (GetToolBar().IsWindow())
		{
			GetToolBar().SendMessage(TB_AUTOSIZE, 0L, 0L);
			CRect rcToolBar = m_ToolBar.GetClientRect();
			rc.top += rcToolBar.Height();
		}

		GetView()->SetWindowPos(NULL, rc, SWP_SHOWWINDOW);
	}

	inline void CDockContainer::CViewPage::SetView(CWnd& wndView)
	// Sets or changes the View window displayed within the frame
	{
		// Assign the view window
		m_pView = &wndView;

		if (m_hWnd)
		{
			if (!m_pView->IsWindow())
			{
				// The container is already created, so create and position the new view too
				GetView()->Create(this);
			}

			RecalcLayout();
		}
	}

	inline LRESULT CDockContainer::CViewPage::WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam)
	{
		switch (uMsg)
		{
		case WM_SIZE:
			RecalcLayout();
			break;
		case WM_NOTIFY:
			switch (((LPNMHDR)lParam)->code)
			{
			// Send the focus change notifications to the grandparent
			case NM_KILLFOCUS:
			case NM_SETFOCUS:
			case UWM_FRAMELOSTFOCUS:
				::SendMessage(::GetParent(::GetParent(m_hWnd)), WM_NOTIFY, wParam, lParam);
				break;
			}

			break;
		}

		// pass unhandled messages on for default processing
		return CWnd::WndProcDefault(uMsg, wParam, lParam);
	}

} // namespace Win32xx

#endif // _WIN32XX_DOCKING_H_