Bonjour je cherche à créer un template pour MDIChildWnd:

le.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
#pragma once
 
template <typename T>
class DefaultMDIChild : public CMDIChildWnd
{
	DECLARE_DYNCREATE(DefaultMDIChild<T>)
 
protected:
	//! @brief Constructeur protégé utilisé par la création dynamique
	DefaultMDIChild();
	//! @brief Destructeur
	virtual ~DefaultMDIChild();
	virtual void PostNcDestroy();
	DECLARE_MESSAGE_MAP()
 
public:
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	//! @brief Fonction de recuperation du pointeur de la form
	inline T* GetForm() { return form; }
 
private:
	T* form;	
};
le .cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
#include "stdafx.h"
#include "DefaultMDIChild.h"
 
 
// CFrmDeal
 
IMPLEMENT_DYNCREATE(DefaultMDIChild<T>, CMDIChildWnd)
 
template <typename T>
DefaultMDIChild<T>::DefaultMDIChild()
{
 
}
 
template <typename T>
DefaultMDIChild<T>::~DefaultMDIChild()
{
}
 
BEGIN_MESSAGE_MAP(DefaultMDIChild<T>, CMDIChildWnd)
	ON_WM_CREATE()
END_MESSAGE_MAP()
 
 
// Gestionnaires de messages de CFrmDeal
 
template <typename T>
int DefaultMDIChild<T>::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	form = new T();
	if(!form->Create(NULL,_T("Deal"), AFX_WS_DEFAULT_VIEW,CRect(0,0,0,0), this, AFX_IDW_PANE_FIRST, NULL))	
	{
		TRACE0("Impossible de créer la fenêtre d'affichage\n");
		return -1;
	}
 
	return 0;
}
 
template <typename T>
void DefaultMDIChild<T>::PostNcDestroy() {
    CMDIChildWnd::PostNcDestroy();
}
et evidement j'ai plein d erreur à cause des MACRO MFC:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
IMPLEMENT_DYNCREATE(DefaultMDIChild<T>, CMDIChildWnd)
 
BEGIN_MESSAGE_MAP(DefaultMDIChild<T>, CMDIChildWnd)
	ON_WM_CREATE()
END_MESSAGE_MAP()
 
	DECLARE_DYNCREATE(DefaultMDIChild<T>)
car elle n'aime pas trop le concept de template

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Error	3	error C2065: 'T' : undeclared identifier	c:\cc_fxtops_maint_evol\gr\fxtops\cpp\fxtops\defaultmdichild.cpp	8
Error	11	error C2143: syntax error : missing ';' before '{'	c:\cc_fxtops_maint_evol\gr\fxtops\cpp\fxtops\defaultmdichild.cpp	8
Error	1	error C2143: syntax error : missing ';' before '<'	c:\cc_fxtops_maint_evol\gr\fxtops\cpp\fxtops\defaultmdichild.h	6
Error	10	error C2143: syntax error : missing ';' before '<'	c:\cc_fxtops_maint_evol\gr\fxtops\cpp\fxtops\defaultmdichild.cpp	8
Error	2	error C2238: unexpected token(s) preceding ';'	c:\cc_fxtops_maint_evol\gr\fxtops\cpp\fxtops\defaultmdichild.h	6
Error	12	error C2447: '{' : missing function header (old-style formal list?)	c:\cc_fxtops_maint_evol\gr\fxtops\cpp\fxtops\defaultmdichild.cpp	8
Error	7	error C2509: '_GetBaseClass' : member function not declared in 'DefaultMDIChild'	c:\cc_fxtops_maint_evol\gr\fxtops\cpp\fxtops\defaultmdichild.cpp	8
Error	5	error C2509: 'CreateObject' : member function not declared in 'DefaultMDIChild'	c:\cc_fxtops_maint_evol\gr\fxtops\cpp\fxtops\defaultmdichild.cpp	8
Error	18	error C2509: 'GetMessageMap' : member function not declared in 'DefaultMDIChild'	c:\cc_fxtops_maint_evol\gr\fxtops\cpp\fxtops\defaultmdichild.cpp	21
Error	16	error C2509: 'GetRuntimeClass' : member function not declared in 'DefaultMDIChild'	c:\cc_fxtops_maint_evol\gr\fxtops\cpp\fxtops\defaultmdichild.cpp	8
Error	14	error C2509: 'GetThisClass' : member function not declared in 'DefaultMDIChild'	c:\cc_fxtops_maint_evol\gr\fxtops\cpp\fxtops\defaultmdichild.cpp	8
Error	20	error C2509: 'GetThisMessageMap' : member function not declared in 'DefaultMDIChild'	c:\cc_fxtops_maint_evol\gr\fxtops\cpp\fxtops\defaultmdichild.cpp	21
Error	4	error C2955: 'DefaultMDIChild' : use of class template requires template argument list	c:\cc_fxtops_maint_evol\gr\fxtops\cpp\fxtops\defaultmdichild.cpp	8
Error	6	error C2955: 'DefaultMDIChild' : use of class template requires template argument list	c:\cc_fxtops_maint_evol\gr\fxtops\cpp\fxtops\defaultmdichild.cpp	8
Error	8	error C2955: 'DefaultMDIChild' : use of class template requires template argument list	c:\cc_fxtops_maint_evol\gr\fxtops\cpp\fxtops\defaultmdichild.cpp	8
Error	13	error C2955: 'DefaultMDIChild' : use of class template requires template argument list	c:\cc_fxtops_maint_evol\gr\fxtops\cpp\fxtops\defaultmdichild.cpp	8
Error	15	error C2955: 'DefaultMDIChild' : use of class template requires template argument list	c:\cc_fxtops_maint_evol\gr\fxtops\cpp\fxtops\defaultmdichild.cpp	8
Error	17	error C2955: 'DefaultMDIChild' : use of class template requires template argument list	c:\cc_fxtops_maint_evol\gr\fxtops\cpp\fxtops\defaultmdichild.cpp	21
Error	19	error C2955: 'DefaultMDIChild' : use of class template requires template argument list	c:\cc_fxtops_maint_evol\gr\fxtops\cpp\fxtops\defaultmdichild.cpp	21
Warning	9	warning C4356: 'DefaultMDIChild<T>::classDefaultMDIChild' : static data member cannot be initialized via derived class	c:\cc_fxtops_maint_evol\gr\fxtops\cpp\fxtops\defaultmdichild.cpp	8
Première question, est ce possible de faire des templates avec MFC?
Si oui, comment?