runtime class: from MFC to std C++

M

Mosfet

Hi,

I am trying to port an GUI application from MFC framework to WTL(Windows
Template Library).
MFC is using dynamic polumorphism while WTL makes use of static
polymorphism with lots of templated class.




My problem is about the view manager class.
This class is used to associate a view with an ID and to build it when
required.
This class was mainly composed of a static struct array defined like this

ViewMgr()


ViewMgr::ViewInfo g_ViewInfo[] =
{
{ CViewMgr::MAIN_VIEW, CViewMgr::CREATE_ONCE, IDR_MAINFRAME,
RUNTIME_CLASS(CMainView), NULL,0 },
{ CViewMgr::WELCOME_VIEW, CViewMgr::CREATE_AND_DESTROY,
IDR_MENU_OKCANCEL, RUNTIME_CLASS(CWelcomeView), NULL,0 },
...}


First field is an enum to identify the class,
the second specify if the view is persistent or not when switching to
another view,
the third is the Runtime class and this is this class that I would like
to port in std c++.
the firth is a pointeur to the base class CView.


When doing this port from MFC there were two differences :
1) I wanted to replace the struct array by a std::map
2) Some views are loaded at runtime(DLL) so I have declared an interface
called IDLLFormView and defined like this

struct IDLLFormView
{
virtual ~IDLLFormView() { } // we intend on deriving from this,
virtual HWND Initialize(HWND hParentWnd) = 0; // Use this to
initialize the object
virtual void Destroy() = 0; // Use this to destroy the object
virtual TCHAR* Description() = 0; // What this thing does
virtual HICON GetIcon(int nImageListType) = 0;
};
and views emebbded in thoses DLL exports 2 functions :

WTLDLG_API void GetPlugin( IDLLFormView** ppOutput );
WTLDLG_API LPCTSTR GetPluginName();



So now I am trying to write the new View manager and I got this

class CViewMgr : public CSingleton<CViewMgr>
{
public:
friend class CSingleton<CViewMgr>;

void Init();

protected:
map<LPCTSTR, IDLLFormView*> m_ViewMap;

private:
// Constructor
CViewMgr();
CViewMgr(CViewMgr const&);
virtual ~CViewMgr(void);
};

I have for now two classes that are inside my applications class
CModuleSelectionView and CExplorerView


class CModuleSelectionView :public IDLLFormView,
publicCDialogImpl<CModuleSelectionView>,public
CWinDataExchange<CModuleSelectionView>
{
....
}
class CExplorerView:public IDLLFormView,
publicCDialogImpl<CModuleSelectionView>,public
CWinDataExchange<CModuleSelectionView>
{
....
}

I you are still reading and you understand a bit what I wrote(and it's
not easy because I am not very clear), here is what I would like to know :


How could I handle views, some known at compile time and some others at
runtime.

For instance let's take my two views inside my applications
CExplorerView and CModuleSelectionView

in my ViewMgr init method how can I associate my views with my map ?
How can I construct them, destroy ...


void ViewMgr::Init()
{
// Init views known at runtime
m_ViewMap["Explorer"] = (IDLLFormView)&m_ExplorerView //???????????

}
 
M

Mosfet

Mosfet a écrit :
Hi,

I am trying to port an GUI application from MFC framework to WTL(Windows
Template Library).
MFC is using dynamic polumorphism while WTL makes use of static
polymorphism with lots of templated class.




My problem is about the view manager class.
This class is used to associate a view with an ID and to build it when
required.
This class was mainly composed of a static struct array defined like this

ViewMgr()


ViewMgr::ViewInfo g_ViewInfo[] =
{
{ CViewMgr::MAIN_VIEW, CViewMgr::CREATE_ONCE,
IDR_MAINFRAME, RUNTIME_CLASS(CMainView), NULL,0 },
{ CViewMgr::WELCOME_VIEW, CViewMgr::CREATE_AND_DESTROY,
IDR_MENU_OKCANCEL, RUNTIME_CLASS(CWelcomeView), NULL,0 },
..}


First field is an enum to identify the class,
the second specify if the view is persistent or not when switching to
another view,
the third is the Runtime class and this is this class that I would like
to port in std c++.
the firth is a pointeur to the base class CView.


When doing this port from MFC there were two differences :
1) I wanted to replace the struct array by a std::map
2) Some views are loaded at runtime(DLL) so I have declared an interface
called IDLLFormView and defined like this

struct IDLLFormView
{
virtual ~IDLLFormView() { } // we intend
on deriving from this,
virtual HWND Initialize(HWND hParentWnd) = 0; // Use this to
initialize the object
virtual void Destroy() = 0; // Use this
to destroy the object
virtual TCHAR* Description() = 0; // What
this thing does
virtual HICON GetIcon(int nImageListType) = 0;
};
and views emebbded in thoses DLL exports 2 functions :

WTLDLG_API void GetPlugin( IDLLFormView** ppOutput );
WTLDLG_API LPCTSTR GetPluginName();



So now I am trying to write the new View manager and I got this

class CViewMgr : public CSingleton<CViewMgr>
{
public:
friend class CSingleton<CViewMgr>;

void Init();

protected:
map<LPCTSTR, IDLLFormView*> m_ViewMap;

private:
// Constructor
CViewMgr();
CViewMgr(CViewMgr const&);
virtual ~CViewMgr(void);
};

I have for now two classes that are inside my applications class
CModuleSelectionView and CExplorerView


class CModuleSelectionView :public IDLLFormView,
publicCDialogImpl<CModuleSelectionView>,public
CWinDataExchange<CModuleSelectionView>
{
...
}
class CExplorerView:public IDLLFormView,
publicCDialogImpl<CModuleSelectionView>,public
CWinDataExchange<CModuleSelectionView>
{
...
}

I you are still reading and you understand a bit what I wrote(and it's
not easy because I am not very clear), here is what I would like to know :


How could I handle views, some known at compile time and some others at
runtime.

For instance let's take my two views inside my applications
CExplorerView and CModuleSelectionView

in my ViewMgr init method how can I associate my views with my map ?
How can I construct them, destroy ...


void ViewMgr::Init()
{
// Init views known at runtime
m_ViewMap["Explorer"] = (IDLLFormView)&m_ExplorerView //???????????

}
I am bit surprised but it seems to be possible to do that :

class CViewMgr : public CSingleton<CViewMgr>
{
public:
friend class CSingleton<CViewMgr>;

void Init();

protected:
map<LPCTSTR, IDLLFormView*> m_ViewMap;

// Class know at runtime -
CExplorerViewm_ExplorerView ;


private:
// Constructor
CViewMgr();
CViewMgr(CViewMgr const&);
virtual ~CViewMgr(void);
};

void ViewMgr::Init()
{
// Init views known at runtime
m_ViewMap["Explorer"] = (IDLLFormView)&m_ExplorerView;

}
 
R

red floyd

Mosfet said:
Hi,

I am trying to port an GUI application from MFC framework to WTL(Windows
Template Library).

May I suggest a Windows specific group?
 
S

Sam

Mosfet said:
in my ViewMgr init method how can I associate my views with my map ?
How can I construct them, destroy ...

There is no such class called "ViewMgr" in the C++ standard.

You are referring to Microsoft Windows-specific C++ classes and methods. Try
asking for help in a MS-specific newsgroup or a mailing list, where you're
more likely to get a meaningful answer.



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBHrc/Ux9p3GYHlUOIRAlP/AJ4g6qMwC/V4wsOI6PpgH8eYzvZC5gCcDBRC
0jpgKsllrnfCCSaayLOS2Gc=
=0hh3
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top