Проблема с запуском диалогового приложения
От: RussianFellow Россия http://russianfellow.livejournal.com
Дата: 04.06.20 10:18
Оценка:
Есть файл LunarMissionsOrbits.cpp для главного класса приложения и файл LunarMissionsOrbitsDlg.cpp для главного диалога приложения.
Вот эти файлы:

1) файл LunarMissionOrbits.h :

// LunarMissionOrbits.h : main header file for the PROJECT_NAME application
//

#pragma once

#ifndef __AFXWIN_H__
    #error "include 'stdafx.h' before including this file for PCH"
#endif

#include "resource.h"        // main symbols


// CLunarMissionsOrbitsApp:
// See LunarMissionsOrbits.cpp for the implementation of this class
//

class CLunarMissionsOrbitsApp : public CWinApp
{
public:
    CLunarMissionsOrbitsApp();

// Overrides
public:
    virtual BOOL InitInstance();

// Implementation

    DECLARE_MESSAGE_MAP()
};

extern CLunarMissionsOrbitsApp theApp;


2) файл LunarMissionOrbits.cpp :

// LunarMissionsOrbits.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "LunarMissionsOrbits.h"
#include "LunarMissionsOrbitsDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CLunarMissionOrbits2App

BEGIN_MESSAGE_MAP(CLunarMissionOrbits2App, CWinApp)
    ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()


// CLunarMissionsOrbitsApp construction

CLunarMissionsOrbitsApp::CLunarMissionsOrbitsApp()
{
    // support Restart Manager
    m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;

    // TODO: add construction code here,
    // Place all significant initialization in InitInstance
}


// The one and only CLunarMissionOrbits2App object

CLunarMissionsOrbitsApp theApp;


// CLunarMissionsOrbitsApp initialization

BOOL CLunarMissionsOrbitsApp::InitInstance()
{
    // InitCommonControlsEx() is required on Windows XP if an application
    // manifest specifies use of ComCtl32.dll version 6 or later to enable
    // visual styles.  Otherwise, any window creation will fail.
    INITCOMMONCONTROLSEX InitCtrls;
    InitCtrls.dwSize = sizeof(InitCtrls);
    // Set this to include all the common control classes you want to use
    // in your application.
    InitCtrls.dwICC = ICC_WIN95_CLASSES;
    InitCommonControlsEx(&InitCtrls);

    CWinApp::InitInstance();


    // Create the shell manager, in case the dialog contains
    // any shell tree view or shell list view controls.
    CShellManager *pShellManager = new CShellManager;

    // Standard initialization
    // If you are not using these features and wish to reduce the size
    // of your final executable, you should remove from the following
    // the specific initialization routines you do not need
    // Change the registry key under which our settings are stored
    // TODO: You should modify this string to be something appropriate
    // such as the name of your company or organization
    SetRegistryKey(_T("Local AppWizard-Generated Applications"));

    CLunarMissionsOrbitsDlg dlg;
    m_pMainWnd = &dlg;
    INT_PTR nResponse = dlg.DoModal();
    if (nResponse == IDOK)
    {
        // TODO: Place code here to handle when the dialog is
        //  dismissed with OK
    }
    else if (nResponse == IDCANCEL)
    {
        // TODO: Place code here to handle when the dialog is
        //  dismissed with Cancel
    }
        else if (nResponse == -1)
    {
        TRACE(traceAppMsg, 0, "Предупреждение. Не удалось создать диалоговое окно, поэтому работа приложения неожиданно завершена.\n");
        TRACE(traceAppMsg, 0, "Предупреждение. При использовании элементов управления MFC для диалогового окна невозможно #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS.\n");
    }
    // Delete the shell manager created above.
    if (pShellManager != NULL)
    {
        delete pShellManager;
    }

    // Since the dialog has been closed, return FALSE so that we exit the
    //  application, rather than start the application's message pump.
    return FALSE;
}


3) файл LunarMissionOrbitsDlg.h :

// LunarMissionOrbitsDlg.h : header file
//

#pragma once

#include "afxwin.h"
#include "afxbutton.h"
#include "Resource.h"
#include "stdafx.h"
#include "MyStatic.h"
#include "MyMFCButton.h"
#include "MyMFCButton2.h"

// CLunarMissionOrbitsDlg dialog
class CLunarMissionsOrbitsDlg : public CDialogEx
{
// Construction
public:
    CLunarMissionsOrbitsDlg(CWnd* pParent = NULL);    // standard constructor

// Dialog Data
    enum { IDD = IDD_LUNARMISSIONORBITS_DIALOG };

    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support


// Implementation
protected:
    HICON m_hIcon;

    // Generated message map functions
    virtual BOOL OnInitDialog();
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnPaint();
        afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
    afx_msg HCURSOR OnQueryDragIcon();
    DECLARE_MESSAGE_MAP()
public:
    HBRUSH  m_brush;
    CButton m_IDOK;
    //CMFCButton m_IDC_MFCBUTTON1;
    CMyMFCButton m_IDC_MFCBUTTON1;
    CMyMFCButton2 m_IDC_MFCBUTTON2;
    CMFCButton m_IDC_MFCBUTTON3;
    //CStatic m_IDC_STATIC1;
    //CStatic m_IDC_STATIC2;
    CMyStatic m_IDC_STATIC1;
    CMyStatic m_IDC_STATIC2;
    void  RedrawMFCButton(int i);
    afx_msg void OnBnClickedMfcbutton1();
    afx_msg void OnBnClickedMfcbutton2();
    afx_msg void OnBnClickedOk();
};


4) файл LunarMissionOrbitsDlg.cpp :

// LunarMissionOrbits2Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "LunarMissionOrbits2.h"
#include "LunarMissionOrbits2Dlg.h"
#include "afxdialogex.h"
#include "Satellite.h"
#include "MyMFCButton.h"
#include "MyMFCButton2.h"
#include "FlightToMoonDlg.h"
#include "FlightAroundMoonDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#pragma warning(disable : 4996)

// Диалоговое окно CAboutDlg используется для описания сведений о приложении

NewSatInit  st;
Satellite *sat;

// CAboutDlg dialog used for App About

class CAboutDlg : public CDialogEx
{
public:
    CAboutDlg();

// Dialog Data
    enum { IDD = IDD_ABOUTBOX };

    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

// Implementation
protected:
    DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()


// CLunarMissionOrbits2Dlg dialog




CLunarMissionsOrbitsDlg::CLunarMissionsOrbitsDlg(CWnd* pParent /*=NULL*/)
    : CDialogEx(CLunarMissionsOrbitsDlg::IDD, pParent)
{
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CLunarMissionsOrbitsDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
        DDX_Control(pDX, IDOK, m_IDOK);
    DDX_Control(pDX, IDC_MFCBUTTON1, m_IDC_MFCBUTTON1);
    DDX_Control(pDX, IDC_MFCBUTTON2, m_IDC_MFCBUTTON2);
    DDX_Control(pDX, IDC_MFCBUTTON3, m_IDC_MFCBUTTON3);
    DDX_Control(pDX, IDC_STATIC1, m_IDC_STATIC1);
    DDX_Control(pDX, IDC_STATIC2, m_IDC_STATIC2);
}

BEGIN_MESSAGE_MAP(CLunarMissionsOrbitsDlg, CDialogEx)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
        ON_WM_CTLCOLOR()
    ON_BN_CLICKED(IDC_MFCBUTTON1, &CLunarMissionsOrbitsDlg::OnBnClickedMfcbutton1)
    ON_BN_CLICKED(IDC_MFCBUTTON2, &CLunarMissionsOrbitsDlg::OnBnClickedMfcbutton2)
    ON_BN_CLICKED(IDOK, &CLunarMissionsOrbitsDlg::OnBnClickedOk)
END_MESSAGE_MAP()


// CLunarMissionOrbits2Dlg message handlers

BOOL CLunarMissionsOrbitsDlg::OnInitDialog()
{
        CFont  *pfont1, *pfont2, *pfont3, *pfont4, *pfont5, *pfont6;
    LOGFONT  lf1, lf2, lf3;

    CDialogEx::OnInitDialog();

    // Add "About..." menu item to system menu.

    // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);

    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
        BOOL bNameValid;
        CString strAboutMenu;
        bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
        ASSERT(bNameValid);
        if (!strAboutMenu.IsEmpty())
        {
            pSysMenu->AppendMenu(MF_SEPARATOR);
            pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
        }
    }

    // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);            // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon

    // TODO: Add extra initialization here
            //m_IDC_MFCBUTTON1.pMFCButton2 = &m_IDC_MFCBUTTON2;
    //m_IDC_MFCBUTTON2.pMFCButton = &m_IDC_MFCBUTTON1;
    //m_IDC_MFCBUTTON1.pDialog = this;
    //m_IDC_MFCBUTTON2.pDialog = this;
    memset(&lf1,0,sizeof(lf1));
    lf1.lfHeight = 40;
    lf1.lfWidth = 10;
    lf1.lfWeight = FW_BOLD;
    lf1.lfCharSet = ANSI_CHARSET;
    lf1.lfOutPrecision = OUT_DEFAULT_PRECIS;
    lf1.lfClipPrecision = CLIP_DEFAULT_PRECIS;
    lf1.lfQuality = PROOF_QUALITY;
    lf1.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
    //strcpy(lf1.lfFaceName,"MS Sans Serif");
    wcscpy(lf1.lfFaceName,L"MS Sans Serif");
    pfont1 = new CFont();
    pfont1->CreateFontIndirect(&lf1);
    pfont2 = new CFont();
    pfont2->CreateFontIndirect(&lf1);
    m_IDC_STATIC1.SetFont(pfont1);
    m_IDC_STATIC2.SetFont(pfont2); 
    memset(&lf2,0,sizeof(lf2));
    lf2.lfHeight = 25;
    lf2.lfWidth = 10;
    lf2.lfWeight = FW_BOLD;
    lf2.lfCharSet = ANSI_CHARSET;
    lf2.lfOutPrecision = OUT_DEFAULT_PRECIS;
    lf2.lfClipPrecision = CLIP_DEFAULT_PRECIS;
    lf2.lfQuality = PROOF_QUALITY;
    lf2.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
    //strcpy(lf2.lfFaceName,"MS Sans Serif");
    wcscpy(lf2.lfFaceName,L"MS Sans Serif");
    pfont3 = new CFont();
    pfont3->CreateFontIndirect(&lf2);
    pfont4 = new CFont();
    pfont4->CreateFontIndirect(&lf2);
    pfont5 = new CFont();
    pfont5->CreateFontIndirect(&lf2);
    m_IDC_MFCBUTTON1.SetFont(pfont3);
    m_IDC_MFCBUTTON2.SetFont(pfont4);
    m_IDC_MFCBUTTON3.SetFont(pfont5);
    memset(&lf3,0,sizeof(lf3));
    lf3.lfHeight = 16;
    lf3.lfWidth = 6;
    lf3.lfWeight = FW_NORMAL;
    lf3.lfCharSet = ANSI_CHARSET;
    lf3.lfOutPrecision = OUT_DEFAULT_PRECIS;
    lf3.lfClipPrecision = CLIP_DEFAULT_PRECIS;
    lf3.lfQuality = PROOF_QUALITY;
    lf3.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
    //strcpy(lf3.lfFaceName,"MS Shell Dlg");
    wcscpy(lf3.lfFaceName,L"MS Shell Dlg");
    pfont6 = new CFont();
    pfont6->CreateFontIndirect(&lf3);
    m_IDOK.SetFont(pfont6);
    m_IDC_STATIC1.RedrawWindow();
    //m_IDC_STATIC1.UpdateWindow();
    m_IDC_STATIC2.RedrawWindow();
    //m_IDC_STATIC2.UpdateWindow();
    //m_IDC_MFCBUTTON1.RedrawWindow();
    return TRUE;  // return TRUE  unless you set the focus to a control
}

void CLunarMissionsOrbitsDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
        CAboutDlg dlgAbout;
        dlgAbout.DoModal();
    }
    else
    {
        CDialogEx::OnSysCommand(nID, lParam);
    }
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CLunarMissionsOrbitsDlg::OnPaint()
{
    if (IsIconic())
    {
        CPaintDC dc(this); // device context for painting

        SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

        // Center icon in client rectangle
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;

        // Draw the icon
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        CDialogEx::OnPaint();
    }
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CLunarMissionsOrbitsDlg::OnQueryDragIcon()
{
    return static_cast<HCURSOR>(m_hIcon);
}

HBRUSH CLunarMissionsOrbitsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    HBRUSH  hbr = CDialogEx::OnCtlColor(pDC,pWnd,nCtlColor);

    if ((pWnd->GetDlgCtrlID()==IDC_STATIC1)||(pWnd->GetDlgCtrlID()==IDC_STATIC2))
    {
        //pDC->SetTextColor(RGB(255,0,0));
        pDC->SetTextColor(RGB(162,21,10));
        pDC->SetBkMode(TRANSPARENT);
    }
    //if (pWnd->GetDlgCtrlID()==IDC_MFCBUTTON1)
    //{
        //hbr = CreateSolidBrush(RGB(12,149,210));
        //pDC->SelectObject(hbr);
        //pDC->SetBkColor(RGB(12,149,210));
        //pDC->SetBkMode(TRANSPARENT);
    //}
    //if (pWnd->GetDlgCtrlID()==IDC_MFCBUTTON3)
    //{
        //
    //}
    return  hbr;
}

void CLunarMissionsOrbitsDlg::OnBnClickedMfcbutton1()
// если была нажата кнопка "Участок перелёта Земля - Луна"
{
    // TODO: добавьте свой код обработчика уведомлений
    //CFlightToMoonDlg  flightToMoonDlg(this);
    CFlightToMoonDlg  flightToMoonDlg(NULL);
    flightToMoonDlg.DoModal();
}


void CLunarMissionsOrbitsDlg::OnBnClickedMfcbutton2()
{
    // TODO: добавьте свой код обработчика уведомлений
    //m_IDC_MFCBUTTON1.ispaint = true;
    //m_IDC_MFCBUTTON1.RedrawWindow();
    //CFlightAroundMoonDlg  flightAroundMoonDlg(this);
    CFlightAroundMoonDlg  flightAroundMoonDlg(NULL);
    flightAroundMoonDlg.DoModal();
}

void  CLunarMissionsOrbitsDlg::RedrawMFCButton(int i)
{
    if (i==1)
    {
        m_IDC_MFCBUTTON1.ispaint = true;
        //m_IDC_MFCBUTTON1.RedrawWindow();
        //m_IDC_MFCBUTTON1.UpdateWindow();
        m_IDC_MFCBUTTON1.UpdateData();
    }
    if (i==2)
    {
        m_IDC_MFCBUTTON2.ispaint = true;
        //m_IDC_MFCBUTTON2.RedrawWindow();
        //m_IDC_MFCBUTTON2.UpdateWindow();
        m_IDC_MFCBUTTON2.UpdateData();
    }
}


void CLunarMissionsOrbitsDlg::OnBnClickedOk()
{
    // TODO: добавьте свой код обработчика уведомлений
    /* m_IDC_MFCBUTTON1.ispaint = true;
    m_IDC_MFCBUTTON1.UpdateData();
    m_IDC_MFCBUTTON2.ispaint = true;
    m_IDC_MFCBUTTON2.UpdateData(); */
    CDialogEx::OnOK();
}


И при запуске программы в файле LunarMissionOrbits.cpp на строке

INT_PTR nResponse = dlg.DoModal();

значение nResponse становится равным -1, после чего отладчик попадает на

else if (nResponse == -1)
    {
        TRACE(traceAppMsg, 0, "Предупреждение. Не удалось создать диалоговое окно, поэтому работа приложения неожиданно завершена.\n");
        TRACE(traceAppMsg, 0, "Предупреждение. При использовании элементов управления MFC для диалогового окна невозможно #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS.\n");
    }


и выскакивает сообщение

Необработанное исключение по адресу 0x53A0D62C (mfc110ud.dll) в LunarMissionOrbits.exe:
0xC0000005: нарушение прав доступа при чтении по адресу 0xFEFEFF66 .


Что это означает? Как исправить эту ошибку?
(Проект был перенесён с другого компьютера, на котором стоит Visual Studio 2010--там всё нормально работает, а на этой машине Visual Studio 2012--и вот такие проблемы).
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.