PageRenderTime 96ms CodeModel.GetById 12ms app.highlight 73ms RepoModel.GetById 1ms app.codeStats 0ms

/Visual Studio 2008/CppWindowsCommonControls/CppWindowsCommonControls.cpp

#
C++ | 1863 lines | 1039 code | 319 blank | 505 comment | 80 complexity | a19595ca17b370ef1dfbc41b6e81a285 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/******************************** Module Header ********************************\
   2Module Name:  CppWindowsCommonControls.cpp
   3Project:      CppWindowsCommonControls
   4Copyright (c) Microsoft Corporation.
   5
   6CppWindowsCommonControls contains simple examples of how to create common 
   7controls defined in comctl32.dll. The controls include Animation, ComboBoxEx, 
   8Updown, Header, MonthCal, DateTimePick, ListView, TreeView, Tab, Tooltip, IP 
   9Address, Statusbar, Progress Bar, Toolbar, Trackbar, and SysLink.
  10
  11This source is subject to the Microsoft Public License.
  12See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
  13All other rights reserved.
  14
  15THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
  16EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
  17WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
  18\*******************************************************************************/
  19
  20#pragma region Includes and Manifest Dependencies
  21#include <stdio.h>
  22#include <windows.h>
  23#include <windowsx.h>
  24#include "Resource.h"
  25#include <assert.h>
  26
  27#include <commctrl.h>
  28#pragma comment(lib, "comctl32.lib")
  29
  30// Enable Visual Style
  31#if defined _M_IX86
  32#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
  33#elif defined _M_IA64
  34#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
  35#elif defined _M_X64
  36#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
  37#else
  38#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
  39#endif
  40#pragma endregion
  41
  42
  43HINSTANCE g_hInst;  // The handle to the instance of the current module
  44
  45
  46//
  47//   FUNCTION: OnClose(HWND)
  48//
  49//   PURPOSE: Process the WM_CLOSE message
  50//
  51void OnClose(HWND hWnd)
  52{
  53    EndDialog(hWnd, 0);
  54}
  55
  56
  57#pragma region Animation
  58
  59// MSDN: Animation Control
  60// http://msdn.microsoft.com/en-us/library/bb761881.aspx
  61
  62#define IDC_ANIMATION		990
  63
  64
  65//
  66//   FUNCTION: OnInitAnimationDialog(HWND, HWND, LPARAM)
  67//
  68//   PURPOSE: Process the WM_INITDIALOG message
  69//
  70BOOL OnInitAnimationDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
  71{
  72    // Load and register animation control class.
  73    INITCOMMONCONTROLSEX iccx = { sizeof(iccx) };
  74    iccx.dwICC = ICC_ANIMATE_CLASS;
  75    if (!InitCommonControlsEx(&iccx))
  76    {
  77        return FALSE;
  78    }
  79
  80    // Create the animation control.
  81    RECT rc = { 20, 20, 280, 60 };
  82    HWND hAnimate = CreateWindowEx(0, ANIMATE_CLASS, 0, 
  83        ACS_TIMER | ACS_AUTOPLAY | ACS_TRANSPARENT | WS_CHILD | WS_VISIBLE, 
  84        rc.left, rc.top, rc.right, rc.bottom, 
  85        hWnd, reinterpret_cast<HMENU>(IDC_ANIMATION), g_hInst, 0);
  86    if (hAnimate == NULL)
  87    {
  88        return FALSE;
  89    }
  90
  91    // Open the AVI clip and display its first frame in the animation control.
  92    if (0 == SendMessage(hAnimate, ACM_OPEN, static_cast<WPARAM>(0), 
  93        reinterpret_cast<LPARAM>(MAKEINTRESOURCE(IDR_UPLOAD_AVI))))
  94    {
  95        return FALSE;
  96    }
  97
  98    // Plays the AVI clip in the animation control.
  99    if (0 == SendMessage(hAnimate, ACM_PLAY, static_cast<WPARAM>(-1), 
 100        MAKELONG(/*from frame*/0, /*to frame*/-1)))
 101    {
 102        return FALSE;
 103    }
 104
 105    return TRUE;
 106}
 107
 108
 109//
 110//  FUNCTION: AnimationDlgProc(HWND, UINT, WPARAM, LPARAM)
 111//
 112//  PURPOSE:  Processes messages for the Animation control dialog.
 113//
 114INT_PTR CALLBACK AnimationDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 115{
 116    switch (message)
 117    {
 118        // Handle the WM_INITDIALOG message in OnInitAnimationDialog
 119        HANDLE_MSG (hWnd, WM_INITDIALOG, OnInitAnimationDialog);
 120
 121        // Handle the WM_CLOSE message in OnClose
 122        HANDLE_MSG (hWnd, WM_CLOSE, OnClose);
 123
 124    default:
 125        return FALSE;	// Let system deal with msg
 126    }
 127    return 0;
 128}
 129
 130#pragma endregion
 131
 132
 133#pragma region ComboBoxEx
 134
 135// MSDN: ComboBoxEx Control Reference
 136// http://msdn.microsoft.com/en-us/library/bb775740.aspx
 137
 138#define IDC_COMBOBOXEX		1990
 139
 140
 141//
 142//   FUNCTION: OnInitComboBoxExDialog(HWND, HWND, LPARAM)
 143//
 144//   PURPOSE: Process the WM_INITDIALOG message
 145//
 146BOOL OnInitComboBoxExDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
 147{
 148    // Load and register ComboBoxEx control class.
 149    INITCOMMONCONTROLSEX iccx = { sizeof(iccx) };
 150    iccx.dwICC = ICC_USEREX_CLASSES;
 151    if (!InitCommonControlsEx(&iccx))
 152    {
 153        return FALSE;
 154    }
 155
 156    // Create the ComboBoxEx control.
 157    RECT rc = { 20, 20, 280, 100 };
 158    HWND hComboEx = CreateWindowEx(0, WC_COMBOBOXEX, 0, CBS_DROPDOWN | WS_CHILD | 
 159        WS_VISIBLE, rc.left, rc.top, rc.right, rc.bottom, hWnd, 
 160        reinterpret_cast<HMENU>(IDC_COMBOBOXEX), g_hInst, 0);
 161    if (hComboEx == NULL)
 162    {
 163        return FALSE;
 164    }
 165
 166    // Create an image list to hold icons for use by the ComboBoxEx control.
 167    // The image list is destroyed in OnComboBoxExClose.
 168    PCWSTR lpszResID[] = { IDI_APPLICATION, IDI_INFORMATION, IDI_QUESTION };
 169    int nIconCount = ARRAYSIZE(lpszResID);
 170    HIMAGELIST hImageList = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 
 171        nIconCount, 0);
 172    if (hImageList == NULL)
 173    {
 174        return FALSE;
 175    }
 176
 177    for (int i = 0; i < nIconCount; i++)
 178    {
 179        HANDLE hIcon = LoadImage(NULL, lpszResID[i], IMAGE_ICON, 0, 0, LR_SHARED);
 180        if (hIcon != NULL)
 181        {
 182            ImageList_AddIcon(hImageList, static_cast<HICON>(hIcon));
 183        }
 184    }
 185
 186    // Associate the image list with the ComboBoxEx common control
 187    SendMessage(hComboEx, CBEM_SETIMAGELIST, 0, 
 188        reinterpret_cast<LPARAM>(hImageList));
 189
 190    // Add nIconCount items to the ComboBoxEx common control
 191    wchar_t szText[200];
 192    for (int i = 0; i < nIconCount; i++)
 193    {
 194        COMBOBOXEXITEM cbei = {0};
 195        cbei.mask = CBEIF_IMAGE | CBEIF_TEXT | CBEIF_SELECTEDIMAGE;
 196        cbei.iItem = -1;
 197        swprintf_s(szText, 200, L"Item  %d", i);
 198        cbei.pszText = szText;
 199        cbei.iImage = i;
 200        cbei.iSelectedImage = i;
 201        SendMessage(hComboEx, CBEM_INSERTITEM, 0, reinterpret_cast<LPARAM>(&cbei));
 202    }
 203
 204    // Store the image list handle as the user data of the window so that it
 205    // can be destroyed when the window is destroyed. (See OnComboBoxExClose)
 206    SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(hImageList));
 207
 208    return TRUE;
 209}
 210
 211//
 212//   FUNCTION: OnComboBoxExClose(HWND)
 213//
 214//   PURPOSE: Process the WM_CLOSE message
 215//
 216void OnComboBoxExClose(HWND hWnd)
 217{
 218    // Destroy the image list associated with the ComboBoxEx control
 219    ImageList_Destroy((HIMAGELIST)GetWindowLongPtr(hWnd, GWLP_USERDATA));
 220
 221    DestroyWindow(hWnd);
 222}
 223
 224//
 225//  FUNCTION: ComboBoxExDlgProc(HWND, UINT, WPARAM, LPARAM)
 226//
 227//  PURPOSE:  Processes messages for the ComboBoxEx control dialog.
 228//
 229//
 230INT_PTR CALLBACK ComboBoxExDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 231{
 232    switch (message)
 233    {
 234        // Handle the WM_INITDIALOG message in OnInitComboBoxExDialog
 235        HANDLE_MSG (hWnd, WM_INITDIALOG, OnInitComboBoxExDialog);
 236
 237        // Handle the WM_CLOSE message in OnComboBoxExClose
 238        HANDLE_MSG (hWnd, WM_CLOSE, OnComboBoxExClose);
 239
 240    default:
 241        return FALSE;	// Let system deal with msg
 242    }
 243    return 0;
 244}
 245
 246#pragma endregion
 247
 248
 249#pragma region Updown
 250// MSDN: Up-Down Control
 251// http://msdn.microsoft.com/en-us/library/bb759880.aspx
 252
 253#define IDC_EDIT		2990
 254#define IDC_UPDOWN		2991
 255
 256//
 257//   FUNCTION: OnInitUpdownDialog(HWND, HWND, LPARAM)
 258//
 259//   PURPOSE: Process the WM_INITDIALOG message
 260//
 261BOOL OnInitUpdownDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
 262{
 263    // Load and register Updown control class
 264    INITCOMMONCONTROLSEX iccx;
 265    iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
 266    iccx.dwICC = ICC_UPDOWN_CLASS;
 267    if (!InitCommonControlsEx(&iccx))
 268        return FALSE;
 269
 270    // Create an Edit control
 271    RECT rc = { 20, 20, 100, 24 };
 272    HWND hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, L"EDIT", 0, 
 273        WS_CHILD | WS_VISIBLE, rc.left, rc.top, rc.right, rc.bottom, 
 274        hWnd, (HMENU)IDC_EDIT, g_hInst, 0);
 275
 276    // Create the ComboBoxEx control
 277    SetRect(&rc, 20, 60, 180, 20);
 278    HWND hUpdown = CreateWindowEx(0, UPDOWN_CLASS, 0, 
 279        UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_WRAP | WS_CHILD | WS_VISIBLE, 
 280        rc.left, rc.top, rc.right, rc.bottom, 
 281        hWnd, (HMENU)IDC_UPDOWN, g_hInst, 0);
 282
 283    // Explicitly attach the Updown control to its 'buddy' edit control
 284    SendMessage(hUpdown, UDM_SETBUDDY, (WPARAM)hEdit, 0);
 285
 286    return TRUE;
 287}
 288
 289//
 290//  FUNCTION: UpdownDlgProc(HWND, UINT, WPARAM, LPARAM)
 291//
 292//  PURPOSE:  Processes messages for the Updown control dialog.
 293//
 294//
 295INT_PTR CALLBACK UpdownDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 296{
 297    switch (message)
 298    {
 299        // Handle the WM_INITDIALOG message in OnInitUpdownDialog
 300        HANDLE_MSG (hWnd, WM_INITDIALOG, OnInitUpdownDialog);
 301
 302        // Handle the WM_CLOSE message in OnClose
 303        HANDLE_MSG (hWnd, WM_CLOSE, OnClose);
 304
 305    default:
 306        return FALSE;	// Let system deal with msg
 307    }
 308    return 0;
 309}
 310
 311#pragma endregion
 312
 313
 314#pragma region Header
 315// MSDN: Header Control
 316// http://msdn.microsoft.com/en-us/library/bb775239.aspx
 317
 318#define IDC_HEADER			3990
 319
 320//
 321//   FUNCTION: OnHeaderSize(HWND, UINT, int, int)
 322//
 323//   PURPOSE: Process the WM_SIZE message
 324//
 325void OnHeaderSize(HWND hWnd, UINT state, int cx, int cy)
 326{
 327    // Adjust the position and the layout of the Header control
 328    RECT rc = { 0, 0, cx, cy };
 329    WINDOWPOS wp = { 0 };
 330    HDLAYOUT hdl = { &rc, &wp };
 331
 332    // Get the header control handle which has been previously stored in the 
 333    // user data associated with the parent window.
 334    HWND hHeader = (HWND)GetWindowLongPtr(hWnd, GWLP_USERDATA);
 335
 336    // hdl.wp retrieves information used to set the size and postion of the  
 337    // header control within the target rectangle of the parent window. 
 338    SendMessage(hHeader, HDM_LAYOUT, 0, (LPARAM)&hdl);
 339
 340    // Set the size and position of the header control based on hdl.wp.
 341    SetWindowPos(hHeader, wp.hwndInsertAfter, 
 342        wp.x, wp.y, wp.cx, wp.cy + 8, wp.flags);
 343}
 344
 345//
 346//   FUNCTION: OnInitHeaderDialog(HWND, HWND, LPARAM)
 347//
 348//   PURPOSE: Process the WM_INITDIALOG message
 349//
 350BOOL OnInitHeaderDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
 351{
 352    // Load and register Header control class
 353    INITCOMMONCONTROLSEX iccx;
 354    iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
 355    iccx.dwICC = ICC_WIN95_CLASSES;
 356    if (!InitCommonControlsEx(&iccx))
 357        return FALSE;
 358
 359    // Create the Header control
 360    RECT rc = { 0, 0, 0, 0 };
 361    HWND hHeader = CreateWindowEx(0, WC_HEADER, 0, 
 362        HDS_BUTTONS | WS_CHILD | WS_VISIBLE, 
 363        rc.left, rc.top, rc.right, rc.bottom, 
 364        hWnd, (HMENU)IDC_HEADER, g_hInst, 0);
 365
 366    // Store the header control handle as the user data associated with the 
 367    // parent window so that it can be retrieved for later use.
 368    SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)hHeader);
 369
 370    // Resize the header control
 371    GetClientRect(hWnd, &rc);
 372    OnHeaderSize(hWnd, 0, rc.right, rc.bottom);
 373
 374    // Set the font for the header common control
 375    SendMessage(hHeader, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0);
 376
 377    // Add 4 Header items
 378    TCHAR szText[200];
 379    for (UINT i = 0; i < 4; i++)
 380    {
 381        HDITEM hdi = {0};
 382        hdi.mask = HDI_WIDTH | HDI_FORMAT | HDI_TEXT;
 383        hdi.cxy = rc.right / 4;
 384        hdi.fmt = HDF_CENTER;
 385        swprintf_s(szText, 200, L"Header  %d", i);
 386        hdi.pszText = szText;
 387        hdi.cchTextMax = 200;
 388
 389        SendMessage(hHeader, HDM_INSERTITEM, i, (LPARAM)&hdi);
 390    }
 391
 392    return TRUE;
 393}
 394
 395//
 396//  FUNCTION: HeaderDlgProc(HWND, UINT, WPARAM, LPARAM)
 397//
 398//  PURPOSE:  Processes messages for the Header control dialog.
 399//
 400//
 401INT_PTR CALLBACK HeaderDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 402{
 403    switch (message)
 404    {
 405        // Handle the WM_INITDIALOG message in OnInitHeaderDialog
 406        HANDLE_MSG (hWnd, WM_INITDIALOG, OnInitHeaderDialog);
 407
 408        // Handle the WM_CLOSE message in OnClose
 409        HANDLE_MSG (hWnd, WM_CLOSE, OnClose);
 410
 411        // Handle the WM_SIZE message in OnHeaderSize
 412        HANDLE_MSG (hWnd, WM_SIZE, OnHeaderSize);
 413
 414    default:
 415        return FALSE;	// Let system deal with msg
 416    }
 417    return 0;
 418}
 419
 420#pragma endregion
 421
 422
 423#pragma region MonthCal
 424// MSDN: Month Calendar Control Reference
 425// http://msdn.microsoft.com/en-us/library/bb760917.aspx
 426
 427#define IDC_MONTHCAL		4990
 428
 429//
 430//   FUNCTION: OnInitMonthCalDialog(HWND, HWND, LPARAM)
 431//
 432//   PURPOSE: Process the WM_INITDIALOG message
 433//
 434BOOL OnInitMonthCalDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
 435{
 436    // Load and register MonthCal control class
 437    INITCOMMONCONTROLSEX iccx;
 438    iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
 439    iccx.dwICC = ICC_DATE_CLASSES;
 440    if (!InitCommonControlsEx(&iccx))
 441        return FALSE;
 442
 443    // Create the Month Calendar control
 444    RECT rc = { 20, 20, 280, 200 };
 445    HWND hMonthCal = CreateWindowEx(0, MONTHCAL_CLASS, 0, 
 446        WS_CHILD | WS_VISIBLE, rc.left, rc.top, rc.right, rc.bottom, 
 447        hWnd, (HMENU)IDC_MONTHCAL, g_hInst, 0);
 448
 449    return TRUE;
 450}
 451
 452//
 453//  FUNCTION: MonthCalDlgProc(HWND, UINT, WPARAM, LPARAM)
 454//
 455//  PURPOSE:  Processes messages for the MonthCal control dialog.
 456//
 457//
 458INT_PTR CALLBACK MonthCalDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 459{
 460    switch (message)
 461    {
 462        // Handle the WM_INITDIALOG message in OnInitMonthCalDialog
 463        HANDLE_MSG (hWnd, WM_INITDIALOG, OnInitMonthCalDialog);
 464
 465        // Handle the WM_CLOSE message in OnClose
 466        HANDLE_MSG (hWnd, WM_CLOSE, OnClose);
 467
 468    default:
 469        return FALSE;	// Let system deal with msg
 470    }
 471    return 0;
 472}
 473
 474#pragma endregion
 475
 476
 477#pragma region DateTimePick
 478// MSDN: Date and Time Picker
 479// http://msdn.microsoft.com/en-us/library/bb761727.aspx
 480
 481#define IDC_DATETIMEPICK		5990
 482
 483//
 484//   FUNCTION: OnInitDateTimePickDialog(HWND, HWND, LPARAM)
 485//
 486//   PURPOSE: Process the WM_INITDIALOG message
 487//
 488BOOL OnInitDateTimePickDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
 489{
 490    // Load and register DateTimePick control class
 491    INITCOMMONCONTROLSEX iccx;
 492    iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
 493    iccx.dwICC = ICC_DATE_CLASSES;
 494    if (!InitCommonControlsEx(&iccx))
 495        return FALSE;
 496
 497    // Create the DateTimePick control
 498    RECT rc = { 20, 20, 150, 30 };
 499    HWND hDateTimePick = CreateWindowEx(0, DATETIMEPICK_CLASS, 0, 
 500        WS_CHILD | WS_VISIBLE, rc.left, rc.top, rc.right, rc.bottom, 
 501        hWnd, (HMENU)IDC_DATETIMEPICK, g_hInst, 0);
 502
 503    return TRUE;
 504}
 505
 506//
 507//  FUNCTION: DateTimePickDlgProc(HWND, UINT, WPARAM, LPARAM)
 508//
 509//  PURPOSE:  Processes messages for the DateTimePick control dialog.
 510//
 511//
 512INT_PTR CALLBACK DateTimePickDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 513{
 514    switch (message)
 515    {
 516        // Handle the WM_INITDIALOG message in OnInitDateTimePickDialog
 517        HANDLE_MSG (hWnd, WM_INITDIALOG, OnInitDateTimePickDialog);
 518
 519        // Handle the WM_CLOSE message in OnClose
 520        HANDLE_MSG (hWnd, WM_CLOSE, OnClose);
 521
 522    default:
 523        return FALSE;	// Let system deal with msg
 524    }
 525    return 0;
 526}
 527
 528#pragma endregion
 529
 530
 531#pragma region Listview
 532// MSDN: List View
 533// http://msdn.microsoft.com/en-us/library/bb774737.aspx
 534
 535#define IDC_LISTVIEW		6990
 536
 537struct LVHandles
 538{
 539    HWND hListview;
 540    HIMAGELIST hLargeIcons;
 541    HIMAGELIST hSmallIcons;
 542};
 543
 544//
 545//   FUNCTION: OnListviewSize(HWND, UINT, int, int)
 546//
 547//   PURPOSE: Process the WM_SIZE message
 548//
 549void OnListviewSize(HWND hWnd, UINT state, int cx, int cy)
 550{
 551    // Get the pointer to listview information which was previously stored in 
 552    // the user data associated with the parent window.
 553    LVHandles* lvh = (LVHandles*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
 554
 555    // Resize the listview control to fill the parent window's client area
 556    MoveWindow(lvh->hListview, 0, 0, cx, cy, 1);
 557
 558    // Arrange contents of listview along top of control
 559    SendMessage(lvh->hListview, LVM_ARRANGE, LVA_ALIGNTOP, 0);
 560}
 561
 562//
 563//   FUNCTION: OnInitListviewDialog(HWND, HWND, LPARAM)
 564//
 565//   PURPOSE: Process the WM_INITDIALOG message
 566//
 567BOOL OnInitListviewDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
 568{
 569    // Load and register Listview control class
 570    INITCOMMONCONTROLSEX iccx;
 571    iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
 572    iccx.dwICC = ICC_LISTVIEW_CLASSES;
 573    if (!InitCommonControlsEx(&iccx))
 574        return FALSE;
 575
 576    // Create storage for struct to contain information about the listview 
 577    // (window and image list handles).
 578    LVHandles* lvh = new LVHandles();
 579
 580    // Store that pointer as the user data associated with the parent window 
 581    // so that it can be retrieved for later use. 
 582    SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)lvh);
 583
 584    // Create the Listview control
 585    RECT rc;
 586    GetClientRect(hWnd, &rc);
 587    lvh->hListview = CreateWindowEx(0, WC_LISTVIEW, 0, 
 588        LVS_ICON | WS_CHILD | WS_VISIBLE, 
 589        rc.left, rc.top, rc.right, rc.bottom, 
 590        hWnd, (HMENU)IDC_LISTVIEW, g_hInst, 0);
 591
 592
 593    /////////////////////////////////////////////////////////////////////////
 594    // Set up and attach image lists to list view common control.
 595    // 
 596
 597    // Create the image lists
 598    int lx = GetSystemMetrics(SM_CXICON);
 599    int ly = GetSystemMetrics(SM_CYICON);
 600    lvh->hLargeIcons = ImageList_Create(lx, ly, ILC_COLOR32 | ILC_MASK, 1, 1); 
 601    int sx = GetSystemMetrics(SM_CXSMICON);
 602    int sy = GetSystemMetrics(SM_CYSMICON);
 603    lvh->hSmallIcons = ImageList_Create(sx, sy, ILC_COLOR32 | ILC_MASK, 1, 1);
 604
 605    // Add icons to image lists
 606    HICON hLargeIcon, hSmallIcon;
 607    for (int rid = IDI_ICON1; rid <= IDI_ICON10; rid++)
 608    {
 609        // Load and add the large icon
 610        hLargeIcon = (HICON)LoadImage(g_hInst, MAKEINTRESOURCE(rid), 
 611            IMAGE_ICON, lx, ly, 0);
 612        ImageList_AddIcon(lvh->hLargeIcons, hLargeIcon);
 613        DestroyIcon(hLargeIcon);
 614
 615        // Load and add the small icon
 616        hSmallIcon = (HICON)LoadImage(g_hInst, MAKEINTRESOURCE(rid), 
 617            IMAGE_ICON, sx, sy, 0);
 618        ImageList_AddIcon(lvh->hSmallIcons, hSmallIcon);
 619        DestroyIcon(hSmallIcon);
 620    }
 621
 622    // Attach image lists to list view common control
 623    ListView_SetImageList(lvh->hListview, lvh->hLargeIcons, LVSIL_NORMAL); 
 624    ListView_SetImageList(lvh->hListview, lvh->hSmallIcons, LVSIL_SMALL);
 625
 626
 627    /////////////////////////////////////////////////////////////////////////
 628    // Add items to the the list view common control.
 629    // 
 630
 631    LVITEM lvi = {0};
 632    lvi.mask = LVIF_TEXT | LVIF_IMAGE;
 633    TCHAR szText[200];
 634    for (int i = 0; i < 10; i++)
 635    {
 636        lvi.iItem = i;
 637        swprintf_s(szText, 200, L"Item  %d", i);
 638        lvi.pszText = szText;
 639        lvi.iImage = i;
 640
 641        SendMessage(lvh->hListview, LVM_INSERTITEM, 0, (LPARAM)&lvi);
 642    }
 643
 644    return TRUE;
 645}
 646
 647//
 648//   FUNCTION: OnListviewClose(HWND)
 649//
 650//   PURPOSE: Process the WM_CLOSE message
 651//
 652void OnListviewClose(HWND hWnd)
 653{
 654    // Free up resources
 655
 656    // Get the information which was previously stored as the user data of 
 657    // the main window
 658    LVHandles* lvh = (LVHandles*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
 659
 660    // Destroy the image lists
 661    ImageList_Destroy(lvh->hLargeIcons);
 662    ImageList_Destroy(lvh->hSmallIcons);
 663    delete lvh;
 664
 665    DestroyWindow(hWnd);
 666}
 667
 668//
 669//  FUNCTION: ListviewDlgProc(HWND, UINT, WPARAM, LPARAM)
 670//
 671//  PURPOSE:  Processes messages for the Listview control dialog.
 672//
 673//
 674INT_PTR CALLBACK ListviewDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 675{
 676    switch (message)
 677    {
 678        // Handle the WM_INITDIALOG message in OnInitListviewDialog
 679        HANDLE_MSG (hWnd, WM_INITDIALOG, OnInitListviewDialog);
 680
 681        // Handle the WM_CLOSE message in OnClose
 682        HANDLE_MSG (hWnd, WM_CLOSE, OnListviewClose);
 683
 684        // Handle the WM_SIZE message in OnListviewSize
 685        HANDLE_MSG (hWnd, WM_SIZE, OnListviewSize);
 686
 687    default:
 688        return FALSE;	// Let system deal with msg
 689    }
 690    return 0;
 691}
 692
 693#pragma endregion
 694
 695
 696#pragma region Treeview
 697// MSDN: Tree View
 698// http://msdn.microsoft.com/en-us/library/bb759988.aspx
 699
 700#define IDC_TREEVIEW		7990
 701
 702//
 703//   FUNCTION: OnTreeviewSize(HWND, UINT, int, int)
 704//
 705//   PURPOSE: Process the WM_SIZE message
 706//
 707void OnTreeviewSize(HWND hWnd, UINT state, int cx, int cy)
 708{
 709    // Get the treeview control handle which was previously stored in the 
 710    // user data associated with the parent window.
 711    HWND hTreeview = (HWND)GetWindowLongPtr(hWnd, GWLP_USERDATA);
 712
 713    // Resize treeview control to fill client area of its parent window
 714    MoveWindow(hTreeview, 0, 0, cx, cy, TRUE);
 715}
 716
 717HTREEITEM InsertTreeviewItem(const HWND hTreeview, const LPTSTR pszText, 
 718                             HTREEITEM htiParent)
 719{
 720    TVITEM tvi = {0};
 721    tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
 722    tvi.pszText = pszText;
 723    tvi.cchTextMax = wcslen(pszText);
 724    tvi.iImage = 0;
 725
 726    TVINSERTSTRUCT tvis = {0};
 727    tvi.iSelectedImage = 1;
 728    tvis.item = tvi; 
 729    tvis.hInsertAfter = 0;
 730    tvis.hParent = htiParent;
 731
 732    return (HTREEITEM)SendMessage(hTreeview, TVM_INSERTITEM, 0, (LPARAM)&tvis);
 733}
 734
 735//
 736//   FUNCTION: OnInitTreeviewDialog(HWND, HWND, LPARAM)
 737//
 738//   PURPOSE: Process the WM_INITDIALOG message
 739//
 740BOOL OnInitTreeviewDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
 741{
 742    // Load and register Treeview control class
 743    INITCOMMONCONTROLSEX iccx;
 744    iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
 745    iccx.dwICC = ICC_TREEVIEW_CLASSES;
 746    if (!InitCommonControlsEx(&iccx))
 747        return FALSE;
 748
 749    // Create the Treeview control
 750    RECT rc;
 751    GetClientRect(hWnd, &rc);
 752    HWND hTreeview = CreateWindowEx(0, WC_TREEVIEW, 0, 
 753        TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS | WS_CHILD | WS_VISIBLE, 
 754        rc.left, rc.top, rc.right, rc.bottom, 
 755        hWnd, (HMENU)IDC_TREEVIEW, g_hInst, 0);
 756
 757    // Store the Treeview control handle as the user data associated with the 
 758    // parent window so that it can be retrieved for later use.
 759    SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)hTreeview);
 760
 761
 762    /////////////////////////////////////////////////////////////////////////
 763    // Set up and attach image lists to tree view common control.
 764    // 
 765
 766    // Create an image list
 767    HIMAGELIST hImages = ImageList_Create(
 768        GetSystemMetrics(SM_CXSMICON),
 769        GetSystemMetrics(SM_CYSMICON), 
 770        ILC_COLOR32 | ILC_MASK, 1, 1);
 771
 772    // Get an instance handle for a source of icon images
 773    HINSTANCE hLib = LoadLibrary(L"shell32.dll");
 774    if (hLib)
 775    {
 776        for (int i = 4; i < 6; i++)
 777        {
 778            // Because the icons are loaded from system resources (i.e. they are 
 779            // shared), it is not necessary to free resources with 'DestroyIcon'.
 780            HICON hIcon = (HICON)LoadImage(hLib, MAKEINTRESOURCE(i), IMAGE_ICON,
 781                0, 0, LR_SHARED);
 782            ImageList_AddIcon(hImages, hIcon); 
 783        }
 784        
 785        FreeLibrary(hLib);
 786        hLib = NULL;
 787    }
 788
 789    // Attach image lists to tree view common control
 790    TreeView_SetImageList(hTreeview, hImages, TVSIL_NORMAL);
 791
 792
 793    /////////////////////////////////////////////////////////////////////////
 794    // Add items to the tree view common control.
 795    // 
 796
 797    // Insert the first item at root level
 798    HTREEITEM hPrev = InsertTreeviewItem(hTreeview, L"First", TVI_ROOT);
 799
 800    // Sub item of first item
 801    hPrev = InsertTreeviewItem(hTreeview, L"Level01", hPrev);
 802
 803    // Sub item of 'level01' item
 804    hPrev = InsertTreeviewItem(hTreeview, L"Level02", hPrev);
 805
 806    // Insert the second item at root level
 807    hPrev = InsertTreeviewItem(hTreeview, L"Second", TVI_ROOT);
 808
 809    // Insert the third item at root level
 810    hPrev = InsertTreeviewItem(hTreeview, L"Third", TVI_ROOT);
 811
 812    return TRUE;
 813}
 814
 815//
 816//   FUNCTION: OnTreeviewClose(HWND)
 817//
 818//   PURPOSE: Process the WM_CLOSE message
 819//
 820void OnTreeviewClose(HWND hWnd)
 821{
 822    // Get the treeview control handle which was previously stored in the 
 823    // user data associated with the parent window.
 824    HWND hTreeview = (HWND)GetWindowLongPtr(hWnd, GWLP_USERDATA);
 825
 826    // Free resources used by the treeview's image list
 827    HIMAGELIST hImages = TreeView_GetImageList(hTreeview, TVSIL_NORMAL);
 828    ImageList_Destroy(hImages);
 829
 830    DestroyWindow(hWnd);
 831}
 832
 833//
 834//  FUNCTION: TreeviewDlgProc(HWND, UINT, WPARAM, LPARAM)
 835//
 836//  PURPOSE:  Processes messages for the Treeview control dialog.
 837//
 838//
 839INT_PTR CALLBACK TreeviewDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 840{
 841    switch (message)
 842    {
 843        // Handle the WM_INITDIALOG message in OnInitTreeviewDialog
 844        HANDLE_MSG (hWnd, WM_INITDIALOG, OnInitTreeviewDialog);
 845
 846        // Handle the WM_CLOSE message in OnTreeviewClose
 847        HANDLE_MSG (hWnd, WM_CLOSE, OnTreeviewClose);
 848
 849        // Handle the WM_SIZE message in OnTreeviewSize
 850        HANDLE_MSG (hWnd, WM_SIZE, OnTreeviewSize);
 851
 852    default:
 853        return FALSE;	// Let system deal with msg
 854    }
 855    return 0;
 856}
 857
 858#pragma endregion
 859
 860
 861#pragma region TabControl
 862// MSDN: Tab
 863// http://msdn.microsoft.com/en-us/library/bb760548.aspx
 864
 865#define IDC_TAB			8990
 866
 867//
 868//   FUNCTION: OnTabSize(HWND, UINT, int, int)
 869//
 870//   PURPOSE: Process the WM_SIZE message
 871//
 872void OnTabSize(HWND hWnd, UINT state, int cx, int cy)
 873{
 874    // Get the Tab control handle which was previously stored in the 
 875    // user data associated with the parent window.
 876    HWND hTab = (HWND)GetWindowLongPtr(hWnd, GWLP_USERDATA);
 877
 878    // Resize tab control to fill client area of its parent window
 879    MoveWindow(hTab, 2, 2, cx - 4, cy - 4, TRUE);
 880}
 881
 882int InsertTabItem(HWND hTab, LPTSTR pszText, int iid)
 883{
 884    TCITEM ti = {0};
 885    ti.mask = TCIF_TEXT;
 886    ti.pszText = pszText;
 887    ti.cchTextMax = wcslen(pszText);
 888
 889    return (int)SendMessage(hTab, TCM_INSERTITEM, iid, (LPARAM)&ti);
 890}
 891
 892//
 893//   FUNCTION: OnInitTabControlDialog(HWND, HWND, LPARAM)
 894//
 895//   PURPOSE: Process the WM_INITDIALOG message
 896//
 897BOOL OnInitTabControlDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
 898{
 899    // Load and register Tab control class
 900    INITCOMMONCONTROLSEX iccx;
 901    iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
 902    iccx.dwICC = ICC_TAB_CLASSES;
 903    if (!InitCommonControlsEx(&iccx))
 904        return FALSE;
 905
 906    // Create the Tab control 
 907    RECT rc;
 908    GetClientRect(hWnd, &rc);
 909    HWND hTab = CreateWindowEx(0, WC_TABCONTROL, 0, 
 910        TCS_FIXEDWIDTH | WS_CHILD | WS_VISIBLE, 
 911        rc.left + 2, rc.top + 2, rc.right - 4, rc.bottom - 4, 
 912        hWnd, (HMENU)IDC_TAB, g_hInst, 0);
 913
 914    // Set the font of the tabs to a more typical system GUI font
 915    SendMessage(hTab, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0);
 916
 917    // Store the Tab control handle as the user data associated with the 
 918    // parent window so that it can be retrieved for later use.
 919    SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)hTab);
 920
 921
 922    /////////////////////////////////////////////////////////////////////////
 923    // Add items to the tab common control.
 924    // 
 925
 926    InsertTabItem(hTab, L"First Page", 0);
 927    InsertTabItem(hTab, L"Second Page", 1);
 928    InsertTabItem(hTab, L"Third Page", 2);
 929    InsertTabItem(hTab, L"Fourth Page", 3);
 930    InsertTabItem(hTab, L"Fifth Page", 4);
 931
 932    return TRUE;
 933}
 934
 935//
 936//  FUNCTION: TabControlDlgProc(HWND, UINT, WPARAM, LPARAM)
 937//
 938//  PURPOSE:  Processes messages for the TabControl control dialog.
 939//
 940//
 941INT_PTR CALLBACK TabControlDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 942{
 943    switch (message)
 944    {
 945        // Handle the WM_INITDIALOG message in OnInitTabControlDialog
 946        HANDLE_MSG (hWnd, WM_INITDIALOG, OnInitTabControlDialog);
 947
 948        // Handle the WM_CLOSE message in OnClose
 949        HANDLE_MSG (hWnd, WM_CLOSE, OnClose);
 950
 951        // Handle the WM_SIZE message in OnTabSize
 952        HANDLE_MSG (hWnd, WM_SIZE, OnTabSize);
 953
 954    default:
 955        return FALSE;	// Let system deal with msg
 956    }
 957    return 0;
 958}
 959
 960#pragma endregion
 961
 962
 963#pragma region Tooltip
 964// MSDN: ToolTip
 965// http://msdn.microsoft.com/en-us/library/bb760246.aspx
 966
 967#define IDC_BUTTON1		9990
 968
 969//
 970//   FUNCTION: OnInitTooltipDialog(HWND, HWND, LPARAM)
 971//
 972//   PURPOSE: Process the WM_INITDIALOG message
 973//
 974BOOL OnInitTooltipDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
 975{
 976    // Load and register Tooltip control class
 977    INITCOMMONCONTROLSEX iccx;
 978    iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
 979    iccx.dwICC = ICC_WIN95_CLASSES;
 980    if (!InitCommonControlsEx(&iccx))
 981        return FALSE;
 982
 983    // Create a button control
 984    RECT rc = { 20, 20, 120, 40 };
 985    HWND hBtn = CreateWindowEx(0, L"BUTTON", L"Tooltip Target", 
 986        WS_CHILD | WS_VISIBLE, rc.left, rc.top, rc.right, rc.bottom, 
 987        hWnd, (HMENU)IDC_BUTTON1, g_hInst, 0); 
 988
 989    // Create a tooltip
 990    // A tooltip control should not have the WS_CHILD style, nor should it 
 991    // have an id, otherwise its behavior will be adversely affected.
 992    HWND hTooltip = CreateWindowEx(0, TOOLTIPS_CLASS, L"", TTS_ALWAYSTIP, 
 993        0, 0, 0, 0, hWnd, 0, g_hInst, 0);
 994
 995    // Associate the tooltip with the button control
 996    TOOLINFO ti = {0};
 997    ti.cbSize = sizeof(ti);
 998    ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
 999    ti.uId = (UINT_PTR)hBtn;
1000    ti.lpszText = L"This is a button.";
1001    ti.hwnd = hWnd;
1002    SendMessage(hTooltip, TTM_ADDTOOL, 0, (LPARAM)&ti);
1003
1004    return TRUE;
1005}
1006
1007//
1008//  FUNCTION: TooltipDlgProc(HWND, UINT, WPARAM, LPARAM)
1009//
1010//  PURPOSE:  Processes messages for the Tooltip control dialog.
1011//
1012//
1013INT_PTR CALLBACK TooltipDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1014{
1015    switch (message)
1016    {
1017        // Handle the WM_INITDIALOG message in OnInitTooltipDialog
1018        HANDLE_MSG (hWnd, WM_INITDIALOG, OnInitTooltipDialog);
1019
1020        // Handle the WM_CLOSE message in OnClose
1021        HANDLE_MSG (hWnd, WM_CLOSE, OnClose);
1022
1023    default:
1024        return FALSE;	// Let system deal with msg
1025    }
1026    return 0;
1027}
1028
1029#pragma endregion
1030
1031
1032#pragma region IPAddress
1033// MSDN: IP Address Control
1034// http://msdn.microsoft.com/en-us/library/bb761374.aspx
1035
1036#define IDC_IPADDRESS		10990
1037
1038//
1039//   FUNCTION: OnInitIPAddressDialog(HWND, HWND, LPARAM)
1040//
1041//   PURPOSE: Process the WM_INITDIALOG message
1042//
1043BOOL OnInitIPAddressDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
1044{
1045    // Load and register IPAddress control class
1046    INITCOMMONCONTROLSEX iccx;
1047    iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
1048    iccx.dwICC = ICC_INTERNET_CLASSES;
1049    if (!InitCommonControlsEx(&iccx))
1050        return FALSE;
1051
1052    // Create the IPAddress control
1053    RECT rc = { 20, 20, 180, 24 };
1054    HWND hIPAddress = CreateWindowEx(0, WC_IPADDRESS, 0, 
1055        WS_CHILD | WS_VISIBLE, rc.left, rc.top, rc.right, rc.bottom, 
1056        hWnd, (HMENU)IDC_IPADDRESS, g_hInst, 0);
1057
1058    return TRUE;
1059}
1060
1061//
1062//  FUNCTION: IPAddressDlgProc(HWND, UINT, WPARAM, LPARAM)
1063//
1064//  PURPOSE:  Processes messages for the IPAddress control dialog.
1065//
1066//
1067INT_PTR CALLBACK IPAddressDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1068{
1069    switch (message)
1070    {
1071        // Handle the WM_INITDIALOG message in OnInitIPAddressDialog
1072        HANDLE_MSG (hWnd, WM_INITDIALOG, OnInitIPAddressDialog);
1073
1074        // Handle the WM_CLOSE message in OnClose
1075        HANDLE_MSG (hWnd, WM_CLOSE, OnClose);
1076
1077    default:
1078        return FALSE;	// Let system deal with msg
1079    }
1080    return 0;
1081}
1082
1083#pragma endregion
1084
1085
1086#pragma region Statusbar
1087// MSDN: Status Bar
1088// http://msdn.microsoft.com/en-us/library/bb760726.aspx
1089
1090#define IDC_STATUSBAR		11990
1091
1092//
1093//   FUNCTION: OnStatusbarSize(HWND, UINT, int, int)
1094//
1095//   PURPOSE: Process the WM_SIZE message
1096//
1097void OnStatusbarSize(HWND hWnd, UINT state, int cx, int cy)
1098{
1099    // Get the Statusbar control handle which was previously stored in the 
1100    // user data associated with the parent window.
1101    HWND hStatusbar = (HWND)GetWindowLongPtr(hWnd, GWLP_USERDATA);
1102
1103    // Partition the statusbar here to keep the ratio of the sizes of its 
1104    // parts constant. Each part is set by specifing the coordinates of the 
1105    // right edge of each part. -1 signifies the rightmost part of the parent.
1106    int nHalf = cx / 2;
1107    int nParts[] = { nHalf, nHalf + nHalf / 3, nHalf + nHalf * 2 / 3, -1 };
1108    SendMessage(hStatusbar, SB_SETPARTS, 4, (LPARAM)&nParts);
1109
1110    // Resize statusbar so it's always same width as parent's client area
1111    SendMessage(hStatusbar, WM_SIZE, 0, 0);
1112}
1113
1114//
1115//   FUNCTION: OnInitStatusbarDialog(HWND, HWND, LPARAM)
1116//
1117//   PURPOSE: Process the WM_INITDIALOG message
1118//
1119BOOL OnInitStatusbarDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
1120{
1121    // Load and register IPAddress control class
1122    INITCOMMONCONTROLSEX iccx;
1123    iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
1124    iccx.dwICC = ICC_BAR_CLASSES;
1125    if (!InitCommonControlsEx(&iccx))
1126        return FALSE;
1127
1128    // Create the status bar control
1129    RECT rc = { 0, 0, 0, 0 };
1130    HWND hStatusbar = CreateWindowEx(0, STATUSCLASSNAME, 0, 
1131        SBARS_SIZEGRIP | WS_CHILD | WS_VISIBLE, 
1132        rc.left, rc.top, rc.right, rc.bottom, 
1133        hWnd, (HMENU)IDC_STATUSBAR, g_hInst, 0);
1134
1135    // Store the statusbar control handle as the user data associated with 
1136    // the parent window so that it can be retrieved for later use.
1137    SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)hStatusbar);
1138
1139    // Establish the number of partitions or 'parts' the status bar will 
1140    // have, their actual dimensions will be set in the parent window's 
1141    // WM_SIZE handler.
1142    GetClientRect(hWnd, &rc);
1143    int nHalf = rc.right / 2;
1144    int nParts[4] = { nHalf, nHalf + nHalf / 3, nHalf + nHalf * 2 / 3, -1 };
1145    SendMessage(hStatusbar, SB_SETPARTS, 4, (LPARAM)&nParts);
1146
1147    // Put some texts into each part of the status bar and setup each part
1148    SendMessage(hStatusbar, SB_SETTEXT, 0, (LPARAM)L"Status Bar: Part 1");
1149    SendMessage(hStatusbar, SB_SETTEXT, 1| SBT_POPOUT, (LPARAM)L"Part 2");
1150    SendMessage(hStatusbar, SB_SETTEXT, 2| SBT_POPOUT, (LPARAM)L"Part 3");
1151    SendMessage(hStatusbar, SB_SETTEXT, 3| SBT_POPOUT, (LPARAM)L"Part 4");
1152
1153    return TRUE;
1154}
1155
1156//
1157//  FUNCTION: StatusbarDlgProc(HWND, UINT, WPARAM, LPARAM)
1158//
1159//  PURPOSE:  Processes messages for the Statusbar control dialog.
1160//
1161//
1162INT_PTR CALLBACK StatusbarDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1163{
1164    switch (message)
1165    {
1166        // Handle the WM_INITDIALOG message in OnInitStatusbarDialog
1167        HANDLE_MSG (hWnd, WM_INITDIALOG, OnInitStatusbarDialog);
1168
1169        // Handle the WM_CLOSE message in OnClose
1170        HANDLE_MSG (hWnd, WM_CLOSE, OnClose);
1171
1172        // Handle the WM_SIZE message in OnStatusbarSize
1173        HANDLE_MSG (hWnd, WM_SIZE, OnStatusbarSize);
1174
1175    default:
1176        return FALSE;	// Let system deal with msg
1177    }
1178    return 0;
1179}
1180
1181#pragma endregion
1182
1183
1184#pragma region Progress
1185// MSDN: Progress Bar
1186// http://msdn.microsoft.com/en-us/library/bb760818.aspx
1187
1188#define IDC_PROGRESSBAR		12990
1189
1190//
1191//   FUNCTION: OnInitProgressDialog(HWND, HWND, LPARAM)
1192//
1193//   PURPOSE: Process the WM_INITDIALOG message
1194//
1195BOOL OnInitProgressDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
1196{
1197    // Load and register Progress control class
1198    INITCOMMONCONTROLSEX iccx;
1199    iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
1200    iccx.dwICC = ICC_PROGRESS_CLASS;
1201    if (!InitCommonControlsEx(&iccx))
1202        return FALSE;
1203
1204    // Create the progress bar control
1205    RECT rc = { 20, 20, 250, 20 };
1206    HWND hProgress = CreateWindowEx(0, PROGRESS_CLASS, 0, 
1207        WS_CHILD | WS_VISIBLE, rc.left, rc.top, rc.right, rc.bottom, 
1208        hWnd, (HMENU)IDC_PROGRESSBAR, g_hInst, 0);
1209
1210    // Set the progress bar position to half-way
1211    SendMessage(hProgress, PBM_SETPOS, 50, 0);
1212
1213    return TRUE;
1214}
1215
1216//
1217//  FUNCTION: ProgressDlgProc(HWND, UINT, WPARAM, LPARAM)
1218//
1219//  PURPOSE:  Processes messages for the Progress control dialog.
1220//
1221//
1222INT_PTR CALLBACK ProgressDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1223{
1224    switch (message)
1225    {
1226        // Handle the WM_INITDIALOG message in OnInitProgressDialog
1227        HANDLE_MSG (hWnd, WM_INITDIALOG, OnInitProgressDialog);
1228
1229        // Handle the WM_CLOSE message in OnClose
1230        HANDLE_MSG (hWnd, WM_CLOSE, OnClose);
1231
1232    default:
1233        return FALSE;	// Let system deal with msg
1234    }
1235    return 0;
1236}
1237
1238#pragma endregion
1239
1240
1241#pragma region Toolbar
1242// MSDN: Toolbar
1243// http://msdn.microsoft.com/en-us/library/bb760435.aspx
1244
1245#define IDC_TOOLBAR			13990
1246
1247//
1248//   FUNCTION: OnInitToolbarDialog(HWND, HWND, LPARAM)
1249//
1250//   PURPOSE: Process the WM_INITDIALOG message
1251//
1252BOOL OnInitToolbarDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
1253{
1254    // Load and register Toolbar control class
1255    INITCOMMONCONTROLSEX iccx;
1256    iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
1257    iccx.dwICC = ICC_BAR_CLASSES;
1258    if (!InitCommonControlsEx(&iccx))
1259        return FALSE;
1260
1261    // Create the Toolbar control
1262    RECT rc = { 0, 0, 0, 0 };
1263    HWND hToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, 0, 
1264        TBSTYLE_FLAT | CCS_ADJUSTABLE | CCS_NODIVIDER | WS_CHILD | WS_VISIBLE, 
1265        rc.left, rc.top, rc.right, rc.bottom, 
1266        hWnd, (HMENU)IDC_TOOLBAR, g_hInst, 0);
1267
1268
1269    /////////////////////////////////////////////////////////////////////////
1270    // Setup and add buttons to Toolbar.
1271    // 
1272
1273    // If an application uses the CreateWindowEx function to create the 
1274    // toolbar, the application must send this message to the toolbar before 
1275    // sending the TB_ADDBITMAP or TB_ADDBUTTONS message. The CreateToolbarEx 
1276    // function automatically sends TB_BUTTONSTRUCTSIZE, and the size of the 
1277    // TBBUTTON structure is a parameter of the function.
1278    SendMessage(hToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
1279
1280    // Add images
1281
1282    TBADDBITMAP tbAddBmp = {0};
1283    tbAddBmp.hInst = HINST_COMMCTRL;
1284    tbAddBmp.nID = IDB_STD_SMALL_COLOR;
1285
1286    SendMessage(hToolbar, TB_ADDBITMAP, 0, (WPARAM)&tbAddBmp);
1287
1288    // Add buttons
1289
1290    const int numButtons = 7;
1291    TBBUTTON tbButtons[numButtons] = 
1292    {
1293        { MAKELONG(STD_FILENEW, 0), NULL, TBSTATE_ENABLED, 
1294        BTNS_AUTOSIZE, {0}, 0, (INT_PTR)L"New" },
1295        { MAKELONG(STD_FILEOPEN, 0), NULL, TBSTATE_ENABLED, 
1296        BTNS_AUTOSIZE, {0}, 0, (INT_PTR)L"Open" },
1297        { MAKELONG(STD_FILESAVE, 0), NULL, 0, 
1298        BTNS_AUTOSIZE, {0}, 0, (INT_PTR)L"Save" }, 
1299        { MAKELONG(0, 0), NULL, 0, 
1300        TBSTYLE_SEP, {0}, 0, (INT_PTR)L"" }, // Separator
1301        { MAKELONG(STD_COPY, 0), NULL, TBSTATE_ENABLED, 
1302        BTNS_AUTOSIZE, {0}, 0, (INT_PTR)L"Copy" }, 
1303        { MAKELONG(STD_CUT, 0), NULL, TBSTATE_ENABLED, 
1304        BTNS_AUTOSIZE, {0}, 0, (INT_PTR)L"Cut" }, 
1305        { MAKELONG(STD_PASTE, 0), NULL, TBSTATE_ENABLED, 
1306        BTNS_AUTOSIZE, {0}, 0, (INT_PTR)L"Paste" }
1307    };
1308
1309    SendMessage(hToolbar, TB_ADDBUTTONS, numButtons, (LPARAM)tbButtons);
1310
1311    // Tell the toolbar to resize itself, and show it.
1312    SendMessage(hToolbar, TB_AUTOSIZE, 0, 0); 
1313
1314    return TRUE;
1315}
1316
1317//
1318//  FUNCTION: ToolbarDlgProc(HWND, UINT, WPARAM, LPARAM)
1319//
1320//  PURPOSE:  Processes messages for the Toolbar control dialog.
1321//
1322//
1323INT_PTR CALLBACK ToolbarDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1324{
1325    switch (message)
1326    {
1327        // Handle the WM_INITDIALOG message in OnInitToolbarDialog
1328        HANDLE_MSG (hWnd, WM_INITDIALOG, OnInitToolbarDialog);
1329
1330        // Handle the WM_CLOSE message in OnClose
1331        HANDLE_MSG (hWnd, WM_CLOSE, OnClose);
1332
1333    default:
1334        return FALSE;	// Let system deal with msg
1335    }
1336    return 0;
1337}
1338
1339#pragma endregion
1340
1341
1342#pragma region Trackbar
1343// MSDN: Trackbar
1344// http://msdn.microsoft.com/en-us/library/bb760145.aspx
1345
1346#define IDC_TRACKBAR			14990
1347
1348//
1349//   FUNCTION: OnInitTrackbarDialog(HWND, HWND, LPARAM)
1350//
1351//   PURPOSE: Process the WM_INITDIALOG message
1352//
1353BOOL OnInitTrackbarDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
1354{
1355    // Load and register Trackbar control class
1356    INITCOMMONCONTROLSEX iccx;
1357    iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
1358    iccx.dwICC = ICC_WIN95_CLASSES; // Or ICC_PROGRESS_CLASS
1359    if (!InitCommonControlsEx(&iccx))
1360        return FALSE;
1361
1362    // Create the Trackbar control
1363    RECT rc = { 20, 20, 250, 20 };
1364    HWND hTrackbar = CreateWindowEx(0, TRACKBAR_CLASS, 0, 
1365        TBS_AUTOTICKS | WS_CHILD | WS_VISIBLE, 
1366        rc.left, rc.top, rc.right, rc.bottom, 
1367        hWnd, (HMENU)IDC_TRACKBAR, g_hInst, 0);
1368
1369    // Set Trackbar range
1370    SendMessage(hTrackbar, TBM_SETRANGE, 0, MAKELONG(0, 20));
1371
1372    return TRUE;
1373}
1374
1375//
1376//  FUNCTION: TrackbarDlgProc(HWND, UINT, WPARAM, LPARAM)
1377//
1378//  PURPOSE:  Processes messages for the Trackbar control dialog.
1379//
1380//
1381INT_PTR CALLBACK TrackbarDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1382{
1383    switch (message)
1384    {
1385        // Handle the WM_INITDIALOG message in OnInitTrackbarDialog
1386        HANDLE_MSG (hWnd, WM_INITDIALOG, OnInitTrackbarDialog);
1387
1388        // Handle the WM_CLOSE message in OnClose
1389        HANDLE_MSG (hWnd, WM_CLOSE, OnClose);
1390
1391    default:
1392        return FALSE;	// Let system deal with msg
1393    }
1394    return 0;
1395}
1396
1397#pragma endregion
1398
1399
1400#pragma region SysLink
1401// MSDN: SysLink
1402// http://msdn.microsoft.com/en-us/library/bb760704.aspx
1403
1404#define IDC_SYSLINK			15990
1405
1406//
1407//   FUNCTION: OnInitSysLinkDialog(HWND, HWND, LPARAM)
1408//
1409//   PURPOSE: Process the WM_INITDIALOG message
1410//
1411BOOL OnInitSysLinkDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
1412{
1413    // Load and register SysLink control class
1414    INITCOMMONCONTROLSEX iccx;
1415    iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
1416    iccx.dwICC = ICC_LINK_CLASS;
1417    if (!InitCommonControlsEx(&iccx))
1418        return FALSE;
1419
1420    // Create the SysLink control
1421    // The SysLink control supports the anchor tag(<a>) along with the 
1422    // attributes HREF and ID. 
1423    RECT rc = { 20, 20, 500, 100 };
1424    HWND hLink = CreateWindowEx(0, WC_LINK, 
1425        L"All-In-One Code Framework\n" \
1426        L"<A HREF=\"http://cfx.codeplex.com\">Home</A> " \
1427        L"and <A ID=\"idBlog\">Blog</A>", 
1428        WS_VISIBLE | WS_CHILD | WS_TABSTOP, 
1429        rc.left, rc.top, rc.right, rc.bottom, 
1430        hWnd, (HMENU)IDC_SYSLINK, g_hInst, NULL);
1431
1432    return TRUE;
1433}
1434
1435//
1436//   FUNCTION: OnSysLinkNotify(HWND, int, PNMLINK)
1437//
1438//   PURPOSE: Process the WM_NOTIFY message
1439//
1440LRESULT OnSysLinkNotify(HWND hWnd, int idCtrl, LPNMHDR pNMHdr)
1441{
1442    if (idCtrl != IDC_SYSLINK)	// Make sure that it is the SysLink control
1443        return 0;
1444
1445    // The notifications associated with SysLink controls are NM_CLICK 
1446    // (syslink) and (for links that can be activated by the Enter key) 
1447    // NM_RETURN.
1448    switch (pNMHdr->code)
1449    {
1450    case NM_CLICK:
1451    case NM_RETURN:
1452        {
1453            PNMLINK pNMLink = (PNMLINK)pNMHdr;
1454            LITEM item = pNMLink->item;
1455
1456            // Judging by the index of the link
1457            if (item.iLink == 0) // If it is the first link
1458            {
1459                ShellExecute(NULL, L"open", item.szUrl, NULL, NULL, SW_SHOW);
1460            }
1461            // Judging by the ID of the link
1462            else if (wcscmp(item.szID, L"idBlog") == 0)
1463            {
1464                MessageBox(hWnd, L"http://blogs.msdn.com/codefx", 
1465                    L"All-In-One Code Framework Blog", MB_OK);
1466            }
1467            break;
1468        }
1469    }
1470    return 0;
1471}
1472
1473//
1474//  FUNCTION: SysLinkDlgProc(HWND, UINT, WPARAM, LPARAM)
1475//
1476//  PURPOSE:  Processes messages for the SysLink control dialog.
1477//
1478//
1479INT_PTR CALLBACK SysLinkDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1480{
1481    switch (message)
1482    {
1483        // Handle the WM_INITDIALOG message in OnInitSysLinkDialog
1484        HANDLE_MSG (hWnd, WM_INITDIALOG, OnInitSysLinkDialog);
1485
1486        // Handle the WM_CLOSE message in OnClose
1487        HANDLE_MSG (hWnd, WM_CLOSE, OnClose);
1488
1489        // Handle the WM_NOTIFY message in OnNotify
1490        HANDLE_MSG (hWnd, WM_NOTIFY, OnSysLinkNotify);
1491
1492    default:
1493        return FALSE;	// Let system deal with msg
1494    }
1495    return 0;
1496}
1497
1498#pragma endregion
1499
1500
1501#pragma region Rebar
1502// MSDN: Rebar
1503// http://msdn.microsoft.com/en-us/library/bb774375.aspx
1504
1505#define IDC_REBAR			16990
1506
1507//
1508//   FUNCTION: OnInitRebarDialog(HWND, HWND, LPARAM)
1509//
1510//   PURPOSE: Process the WM_INITDIALOG message
1511//
1512BOOL OnInitRebarDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
1513{
1514    // Load and register Rebar control class
1515    INITCOMMONCONTROLSEX iccx;
1516    iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
1517    iccx.dwICC = ICC_COOL_CLASSES;
1518    if (!InitCommonControlsEx(&iccx))
1519        return FALSE;
1520
1521    // Create the Rebar control
1522    RECT rc = { 0, 0, 0, 0 };
1523    HWND hRebar = CreateWindowEx(0, REBARCLASSNAME, L"", 
1524        WS_VISIBLE | WS_CHILD | RBS_AUTOSIZE, 
1525        rc.left, rc.top, rc.right, rc.bottom, 
1526        hWnd, (HMENU)IDC_REBAR, g_hInst, NULL);
1527
1528    REBARINFO ri = {0};
1529    ri.cbSize = sizeof(REBARINFO);
1530    SendMessage(hRebar, RB_SETBARINFO, 0, (LPARAM)&ri);
1531
1532    // Insert a image
1533    HICON hImg = (HICON)LoadImage(0, IDI_QUESTION, IMAGE_ICON, 0, 0, LR_SHARED);
1534    HWND hwndImg = CreateWindow(L"STATIC", NULL, 
1535        WS_CHILD | WS_VISIBLE | SS_ICON | SS_REALSIZEIMAGE | SS_NOTIFY,
1536        0, 0, 0, 0, hRebar, (HMENU)NULL, g_hInst,	NULL);
1537
1538    // Set static control image
1539    SendMessage(hwndImg, STM_SETICON, (WPARAM)hImg, NULL);
1540
1541    REBARBANDINFO rbBand;
1542    rbBand.cbSize = sizeof(REBARBANDINFO);
1543    rbBand.fMask = RBBIM_STYLE | RBBIM_CHILDSIZE | RBBIM_CHILD | RBBIM_SIZE;
1544    rbBand.fStyle = RBBS_CHILDEDGE | RBBS_NOGRIPPER;
1545    rbBand.hwndChild = hwndImg;
1546    rbBand.cxMinChild = 0;
1547    rbBand.cyMinChild = 20;
1548    rbBand.cx = 20;
1549
1550    // Insert the img into the rebar
1551    SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand);
1552
1553    // Insert a blank band
1554    rbBand.cbSize = sizeof(REBARBANDINFO);
1555    rbBand.fMask =  RBBIM_STYLE | RBBIM_SIZE;
1556    rbBand.fStyle = RBBS_CHILDEDGE | RBBS_HIDETITLE | RBBS_NOGRIPPER;
1557    rbBand.cx = 1;
1558
1559    // Insert the blank band into the rebar
1560    SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand);
1561
1562    return TRUE;
1563}
1564
1565//
1566//  FUNCTION: RebarDlgProc(HWND, UINT, WPARAM, LPARAM)
1567//
1568//  PURPOSE:  Processes messages for the Rebar control dialog.
1569//
1570//
1571INT_PTR CALLBACK RebarDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1572{
1573    switch (message)
1574    {
1575        // Handle the WM_INITDIALOG message in OnInitRebarDialog
1576        HANDLE_MSG (hWnd, WM_INITDIALOG, OnInitRebarDialog);
1577
1578        // Handle the WM_CLOSE message in OnClose
1579        HANDLE_MSG (hWnd, WM_CLOSE, OnClose);
1580
1581    default:
1582        return FALSE;	// Let system deal with msg
1583    }
1584    return 0;
1585}
1586
1587#pragma endregion
1588
1589
1590#pragma region Main Window
1591
1592// 
1593//   FUNCTION: OnInitDialog(HWND, HWND, LPARAM)
1594//
1595//   PURPOSE: Process the WM_INITDIALOG message. 
1596//
1597BOOL OnInitDialog(HWND hWnd, HWND hwndFocus, LPARAM lParam)
1598{
1599    return TRUE;
1600}
1601
1602
1603//
1604//   FUNCTION: OnCommand(HWND, int, HWND, UINT)
1605//
1606//   PURPOSE: Process the WM_COMMAND message
1607//
1608void OnCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify)
1609{
1610    switch (id)
1611    {
1612    case IDC_BUTTON_ANIMATION:
1613        {
1614            HWND hDlg = CreateDialog(g_hInst, 
1615                MAKEINTRESOURCE(IDD_ANIMATIONDIALOG), 
1616                hWnd, AnimationDlgProc);
1617            if (hDlg)
1618            {
1619                ShowWindow(hDlg, SW_SHOW);
1620            }
1621        }
1622        break;
1623
1624    case IDC_BUTTON_COMBOBOXEX:
1625        {
1626            HWND hDlg = CreateDialog(g_hInst, 
1627                MAKEINTRESOURCE(IDD_COMBOBOXEXDIALOG), 
1628                hWnd, ComboBoxExDlgProc);
1629            if (hDlg)
1630            {
1631                ShowWindow(hDlg, SW_SHOW);
1632            }
1633        }
1634        break;
1635
1636    case IDC_BUTTON_DATETIMEPICK:
1637        {
1638            HWND hDlg = CreateDialog(g_hInst, 
1639                MAKEINTRESOURCE(IDD_DATETIMEPICKDIALOG), 
1640                hWnd, DateTimePickDlgProc);
1641            if (hDlg)
1642            {
1643                ShowWindow(hDlg, SW_SHOW);
1644            }
1645        }
1646        break;
1647
1648    case IDC_BUTTON_HEADER:
1649        {
1650            HWND hDlg = CreateDialog(g_hInst, 
1651                MAKEINTRESOURCE(IDD_HEADERDIALOG), 
1652 

Large files files are truncated, but you can click here to view the full file