I recently asked this question which got me started in the right direction - at least for loading the MFC DLL and trying to show a dlg box.
The problem is, the typical dialog box is horrible as a main window for an APP. It is quite simple for me to create a new exe project to do what I want, but the problem is that I have a DLL and the tools just don't seem to allow me to hook up the classes to the windows forms in the resource editor. Thus I can't seem to handle the events that I need.
My questions:
- How do I create and display a CFormView (based on an IDD_FORMVIEW I created in a resource editor) in an MFC DLL project?
- How do I get the form to show and to process input?
- How do I add event/message handlers for that window? (The menu item to do that from the .rc editor is greyed out)
- How do I set a menu to the formview? (the properties for the resource in the editor do not let me associate it with a menu resource. (I can't figure out why)
The links I have been looking at are pretty light and ambiguous about how to do it. Most of them assume I can create a mainframe as an MFC single document app via the "wizard" - which is not the case.
Right now I call Create() on the window class I made and pass in the CWnd of the desktop as the parent.
I am not sure I have subclassed the CFormView Correctly. In fact, I am pretty sure I have done little of what I need to do, though I tried to follow the instructions I have seen.
I then call ShowWindow(SW_SHOW), but I still see nothing.
I think this SHOULD be simple. All I want to do is show the form I created in the form editor.
How do I do that and what is the simplest way?
Here is some code - the cpp code that calls it
MainForm *mf = new MainForm();
mf->Create(CWnd::GetDesktopWindow());
mf->ShowWindow(SW_SHOW);
Here is the .h file for the MainForm class
#include "afxcmn.h"
// MainForm form view
class MainForm : public CFormView
{
DECLARE_DYNCREATE(MainForm)
public:
MainForm();
virtual ~MainForm();
public:
virtual BOOL Create(CWnd* pParent);
public:
enum { IDD = IDD_FORMVIEW_MAIN };
#ifdef _DEBUG
virtual void AssertValid() const;
#ifndef _WIN32_WCE
virtual void Dump(CDumpContext& dc) const;
#endif
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
public:
CListCtrl m_SymbolSetList;
};
and here is the cpp for MainForm
#include "stdafx.h"
#include "MainForm.h"
// MainForm
IMPLEMENT_DYNCREATE(MainForm, CFormView)
MainForm::MainForm()
: CFormView(MainForm::IDD)
{
}
MainForm::~MainForm()
{
}
void MainForm::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST_SYMBOLSETS, m_SymbolSetList);
}
BEGIN_MESSAGE_MAP(MainForm, CFormView)
END_MESSAGE_MAP()
// MainForm diagnostics
#ifdef _DEBUG
void MainForm::AssertValid() const
{
CFormView::AssertValid();
}
#ifndef _WIN32_WCE
void MainForm::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif
#endif //_DEBUG
BOOL MainForm::Create(CWnd* pParent)
{
CRect rect;
//pParent->GetClientRect(rect);
return CFormView::Create(NULL, NULL, WS_CHILD | WS_VISIBLE, rect, pParent, 0, NULL);
}