如何改变通用对话框(如字体对话框)的窗口风格
我用了CFontDialog,现在想改变一下显示的窗口风格,使其显示最大化、最小化按钮。不知该如何实现,希望不用通过自己继承CFontDialog来实现。 问题点数:10、回复次数:10Top
1 楼mahatma_cn(研究硕士生)回复于 2004-09-03 23:26:06 得分 4
引入字体对话框资源FONT.DLG,修改对话框风格。
下面来自msdn
Custom Templates
Common dialog boxes have default templates that define the number, type, and position of the standard controls in the dialog box. You can define a custom template to give users access to additional controls that are unique to your application.
For all common dialog boxes except the Explorer-style Open and Save As dialog boxes, you modify the default template to create a custom template that replaces the default template. The custom template defines the type and position of the standard controls as well as any additional controls.
When you create a custom dialog box template by modifying the default dialog box template, make sure the identifiers for any added controls are unique and do not conflict with the identifiers of the standard controls. The following table lists the name of the default template file and include file for each of the common dialog box types.
Dialog box type Template file Include file
Color Color.dlg ColorDlg.h
Find Findtext.dlg Dlgs.h
Font Font.dlg Dlgs.h
Open (multiple selection) Fileopen.dlg Dlgs.h
Open (single selection) Fileopen.dlg Dlgs.h
Page Setup Prnsetup.dlg Dlgs.h
Print Prnsetup.dlg Dlgs.h
Print Setup (obsolete) Prnsetup.dlg Dlgs.h
Replace Findtext.dlg Dlgs.h
To enable a custom template, you must set a flag in the Flags member of the corresponding structure for the dialog box. If the template is a resource in an application or dynamic-link library, set an ENABLETEMPLATE flag in the Flags member, and use the hInstance and lpTemplateName members of the structure to identify the module and resource name. If the template is already in memory, set an ENABLETEMPLATEHANDLE flag in the Flags member, and use the hInstance member to identify the memory object that contains the template.
In most cases, you must also enable a hook procedure for the dialog box to support and process input for the additional controls in your custom template.
For the Explorer-style Open and Save As dialog boxes, the default templates are not available for modification. Instead, your custom template defines a child dialog box that includes only the items to be added to the standard dialog box. The custom template can also define a static control that specifies the location of the cluster of standard controls in the child dialog box. For more information, see Explorer-Style Custom Templates.Top
2 楼mahatma_cn(研究硕士生)回复于 2004-09-03 23:42:45 得分 0
不明白的话,再问我,我告诉你详细步骤。当然最好自己搞定!因为ms提供了通用对话框模板了。你只要改风格或者添加自己的控件!Top
3 楼jackion31(jackion31)回复于 2004-09-04 10:17:08 得分 0
好的,谢谢,我先试试,不懂再来问你,解决马上结贴Top
4 楼jackion31(jackion31)回复于 2004-09-04 10:53:46 得分 0
我在vc的include目录下找到了FONT.DLG,当我导入这个资源的时候,提示让我填写类型,我写了Font,结果导入后是以二进制方式显示,是不是我导入的时候弄错了,还是要麻烦你给我指点一下,谢谢!Top
5 楼mahatma_cn(研究硕士生)回复于 2004-09-05 08:14:41 得分 2
简单点,打开font.dlg。找到对话框定义的部分,copy下来,再文本方式打开.rc文件,找个位置粘贴下来。Top
6 楼jackion31(jackion31)回复于 2004-09-05 10:44:31 得分 0
我用了楼上说的办法了,资源是导进来了,可是怎么让这个资源和CFontDialog关联呢,我在资源上添加了最大化最小化按扭,但是弹出的对话框还是什么都没有,我试着从这个资源生成一个新的类,让它继承于CFontDialog,这样还是不行,弹出来的对话框还是common dialog,楼上的能再讲讲怎样把资源和CFontDialog关联上吗?那个对话框的ID应该是什么?谢谢!Top
7 楼mahatma_cn(研究硕士生)回复于 2004-09-05 13:50:35 得分 0
定义一个结构对象。
CHOOSEFONT csf;
初始化对象成员。如:
csf.lpTemplateName=MAKEINTRESOURCE(在资源管理器中可以找到对话框ID);
...
..
.
初始化完毕,调用ChooseFont()函数
ChooseFont(&csf);显示对话框!
这是sdk中的方法
MFC中,可以这样,不要去派生了,直接如下。
CDialog cmydlg(MAKEINTRESOURCE(dialog's id));
cmydlg.DoModal();
Top
8 楼mahatma_cn(研究硕士生)回复于 2004-09-05 13:56:21 得分 4
注,上面介绍的MFC中的方法,由于没有初始化字体等,所以字体列表肯定是空的。
所以呢,如果你只是想增加几个标题栏按钮的话,就不要这么繁琐了,派生对话框类,在初始化函数中修改对话框的风格即可!Top
9 楼jackion31(jackion31)回复于 2004-09-05 17:57:54 得分 0
楼上的,我从CFontDialog上派生了一个类,最大化和最小化也加上了,但是问题又出来了,发现点击那两个按扭没有作用,我重载了OnLButtonDown,可是发现在标题拦点击,这个函数不会响应,楼上有办法解决这个问题吗,使这两个按扭有效.Top
10 楼jackion31(jackion31)回复于 2004-09-05 18:02:53 得分 0
我是通过在OnInitialDialog()中调用ModifyStyle(NULL,WS_MAXIMIZEBOX | WS_MINIMIZEBOX)这个函数来实现的,我也曾通过在OnCreate(LPCREATESTRUCT lpCreateStruct)改变lpCreateStruct->style的值,这个连那两个按扭也加不上Top




