- Open MainDlg.h, then comment out line 16 and
18 to activate the IDD macro.
#pragma once
#include "afxdialogex.h"
// CMainDlg dialog
class CMainDlg : public CDialog
{
DECLARE_DYNAMIC(CMainDlg)
public:
CMainDlg(CWnd* pParent = nullptr); // standard constructor
virtual ~CMainDlg();
// Dialog Data
//#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_MAIN };
//#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
};
- With the shortcut
Alt > P > Z
, or by selecting Project (P) > Class Wizard, open the Class Wizard.
-
Select CWinSockView as the Class name, go to the Virtual
Functions tab, type "init", and select OnInitialUpdate from the
Virtual function list, click Add function, then
Apply.
- Open WinSockView.h, declare the class name "CMainDlg" at line 6, and declare its
pointer-instance at lines
20-21.
// WinSockView.h : interface of the CWinSockView class
//
#pragma once
class CMainDlg;
class CWinSockView : public CView
{
// ...
// Implementation
public:
virtual ~CWinSockView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
private:
CMainDlg* m_pMainDlg;
// Generated message map functions
protected:
DECLARE_MESSAGE_MAP()
public:
virtual void OnInitialUpdate();
};
-
Open WinSockView.cpp, and add the necessary code inside the OnInitialUpdate()
function like at lines 8-13.
// CWinSockView message handlers
void CWinSockView::OnInitialUpdate()
{
CView::OnInitialUpdate();
if (m_pMainDlg == nullptr)
{
m_pMainDlg = new CMainDlg();
m_pMainDlg->Create(CMainDlg::IDD, this);
m_pMainDlg->ShowWindow(SW_NORMAL);
}
}