求最新MFC函数手册。我发现我的手册没有cdialog cdialogexx。什么状况?

Using CScrollView derived object in a CDialog derived object in MFC DLL [使用CScrollView派生对象在一个CDialog派生对象在MFC DLL] - 问题-字节技术
Using CScrollView derived object in a CDialog derived object in MFC DLL
使用CScrollView派生对象在一个CDialog派生对象在MFC DLL
问题 (Question)
I would like for someone to explain to me why the following use of a CScrollView derived object within a CDialog derived object works and whether this approach has hidden problems.
My concern is the casting of a CDialog to a CFrameWnd in order to use the CreateView() method of the CFrameWnd class to create a Document/View pair for the CScrollView object in the CDialog object.
I am building an MFC DLL that will provide a series of GUI functions to display and allow the edit of some types of information in a legacy application which displays a page at a time.
One of the first pieces is to provide a way to display reports in a dialog that presents the report in a scrollable component allowing the user to view the entire report.
Looking into using a CSrollView derived control in a CDialog derived GUI object, I found this article, , as I was running into a number of problems with exceptions on CDialog closing when using a CScrollView.
I was also seeing a warning in the debug output window of "Warning: Creating a pane with no CDocument." which I am no longer seeing.
Using the basic concept from the article I have code which seems to be working fine with Visual Studio 2005 in Windows XP in the debugger.
The code I am using in the CDialog derived class for initializing in the OnInitDialog() is as follows.
I am creating the document first and putting lines of text into a memory area and the constructor of the CDialog derived object is given the address of the document, m_pDocument, which is then used in the OnInitDialog() function.
BOOL CScrollReportDialog::OnInitDialog ()
// Get the client area size of the dialog we are putting the
// CScrollView into and pull the right edge in sufficient to
// clear buttons on the right hand side of the dialog.
GetClientRect (&rectSize);
rectSize.right -= 120;
// allocate and set up the view document context linking the view
// to a particular document, in our case a CScrollDocument.
CCreateContext pC
pContext.m_pCurrentDoc = m_pD
pContext.m_pNewViewClass = RUNTIME_CLASS(CScrollReport);
// Cast the pointer to this dialog into a CFrameWnd pointer allowing
// us to access the CFrameWnd methods.
Both CDialog and CFrameWnd are
// derived from CWnd so we can get away with this.
CFrameWnd* pFrameWnd = (CFrameWnd *) ((CWnd *)this);
CScrollReport *pView = (CScrollReport *)pFrameWnd-&CreateView(&pContext);
ASSERT(pView);
// Set an initial scroll size for the CScrollView which will be
// modified in the OnDraw () later when presenting the actual view
// and we have the complete document and can calculate the document's
// scrollable size properly.
CSize sizeT
sizeTotal.cx = rectSize.
sizeTotal.cy = 1 * rectSize.
pView-&SetScrollSizes(MM_TEXT, sizeTotal);
pView-&ShowWindow(SW_NORMAL);
* After a view is created, resize window area of the view to fit into the
Since this is a CScrollView, set an initial size for the
* size of the object being scrolled.
pView-&MoveWindow(&rectSize);
return TRUE;
我想有人向我解释为什么下面使用一个CScrollView派生的对象在一个CDialog派生对象的作品,这种做法是否有隐藏的问题。我关心的是一个CDialog为了一个CFrameWnd铸造用CreateView()创建一个在CDialog对象CScrollView对象文档/视图对CFrameWnd类的方法。我建立一个MFC DLL,将显示和允许编辑某些类型的信息在一个遗留应用程序显示一个页面的时间提供了一系列的GUI功能。第一件是在一个对话框,提出报告的滚动组件允许用户查看整个报告显示报告提供了一种方式。在研究利用派生的控件派生的GUI对象一个CDialog一csrollview,我发现这篇文章,,我遇到一些在使用CScrollView收盘时CDialog异常的问题。我也看到了在调试输出窗口的“警告警告:创造一个没有文档窗格。“我不再看到。使用我的代码似乎是用Visual Studio 2005在Windows XP在调试器中良好的工作文章的基本概念。我初始化在CDialog派生类使用的代码OnInitDialog()如下。我创建的文件的第一个,把行文本为存储区域的CDialog派生对象的构造函数是给定的文件的地址,m_pDocument,然后用它在OnInitDialog()功能。BOOL CScrollReportDialog::OnInitDialog ()
// Get the client area size of the dialog we are putting the
// CScrollView into and pull the right edge in sufficient to
// clear buttons on the right hand side of the dialog.
GetClientRect (&rectSize);
rectSize.right -= 120;
// allocate and set up the view document context linking the view
// to a particular document, in our case a CScrollDocument.
CCreateContext pC
pContext.m_pCurrentDoc = m_pD
pContext.m_pNewViewClass = RUNTIME_CLASS(CScrollReport);
// Cast the pointer to this dialog into a CFrameWnd pointer allowing
// us to access the CFrameWnd methods.
Both CDialog and CFrameWnd are
// derived from CWnd so we can get away with this.
CFrameWnd* pFrameWnd = (CFrameWnd *) ((CWnd *)this);
CScrollReport *pView = (CScrollReport *)pFrameWnd-&CreateView(&pContext);
ASSERT(pView);
// Set an initial scroll size for the CScrollView which will be
// modified in the OnDraw () later when presenting the actual view
// and we have the complete document and can calculate the document's
// scrollable size properly.
CSize sizeT
sizeTotal.cx = rectSize.
sizeTotal.cy = 1 * rectSize.
pView-&SetScrollSizes(MM_TEXT, sizeTotal);
pView-&ShowWindow(SW_NORMAL);
* After a view is created, resize window area of the view to fit into the
Since this is a CScrollView, set an initial size for the
* size of the object being scrolled.
pView-&MoveWindow(&rectSize);
return TRUE;
最佳答案 (Best Answer)
Reviewing the MFC source for CFrameWnd::CreateView() there is no dependency on any CFrameWnd data.
However the implementation of the method could change at a later time.
The version of the MFC source for CFrameWnd::CreateView() uses the MFC dynamic object creation to create an instance of the view.
It then creates the actual window for the view as a child window with a specific MFC document/view window identifier.
Rather than depending on CFrameWnd::CreateView() to remain the same implementation, we can implement our own version.
The modified part of the function is to replace casting the CDialog object to a CFrameWnd object in order to access the CreateView() method with the specific code for the CreateView() implementation as follows.
// Cast the pointer to this dialog into a CFrameWnd pointer allowing
// us to access the CFrameWnd methods.
Both CDialog and CFrameWnd are
// derived from CWnd so we can get away with this.
CFrameWnd* pFrameWnd = (CFrameWnd *) ((CWnd *)this);
CScrollReport *pView = (CScrollReport *)pFrameWnd-&CreateView(&pContext);
ASSERT(pView);
// Use the approach from CFrameWnd::CreateView() to create a view and
// link the view with the document.
We use the dynamic CreateObject()
// functionality to create a CScrollReport view object.
We use the
// standard child window id for the first view of an instance of the
// MFC document/view architecture.
We are basing this on a copy of
// the CFrameWnd::CreateView () method from the MFC source.
nID = AFX_IDW_PANE_FIRST;
CScrollReport *pView = (CScrollReport *)pContext.m_pNewViewClass-&CreateObject();
ASSERT(pView);
ASSERT_KINDOF(CWnd, pView);
if (pView) {
if (!pView-&Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, CRect(0,0,0,0), this, nID, &pContext)) {
TRACE0("Warning: could not create view for dialog.\n");
return FALSE;
TRACE0("Warning: dynamic create of CScrollView for dialog failed.\n");
return FALSE;
EDIT Jan28
One problem run into is sometimes the dialog will display beneath what is a full screen application.
The result is that the dialog with the CScrollView is not visible.
See stackoverflow
for an example of using the SetWindowPos() function.
I am using it in the OnInitDialog() method just before returning.
对MFC源CFrameWnd::CreateView()有任何的CFrameWnd数据不依赖。然而,实施的方法可以在稍后的时间变化。对MFC源版本CFrameWnd::CreateView()使用MFC动态创建对象创建的视图的一个实例。然后创建实际的窗口的视图作为一个子窗口与一个特定的MFC的文档/视图窗口标识符。而不是依赖CFrameWnd::CreateView()保持相同的实现,我们可以实现我们自己的版本。函数的修改部分取代铸造CDialog对象以一个CFrameWnd对象来访问CreateView()为与特定的编码方法CreateView()实现如下。#if 0
// Cast the pointer to this dialog into a CFrameWnd pointer allowing
// us to access the CFrameWnd methods.
Both CDialog and CFrameWnd are
// derived from CWnd so we can get away with this.
CFrameWnd* pFrameWnd = (CFrameWnd *) ((CWnd *)this);
CScrollReport *pView = (CScrollReport *)pFrameWnd-&CreateView(&pContext);
ASSERT(pView);
// Use the approach from CFrameWnd::CreateView() to create a view and
// link the view with the document.
We use the dynamic CreateObject()
// functionality to create a CScrollReport view object.
We use the
// standard child window id for the first view of an instance of the
// MFC document/view architecture.
We are basing this on a copy of
// the CFrameWnd::CreateView () method from the MFC source.
nID = AFX_IDW_PANE_FIRST;
CScrollReport *pView = (CScrollReport *)pContext.m_pNewViewClass-&CreateObject();
ASSERT(pView);
ASSERT_KINDOF(CWnd, pView);
if (pView) {
if (!pView-&Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, CRect(0,0,0,0), this, nID, &pContext)) {
TRACE0("Warning: could not create view for dialog.\n");
return FALSE;
TRACE0("Warning: dynamic create of CScrollView for dialog failed.\n");
return FALSE;
编辑受到会碰到一个问题,有时是对话框将显示在全屏应用程序是什么。结果表明,随着CScrollView对话框是不可见的。看到计算器例如,使用SetWindowPos()功能。我用它在OnInitDialog()方法在返回之前。
本文翻译自StackoverFlow,英语好的童鞋可直接参考原文:下次自动登录
现在的位置:
& 综合 & 正文
CDialogEx对话框
中常用的窗口之一,而MFC对话框的默认的样式在很多应用中都显得很单调,如何对对话框的样式和风格进行修改是很多开发者需要面临的问题,本文从MFC的CDialog派生出自己的对话框样式,给出了很多改变对话框样式的函数,通过调用这些函数,就可以很好的改变对话框的各种风格。
( CBrush* pBrush );
( COLORREF clrBk );
( CFont* pFont );
,CAPTIONTEXT_CENTER,CAPTIONTEXT_RIGHT
(int positionType);
(COLORREF clrActiveCaptionText,COLORREF clrInactiveCaptionText);
(COLORREF clrActiveCaptionBar,COLORREF clrInactiveCaptionBar);
lpbmpLeft,LPCTSTR lpbmpRight,LPCTSTR lpbmpBottom)
hbmpLeft,HBITMAP hbmpRight,HBITMAP hbmpBottom)
& strArrBtnClose,CStringArray& strArrBtnMin,CStringArray& strArrBtnMax)
* hbmpBtnClose,HBITMAP* hbmpBtnMin,HBITMAP* hbmpBtnMax, int nElement)
hbmpACaption,HBITMAP hbmpNCaption)
lpszACaption,LPCTSTR lpszNCaption)
SetBorderColor(COLORREF clrLeft,COLORREF clrTop,COLORREF clrRight, COLORREF clrBottom);
(255,0,0),RGB(0,255,255));//(255,0,0)
(255,255,0),RGB(0,255,255));//(255,255,0)
(255,0,255));//(255,0,255)
(0,255,0),右RGB(255,255,0),底RGB(0,255,255)
(255,0,0),RGB(0,255,0),RGB(255,255,0),RGB(0,255,255));
&&&&推荐文章:
【上篇】【下篇】&&&&中文版MFC参考手册
中文版MFC参考手册
该MFC参考含盖了Microsoft基本类库中的类、全局函数、全局变量和宏的内容。
参考中“类层次结构图”是为了方便查找某个类的基类。
该MFC参考通常不描述通过继承的函数或操作符。若要寻求这些函数的信息,请参阅类层次结构图中该类的基类信息。
每个类的说明文档包括:该类的概括、类成员的种类、以及该成员函数、重载操作符或数据成员的基本用途。
仅撰写应用程序或派生类在一般情况下对于公共和保护类成员的使用说明。
寻求完整的类成员的列表,请参阅该类的头文件。
本书目录 · 层次结构图 直观的描述MFC中各类的关系。
· MFC类 详细解说MFC库中的每个类和头文件信息。
· MFC宏和全局 详细解说MFC库中的每个宏、全局函数、全局变量。
· 结构、风格、回调函数和消息映射 详细解说MFC库中的各个结构、风格、回调函数和消息映射。
若举报审核通过,可奖励20下载分
被举报人:
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:
VIP下载&&免积分60元/年(1200次)
您可能还需要
开发技术下载排行MFC窗口颜色的设置 - 推酷
MFC窗口颜色的设置
本文主要介绍对话框背景色以及控件颜色的设置(SetDialogBkColor()不再被支持)。
对话框背景色的设置
消息,代码如下所示:
void CtestDlg::OnPaint()
if (IsIconic())
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast&WPARAM&(dc.GetSafeHdc()), 0);
// 使图标在工作区矩形中居中
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
//CDialogEx::OnPaint();
//设置为绿色背景
GetClientRect(rect);
dc.FillSolidRect(rect,RGB(0,255,0));
OnCtlColor
(CDC* pDC, CWnd* pWnd, UINT nCtlColor),即
WM_CTLCOLOR
a)在对话框的.h文件中添加CBrush类的成员m_brush
b)在对话框的.cpp文件中的OnInitDialog()中添加以下代码(背景红色):
m_brush.CreateSolidBrush(RGB(255,0,0));
c)重载OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor),代码如下:
HBRUSH CtestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
在此更改 DC 的任何特性
if(nCtlColor == CTLCOLOR_DLG)
//返加红色刷子
如果默认的不是所需画笔,则返回另一个画笔
控件颜色的设置
OnCtlColor
(CDC* pDC, CWnd* pWnd, UINT nCtlColor),即
WM_CTLCOLOR
HBRUSH CtestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
在此更改 DC 的任何特性
// 设置显示字体
CFont * font=new CF
font-&CreateFont(16,0,0,0,FW_SEMIBOLD,FALSE,FALSE,0,
ANSI_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
DEFAULT_PITCH&FF_SWISS,_T(&Arial&));
switch(nCtlColor)
case CTLCOLOR_STATIC: //对所有静态文本框的设置
pDC-&SetBkMode(TRANSPARENT);
//设置背景为透明
pDC-&SetTextColor(RGB(255,255,0)); //设置字体颜色
pWnd-&SetFont(font); //设置字体
HBRUSH B = CreateSolidBrush(RGB(125,125,255));
//创建画刷
return (HBRUSH) B; //返回画刷句柄
case CTLCOLOR_EDIT: //对所有编辑框的设置
if(IDC_EDIT2 == pWnd-&GetDlgCtrlID())
pDC-&SetBkMode(TRANSPARENT);
pDC-&SetTextColor(RGB(255,255,0));
pWnd-&SetFont(font);
HBRUSH B = CreateSolidBrush(RGB(125,125,125));
return (HBRUSH) B;
if(IDC_EDIT3 == pWnd-&GetDlgCtrlID())
pDC-&SetBkMode(TRANSPARENT);
pDC-&SetTextColor(RGB(255,0, 0));
pWnd-&SetFont(font);
HBRUSH B = CreateSolidBrush(RGB(125,125,0));
return (HBRUSH) B;
return CDialog::OnCtlColor(pDC,pWnd, nCtlColor);
如果默认的不是所需画笔,则返回另一个画笔
nCtlColor的类别有以下几种:
CTLCOLOR_BTN& 按钮控件
CTLCOLOR_DLG& 对话框
CTLCOLOR_EDIT& 编辑框
CTLCOLOR_LISTBOX& 列表框
CTLCOLOR_MSGBOX&& 消息框
CTLCOLOR_SCROLLBAR& 滚动条
CTLCOLOR_STATIC& 静态文本
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致&&&&MFC函数库手册(中文版)
MFC函数库手册(中文版)
MFC函数库手册,内含MFC类库和函数库详解,结构和消息映射等原理,纯中文版,学习MFC的好帮手。
若举报审核通过,可奖励20下载分
被举报人:
zhangjian512
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:
VIP下载&&免积分60元/年(1200次)
您可能还需要
开发技术下载排行}

我要回帖

更多关于 mfc手册 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信