【问题标题】:How to implement function InitInstance() for class Derived from CDialog? MFC如何为从 CDialog 派生的类实现函数 InitInstance()? MFC
【发布时间】:2015-06-08 18:55:35
【问题描述】:

我有一堂课:

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()

};

我应该如何在我的应用程序中实现 InitInstance 方法而不是在 AfxWinMAin() 中捕获 NUllReferenceExeption?这就是我现在所拥有的:

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;
}

为此我做了一个oj

How to get rid of null reference

【问题讨论】:

  • 旁注:INIT'COMMON'CONTROL'SEX(对不起)
  • 可能是INITCOMMONCONTROLSEX InitCtrls = {}(用零初始化,但它是一个蓝色的镜头)
  • 我对你想要做什么感到困惑。 InitInstance 是 CWinApp 的子方法,不是,CDialog.
  • @rrirower: InitInstanceCWinThread 的成员。

标签: c++ visual-c++ mfc dialog


【解决方案1】:

你问错问题了。您需要将 InitInstance 实现为 CWinApp 类(或 CWinAppEx)的成员。请参阅我对您上一个问题的回答,了解一种创建基于对话框的 MFC 应用程序的简单方法,该应用程序将首先构建并运行。

【讨论】:

    猜你喜欢
    • 2020-01-30
    • 1970-01-01
    • 2019-07-16
    • 1970-01-01
    • 2011-05-16
    • 1970-01-01
    • 1970-01-01
    • 2022-01-05
    • 1970-01-01
    相关资源
    最近更新 更多