CFugue
InitCommonControls.h
1 #ifndef __INITCOMMONCONTROLS_H__83716747_6B45_4c0a_8B18_81C4751EA455_
2 #define __INITCOMMONCONTROLS_H__83716747_6B45_4c0a_8B18_81C4751EA455_
3 
4 #include <commctrl.h>
5 #pragma comment(lib, "comctl32.lib")
6 
7 /// <Summary>
8 /// Helper Class to ensure the initialization of Common Controls Library.
9 /// Add this as a Base Class for Your Control Class to Initialize the Common Control Library Automatically.
10 ///
11 /// Since this Class uses a local static variable in the constructor for the Library Initialization,
12 /// the InitCommonControlsEx() is called only once per App for all the derived class objects.
13 ///
14 /// Being a base class - this guarantees that the library is initialized before any derived class
15 /// functions are invoked.
16 ///
17 /// In case your control has multiple base classes, try to make the CInitCommonControls as the
18 /// first base class followed by the others. This makes sure that InitCommonControlsEx() is called
19 /// before any other dependent functions in other base classes are invoked.
20 /// </Summary>
21 /// <remarks>
22 /// Usage:
23 /// class MyClass: CInitCommonControls<ICC_LISTVIEW_CLASSES | ICC_TREEVIEW_CLASSES>
24 /// {
25 /// //...
26 /// }
27 /// </remarks>
28 
29 template<DWORD dwICC = ICC_WIN95_CLASSES>
31 {
32 
33 protected:
34 
35  /// Protected Constructor
36  inline CInitCommonControls(void)
37  {
38  ///
39  /// Helper Structure to Call the InitCommonControlsEx() function
40  ///
41  static struct _tagInitCommonControls
42  {
43  _tagInitCommonControls()
44  {
45  INITCOMMONCONTROLSEX icce;
46  icce.dwSize = sizeof(INITCOMMONCONTROLSEX);
47  icce.dwICC = dwICC; // Use the Template Argument for the Library Initialization
48  InitCommonControlsEx(&icce);
49  }
50  } DummyInitCommonControls; // Static Local Variable Gets initialized only once (for the first Object)
51  }
52 
53  /// Protected Destructor
54  inline ~CInitCommonControls(void)
55  {
56  }
57 
58 };
59 
60 #endif
CInitCommonControls(void)
Protected Constructor.
~CInitCommonControls(void)
Protected Destructor.

CFugue, the C++ Music Programming Library © Copyright 2009 Cenacle Research India Private Limited Gopalakrishna Palem