Willem-Aart
Willem-Aart

Reputation: 2440

Secondary window in MFC application

I'm trying to add a secondary window to my MFC application. This is what I wrote for showing the main window:

Header:

class CMyApp : public CWinApp
{
public:
    virtual BOOL InitInstance ();

};

class CMainWindow : public CFrameWnd
{
public:
    CMainWindow (char *p_mchar);
protected:
    afx_msg void OnPaint ();
    DECLARE_MESSAGE_MAP();
};

Source file:

#include <afxwin.h>
#include <afxmt.h>
#include "mfc0.h"
#include <string.h>

CMyApp myApp;

BOOL CMyApp::InitInstance ()
{
    m_pMainWnd = new CMainWindow("Test 1");
    m_pMainWnd->ShowWindow (m_nCmdShow);
    m_pMainWnd->UpdateWindow ();
    return TRUE;
}

BEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd)
    ON_WM_PAINT ()
END_MESSAGE_MAP ()

CMainWindow::CMainWindow (char *p_mchar)
{
    Create (NULL, L"mfc0");
}

void CMainWindow::OnPaint ()
{
    CPaintDC dc (this);
    CMainWindow* hwnd = this;
}

I assume that adding another CFrameWnd is the way to go, but I can't figure out how to show that window in the application. I can't use m_pMainWnd twice, right? There must be a simple solution, but I'm a bit lost here.

Upvotes: 0

Views: 177

Answers (1)

ScottMcP-MVP
ScottMcP-MVP

Reputation: 10415

If you want to do painting on the second window then creating another CFrameWnd is a good way to go. Just add a member variable to your CWinApp derived class, like m_pSecondWindow. If you want controls on the second window then a modelesss dialog is a better way to go.

Upvotes: 1

Related Questions