我正在尝试向我的 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,对吗?必须有一个简单的解决方案,但我在这里有点迷路。
最佳答案
如果您想在第二个窗口上绘画,那么创建另一个 CFrameWnd 是一个不错的方法。只需向您的 CWinApp 派生类添加一个成员变量,例如 m_pSecondWindow。如果你想在第二个窗口上进行控制,那么无模式对话框是更好的选择。
关于c++ - MFC 应用程序中的辅助窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28089717/