【发布时间】:2017-01-10 16:09:18
【问题描述】:
我正在更新一些在 Win7 或更高版本上无法运行的旧软件。所以,我正在重建一些使用最新 win32 更新的 MFC 库。
现在我有两个问题:
- MessageBox 出现在 CFrameWnd 后面,因此无法访问它,导致应用程序停止。
- 打开对话框(无论是基于 CFileDialog 还是 IFileDilog)在更改文件类型时不会刷新。
但是,如果 CFrameWnd 被隐藏,这两个问题都可以解决。或者,在 MessageBox 的情况下,如果您编写以下代码,则无需隐藏窗口: PostMessage(0x118);其实我也不知道为什么。
这里一定有我遗漏的东西。
在使用继承自 IFileDialog 的 OpenFileDialog 类时,我还遇到了另一个问题。是当关闭此对话框而不拾取文件时,应用程序崩溃。
//--targetver.h
#pragma once
#include <sdkddkver.h>
//--stdafx.h:
#ifndef CS_EXTRALEAN
#define CS_EXTRALEAN
#endif
#pragma once
#include "targetver.h"
#include<afxwin.h>
#include<afxext.h>
#include<afxcmn.h>
//--stdafx.cpp
#include "stdafx.h"
//--CMainWnd.h
#pragma once
class CMainWnd : public CFrameWnd
{
public:
CMainWnd();
~CMainWnd();
afx_msg void OnPaint();
afx_msg void OnLButtonDown(UINT, CPoint);
DECLARE_MESSAGE_MAP()
};
//--CMainWnd.cpp
#include "stdafx.h"
#include"CMainWnd.h"
BEGIN_MESSAGE_MAP(CMainWnd, CFrameWnd)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
CMainWnd::CMainWnd()
: CFrameWnd()
{
CString class_name = AfxRegisterWndClass(
CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS,
AfxGetApp()->LoadStandardCursor(IDC_ARROW),
(HBRUSH)::GetStockObject(BLACK_BRUSH),
AfxGetApp()->LoadStandardIcon(IDI_ASTERISK));
HRESULT hResult = this->Create(
class_name,
L"This is CMainWnd",
WS_OVERLAPPEDWINDOW,
this->rectDefault,
NULL,
NULL,
0,
NULL);
}
CMainWnd::~CMainWnd() { }
void CMainWnd::OnPaint()
{ }
void CMainWnd::OnLButtonDown(UINT, CPoint)
{
MessageBox(L"HELLO MFC", L"MFC", MB_OK);
}
//--CAppWnd.h
#pragma once
class CAppWnd : public CWinApp
{
public:
CAppWnd();
~CAppWnd();
BOOL InitInstance();
DECLARE_MESSAGE_MAP()
};
//--CAppWnd.cpp
#include "stdafx.h"
#include "CAppWnd.h"
#include "CMainWnd.h"
BEGIN_MESSAGE_MAP(CAppWnd, CWinApp)
END_MESSAGE_MAP()
CAppWnd::CAppWnd()
:CWinApp()
{ }
CAppWnd::~CAppWnd()
{ }
BOOL CAppWnd::InitInstance()
{
this->m_pMainWnd = new CMainWnd;
this->m_pMainWnd->ShowWindow(m_nCmdShow);
return CWinApp::InitInstance();
}
CAppWnd The_App;
【问题讨论】:
-
c++ 是很久以前的事了,但是你不能给你的 MessageBox 一个所有者,让它总是出现在这个所有者之上吗?
-
我试过没用。我的代码一定有我没有注意到的问题。
-
在这里复制代码并不是每个人都会下载你的源代码并寻找它
-
最好下载代码,因为它更容易从 Visual Studio 中查看,而不是从网页中读取大量行。传递的功能可不小。
-
不,不是。事实上,仅此一项就是将您的问题标记为 "off-topic" 的原因(请参阅 help center)。
标签: c++ winforms mfc refresh openfiledialog