【问题标题】:Secondary window in MFC applicationMFC 应用程序中的辅助窗口
【发布时间】:2015-01-22 13:15:22
【问题描述】:

我正在尝试向我的 MFC 应用程序添加辅助窗口。这是我为显示主窗口而写的:

标题:

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

源文件:

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

我认为添加另一个 CFrameWnd 是可行的方法,但我不知道如何在应用程序中显示该窗口。我不能使用 m_pMainWnd 两次,对吧?必须有一个简单的解决方案,但我在这里有点迷失了。

【问题讨论】:

    标签: c++ mfc window frame


    【解决方案1】:

    如果您想在第二个窗口上进行绘画,那么创建另一个 CFrameWnd 是一个不错的方法。只需将成员变量添加到您的 CWinApp 派生类,例如 m_pSecondWindow。如果您想在第二个窗口上进行控制,那么无模式对话框是更好的选择。

    【讨论】:

    • 谢谢!通过添加“CSecondWindow *m_pSecondWnd;”得到这个工作。
    猜你喜欢
    • 2020-02-25
    • 1970-01-01
    • 1970-01-01
    • 2012-01-26
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-15
    相关资源
    最近更新 更多