1 // This is a part of the Microsoft Foundation Classes C++ library.
2 // Copyright (C) Microsoft Corporation
3 // All rights reserved.
5 // This source code is only intended as a supplement to the
6 // Microsoft Foundation Classes Reference and related
7 // electronic documentation provided with the library.
8 // See these sources for detailed information regarding the
9 // Microsoft Foundation Classes product.
11 // CWnd support for MFC Control containment (Feature Pack controls)
16 #include "afxctrlcontainer.h"
18 #include "afxtagmanager.h"
19 #include "afxbutton.h"
20 #include "afxcolorbutton.h"
21 #include "afxeditbrowsectrl.h"
22 #include "afxfontcombobox.h"
23 #include "afxlinkctrl.h"
24 #include "afxmaskededit.h"
25 #include "afxmenubutton.h"
26 #include "afxpropertygridctrl.h"
27 #include "afxshelllistctrl.h"
28 #include "afxshelltreectrl.h"
29 #include "afxvslistbox.h"
32 ////////////////////////////////////////////////////////////////////////////
34 #if (_MSC_VER == 1700)
35 void AfxDoRegisterMFCControlClass(LPCTSTR lpszClassName
, LPCTSTR lpszBaseClassName
)
37 static void DoRegisterWindowClass(LPCTSTR lpszClassName
, LPCTSTR lpszBaseClassName
)
40 ASSERT(lpszClassName
!= NULL
);
41 ASSERT(lpszBaseClassName
!= NULL
);
45 HINSTANCE hInst
= AfxGetInstanceHandle();
46 #if (_MSC_VER == 1700)
47 if (!GetClassInfo(hInst
, lpszBaseClassName
, &wnd
))
49 if (!AfxCtxGetClassInfo(hInst
, lpszBaseClassName
, &wnd
))
52 wnd
.style
= CS_DBLCLKS
;
53 wnd
.hInstance
= hInst
;
54 wnd
.lpfnWndProc
= ::DefWindowProc
;
57 wnd
.lpszClassName
= lpszClassName
;
58 AfxRegisterClass(&wnd
);
61 #if (_MSC_VER == 1600)
62 void AfxRegisterMFCCtrlClasses()
64 DoRegisterWindowClass(_T("MFCButton"), WC_BUTTON
);
65 DoRegisterWindowClass(_T("MFCColorButton"), WC_BUTTON
);
66 DoRegisterWindowClass(_T("MFCEditBrowse"), WC_EDIT
);
67 DoRegisterWindowClass(_T("MFCFontComboBox"), WC_COMBOBOX
);
68 DoRegisterWindowClass(_T("MFCLink"), WC_BUTTON
);
69 DoRegisterWindowClass(_T("MFCMaskedEdit"), WC_EDIT
);
70 DoRegisterWindowClass(_T("MFCMenuButton"), WC_BUTTON
);
71 DoRegisterWindowClass(_T("MFCPropertyGrid"), WC_STATIC
);
72 DoRegisterWindowClass(_T("MFCShellList"), WC_LISTVIEW
);
73 DoRegisterWindowClass(_T("MFCShellTree"), WC_TREEVIEW
);
74 DoRegisterWindowClass(_T("MFCVSListBox"), WC_STATIC
);
78 ////////////////////////////////////////////////////////////////////////////
79 // CMFCControlContainer
81 CMFCControlContainer::CMFCControlContainer(CWnd
* pWnd
) : m_pWnd(pWnd
)
85 CMFCControlContainer::~CMFCControlContainer()
87 FreeSubclassedControls();
91 #if (_MSC_VER == 1600)
92 BOOL
CMFCControlContainer::SubclassDlgControls()
94 if (m_pWnd
->GetSafeHwnd() != NULL
)
96 // Subclass Feature Pack controls:
97 CWnd
* pWndChild
= m_pWnd
->GetWindow(GW_CHILD
);
98 while (pWndChild
!= NULL
)
100 ASSERT_VALID(pWndChild
);
102 TCHAR lpszClassName
[MAX_CLASS_NAME
+ 1];
104 ::GetClassName(pWndChild
->GetSafeHwnd(), lpszClassName
, MAX_CLASS_NAME
);
105 CWnd
* pWndSubclassedCtrl
= CreateDlgControl(lpszClassName
);
107 if (pWndSubclassedCtrl
!= NULL
)
109 m_arSubclassedCtrls
.Add((CObject
*)pWndSubclassedCtrl
);
110 pWndSubclassedCtrl
->SubclassWindow(pWndChild
->GetSafeHwnd());
113 pWndChild
= pWndChild
->GetNextWindow();
123 void CMFCControlContainer::FreeSubclassedControls()
125 // Free subclassed controls:
126 for (int i
= 0; i
< m_arSubclassedCtrls
.GetCount(); i
++)
128 if (m_arSubclassedCtrls
[i
] != NULL
)
130 delete m_arSubclassedCtrls
[i
];
133 m_arSubclassedCtrls
.RemoveAll();
136 CWnd
* CMFCControlContainer::CreateDlgControl(LPCTSTR lpszClassName
)
138 ASSERT(m_pWnd
->GetSafeHwnd() != NULL
);
140 if (lpszClassName
!= NULL
)
142 CString strClass
= lpszClassName
;
143 CWnd
* pWndSubclassedCtrl
= NULL
;
145 if (strClass
== _T("MFCButton"))
147 pWndSubclassedCtrl
= new CMFCButton
;
149 else if (strClass
== _T("MFCColorButton"))
151 pWndSubclassedCtrl
= new CMFCColorButton
;
153 else if (strClass
== _T("MFCEditBrowse"))
155 pWndSubclassedCtrl
= new CMFCEditBrowseCtrl
;
157 else if (strClass
== _T("MFCFontComboBox"))
159 pWndSubclassedCtrl
= new CMFCFontComboBox
;
161 else if (strClass
== _T("MFCLink"))
163 pWndSubclassedCtrl
= new CMFCLinkCtrl
;
165 else if (strClass
== _T("MFCMaskedEdit"))
167 pWndSubclassedCtrl
= new CMFCMaskedEdit
;
169 else if (strClass
== _T("MFCMenuButton"))
171 pWndSubclassedCtrl
= new CMFCMenuButton
;
173 else if (strClass
== _T("MFCPropertyGrid"))
175 pWndSubclassedCtrl
= new CMFCPropertyGridCtrl
;
177 else if (strClass
== _T("MFCShellList"))
179 pWndSubclassedCtrl
= new CMFCShellListCtrl
;
181 else if (strClass
== _T("MFCShellTree"))
183 pWndSubclassedCtrl
= new CMFCShellTreeCtrl
;
185 else if (strClass
== _T("MFCVSListBox"))
187 pWndSubclassedCtrl
= new CVSListBox
;
190 return pWndSubclassedCtrl
;
196 BOOL
CMFCControlContainer::IsSubclassedFeaturePackControl(HWND hWndCtrl
)
198 if (hWndCtrl
== NULL
)
203 for (int i
= 0; i
< m_arSubclassedCtrls
.GetCount(); i
++)
205 CWnd
* pWnd
= (CWnd
*)m_arSubclassedCtrls
[i
];
206 if (pWnd
->GetSafeHwnd() == hWndCtrl
)
215 #if (_MSC_VER == 1600)
216 void CMFCControlContainer::PreUnsubclassControl(CWnd
* pControl
)
218 UNREFERENCED_PARAMETER(pControl
);
220 // CMFCShellListCtrl* pListCtrl = DYNAMIC_DOWNCAST(CMFCShellListCtrl, pControl);
221 // if (pListCtrl != NULL && pListCtrl->GetHeaderCtrl().GetSafeHwnd() != NULL)
223 // pListCtrl->GetHeaderCtrl().UnsubclassWindow();
228 BOOL
CMFCControlContainer::ReSubclassControl(HWND hWndCtrl
, WORD nIDC
, CWnd
& control
)
230 if (hWndCtrl
== NULL
)
236 for (int i
= 0; i
< m_arSubclassedCtrls
.GetCount(); i
++)
238 CWnd
* pWnd
= (CWnd
*)m_arSubclassedCtrls
[i
];
239 if (pWnd
->GetSafeHwnd() == hWndCtrl
)
248 CWnd
* pWnd
= DYNAMIC_DOWNCAST(CWnd
, m_arSubclassedCtrls
[nIndex
]);
250 if (pWnd
->GetSafeHwnd() != NULL
)
256 BYTE
* pbInitData
= NULL
;
257 GetControlData(nIDC
, dwSize
, pbInitData
);
259 // Free old subclassed control:
260 m_arSubclassedCtrls
[nIndex
] = NULL
;
263 PreUnsubclassControl(pWnd
);
264 VERIFY(pWnd
->UnsubclassWindow() == hWndCtrl
);
269 if (!control
.SubclassWindow(hWndCtrl
))
271 ASSERT(FALSE
); // possibly trying to subclass twice?
272 AfxThrowNotSupportedException();
278 control
.SendMessage(WM_MFC_INITCTRL
, (WPARAM
)dwSize
, (LPARAM
)pbInitData
);
288 void CMFCControlContainer::SetControlData(WORD nIDC
, DWORD dwSize
, BYTE
* pbData
)
290 CByteArray
* pArray
= new CByteArray
;
291 pArray
->SetSize(dwSize
);
293 BYTE
* pbBuffer
= pArray
->GetData();
294 if (memcpy_s(pbBuffer
, dwSize
, pbData
, dwSize
) != 0)
301 m_mapControlData
.SetAt(nIDC
, pArray
);
304 BOOL
CMFCControlContainer::GetControlData(WORD nIDC
, DWORD
& dwSize
, BYTE
*& pbData
)
306 CObject
* pData
= NULL
;
307 if (m_mapControlData
.Lookup(nIDC
, pData
) && pData
!= NULL
)
309 CByteArray
* pArray
= (CByteArray
*)pData
;
310 dwSize
= (DWORD
)pArray
->GetSize();
311 pbData
= pArray
->GetData();
318 void CMFCControlContainer::ClearControlData()
321 CObject
* pData
= NULL
;
322 POSITION pos
= m_mapControlData
.GetStartPosition();
325 m_mapControlData
.GetNextAssoc(pos
, nIDC
, pData
);
326 CByteArray
* pArray
= (CByteArray
*)pData
;
330 m_mapControlData
.RemoveAll();
333 #if (_MSC_VER == 1600)
335 ////////////////////////////////////////////////////////////////////////////
336 // Accessing dialog DLGINIT helpers
338 int __stdcall
CMFCControlContainer::UTF8ToString(LPCSTR lpSrc
, CString
& strDst
, int nLength
)
341 int count
= ::MultiByteToWideChar(CP_UTF8
, 0, lpSrc
, nLength
, NULL
, 0);
347 LPWSTR lpWide
= new WCHAR
[count
+ 1];
348 memset(lpWide
, 0, (count
+ 1) * sizeof(WCHAR
));
350 ::MultiByteToWideChar(CP_UTF8
, 0, lpSrc
, nLength
, lpWide
, count
);
355 count
= ::WideCharToMultiByte(::GetACP(), 0, lpWide
, -1, NULL
, 0, NULL
, 0);
359 lpDst
= new char[count
+ 1];
360 memset(lpDst
, 0, count
+ 1);
362 ::WideCharToMultiByte(::GetACP(), 0, lpWide
, -1, lpDst
, count
, NULL
, 0);
373 BOOL __stdcall
CMFCControlContainer::ReadBoolProp(CTagManager
& /*tagManager*/, LPCTSTR lpszTag
, BOOL
& bMember
)
381 // tagManager.ExcludeTag(lpszTag, str);
388 bMember
= (str
.CompareNoCase(PS_True
) == 0);