How to implement function InitInstance() for class Derived from CDialog? MFC

1.7k Views Asked by At

I have a class:

include<afxwin.h>
include<Winuser.h>
include<Windows.h>


HWND hwndOwner;

class CChildView :public CDialog
{
    DECLARE_DYNAMIC(CChildView)

public:

CChildView();
~CChildView();
afx_msg void OnPaint();
afx_msg void OnLevelProf();
afx_msg void OnLevelAmat();
afx_msg void OnLevelBeg();
afx_msg void OnStepC();
void new_game();

virtual BOOL InitInstance();
//void CloseWindow();
BOOL PreCreateWindow(CREATESTRUCT& cs);
int end_analyze();
void ii();
unsigned long calculate(int id, int x, int y);
afx_msg void OnNewGame();
//void Invalidate();
afx_msg void OnX1010();
afx_msg void OnX1919();
afx_msg void OnX3030();
afx_msg void OnX5050();
afx_msg void OnX100100();
//MessageBoxW();
void resize_window();
afx_msg void OnLButtonDown(UINT, CPoint xy);
//void GetWindowRect(RECT);
//int MessageBoxW();
 void OnStepH();
void set_chеcked_menu(unsigned int old_id, unsigned int new_id);
DECLARE_MESSAGE_MAP()

};

How should I to implement the method InitInstance to my app not to Catch a NUllReferenceExeption in AfxWinMAin()? That what i have now:

CChildView obj;

BOOL CChildView::InitInstance()
{
    INITCOMMONCONTROLSEX InitCtrls;
    InitCtrls.dwSize = sizeof(InitCtrls);
    InitCtrls.dwICC = ICC_WIN95_CLASSES;
    InitCommonControlsEx(&InitCtrls);

    obj.Create(L"dsa", nullptr);

    return FALSE;
}

I made an oj in order to this

How to get rid of null reference

1

There are 1 best solutions below

0
On

You are asking the wrong question. You are required to implement InitInstance as a member of your CWinApp class (or CWinAppEx). See my answer to your previous question for an easy way to create a dialog-based MFC application that will build and run first try.