📄 在属性页中添加字体对话框.htm
字号:
AddTxt=" [list][*] [/*][*] [/*][*] [/*][/list]";
AddText(AddTxt);
} else {
txt=prompt("列表类型\n输入 'A' 表示有序列表, '1' 表示无序列表, 留空表示无序列表.","");
while ((txt!="") && (txt!="A") && (txt!="a") && (txt!="1") && (txt!=null)) {
txt=prompt("错误!\n类型只能输入 'A' 、 '1' 或者留空.","");
}
if (txt!=null) {
if (txt=="") {
AddTxt="[list]";
} else {
AddTxt="[list="+txt+"]";
}
txt="1";
while ((txt!="") && (txt!=null)) {
txt=prompt("列表项\n空白表示结束列表","");
if (txt!="") {
AddTxt+="[*]"+txt+"[/*]";
}
}
AddTxt+="[/list] ";
AddText(AddTxt);
}
}
}
function showfont(font) {
if (helpstat){
alert("字体标记\n给文字设置字体.\n用法: [face="+font+"]改变文字字体为"+font+"[/face]");
} else if (basic) {
AddTxt="[face="+font+"][/face]";
AddText(AddTxt);
} else {
txt=prompt("要设置字体的文字"+font,"文字");
if (txt!=null) {
AddTxt="[face="+font+"]"+txt;
AddText(AddTxt);
AddTxt="[/face]";
AddText(AddTxt);
}
}
}
function underline() {
if (helpstat) {
alert("下划线标记\n给文字加下划线.\n用法: [u]要加下划线的文字[/u]");
} else if (basic) {
AddTxt="[u][/u]";
AddText(AddTxt);
} else {
txt=prompt("下划线文字.","文字");
if (txt!=null) {
AddTxt="[u]"+txt;
AddText(AddTxt);
AddTxt="[/u]";
AddText(AddTxt);
}
}
}
function setfly() {
if (helpstat){
alert("飞翔标记\n使文字飞行.\n用法: [fly]文字为这样文字[/fly]");
} else if (basic) {
AddTxt="[fly][/fly]";
AddText(AddTxt);
} else {
txt=prompt("飞翔文字","文字");
if (txt!=null) {
AddTxt="[fly]"+txt;
AddText(AddTxt);
AddTxt="[/fly]";
AddText(AddTxt);
}
}
}
function move() {
if (helpstat) {
alert("移动标记\n使文字产生移动效果.\n用法: [move]要产生移动效果的文字[/move]");
} else if (basic) {
AddTxt="[move][/move]";
AddText(AddTxt);
} else {
txt=prompt("要产生移动效果的文字","文字");
if (txt!=null) {
AddTxt="[move]"+txt;
AddText(AddTxt);
AddTxt="[/move]";
AddText(AddTxt);
}
}
}
function shadow() {
if (helpstat) {
alert("阴影标记\n使文字产生阴影效果.\n用法: [SHADOW=宽度, 颜色, 边界]要产生阴影效果的文字[/SHADOW]");
} else if (basic) {
AddTxt="[SHADOW=255,blue,1][/SHADOW]";
AddText(AddTxt);
} else {
txt2=prompt("文字的长度、颜色和边界大小","255,blue,1");
if (txt2!=null) {
txt=prompt("要产生阴影效果的文字","文字");
if (txt!=null) {
if (txt2=="") {
AddTxt="[SHADOW=255, blue, 1]"+txt;
AddText(AddTxt);
AddTxt="[/SHADOW]";
AddText(AddTxt);
} else {
AddTxt="[SHADOW="+txt2+"]"+txt;
AddText(AddTxt);
AddTxt="[/SHADOW]";
AddText(AddTxt);
}
}
}
}
}
function glow() {
if (helpstat) {
alert("光晕标记\n使文字产生光晕效果.\n用法: [GLOW=宽度, 颜色, 边界]要产生光晕效果的文字[/GLOW]");
} else if (basic) {
AddTxt="[glow=255,red,2][/glow]";
AddText(AddTxt);
} else {
txt2=prompt("文字的长度、颜色和边界大小","255,red,2");
if (txt2!=null) {
txt=prompt("要产生光晕效果的文字.","文字");
if (txt!=null) {
if (txt2=="") {
AddTxt="[glow=255,red,2]"+txt;
AddText(AddTxt);
AddTxt="[/glow]";
AddText(AddTxt);
} else {
AddTxt="[glow="+txt2+"]"+txt;
AddText(AddTxt);
AddTxt="[/glow]";
AddText(AddTxt);
}
}
}
}
}
function openscriphtml()
{
if (navigator.appName!="Microsoft Internet Explorer")
alert("此功能 Netscape 用户不能使用!")
else
{newwin=window.open('htmledit/editor.html','','width=544,height=294');
newwin.focus();
}
}
function runEx(){
//alert('请注意,按下确定将生成页面,按下后请稍后....');
var winEx = window.open("", "winEx", "width=600,height=400,status=yes,menubar=yes,scrollbars=yes,resizable=yes"); winEx.document.open("text/html", "replace");
winEx.document.write(unescape(event.srcElement.parentElement.children[2].value));
winEx.document.close();
}
function openScript(url, width, height) {
var Win = window.open(url,"openScript",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=yes,status=yes' );
}
</SCRIPT>
<script language="Javascript">
<!-- hide
function insertsmilie(smilieface){
document.frmAnnounce.body.value+=smilieface;
}
// -->
</script>
<html>
<head>
<meta NAME="GENERATOR" Content="Microsoft FrontPage 4.0">
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=gb2312">
<meta name="keywords" content="情天汉武,http://www.9712.net">
<style type=text/css>
td { font-size: 9pt; }
.content { font-size: 10pt; }
</style>
<title>在属性页中添加字体对话框|http://www.9712.net</title>
</head>
<body>
<TABLE cellSpacing=0 cellPadding=0 width="95%" border=0 align=center>
<TBODY>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=4 width="100%" border=0>
<TR>
<TD colspan="2">
</TD></TR>
<TR>
<TD colspan="2">
<table width=100% cellpadding=0 cellspacing=0 border=0>
<tr><td width=*>
| <a href="index.asp?classid=12">Visual C++</a>>><a href="index.asp?classid=12&Nclassid=46">窗体</a>
</td><td align=right>
<script>
var i=9;
function chgsize(act)
{
if (act=="add")
{i++;}
else
{i--;}
document.styleSheets[0].rules[0].style.fontSize=i+"pt";
document.styleSheets[0].rules[1].style.fontSize=i+1+"pt";
}
</script>
字体大小:<a href=# onclick="chgsize('')" >-</a> <a href=# onclick="chgsize('add')" >+</a> <img src=pic/printpage.gif align=absmiddle> <a href=javascript:window.print()>打印</a></td>
</tr>
</table>
</TD></TR>
<TR>
<TD colspan="2">
<center><b><font class=content>在属性页中添加字体对话框</font></b><br>www.9712.net 2003-12-24 情天汉武</center><p>
<blockquote>
<br>
<font class=content id=content>在属性页中添加字体对话框</P><P></P><P> mfc提供了三种属性页类:cfontproppage、ccolorproppage和cpictureproppage。<BR>但是,它们只能与ole automation一起使用。在本文中将介绍如何在属性对话框中添<BR>加字体属性页。</P><P> 解决的办法是你自己建立字体属性页。为了让你能定制通用对话框的行为,sdk<BR>提供了这些对话框的对话框资源。“choose font”对话框是在include目录中的<BR>font.dlg文件中,相应的符号在dlgs.h文件中。使用这些文件作为出发点,我们<BR>可以为字体属性页建立资源,并且添加一个使用这些资源的cpropertypage继承类。<BR>下面的实现可能是有限的的,但也有一定的参考价值。如果你想增强它,可以查看<BR>mfc源程序目录中的cfontproppage源文件。</P><P>第一步:添加对话资源<BR> 你可以在devstudio中打开下面的rc文件devstudio,然后把对话框资源复制到<BR>你的主资源文件中,或者你也可以把该资源文件包含进去。</P><P> 为了复制资源文件,请在devstudio中打开“fontpage.rc”文件,然后展开资源<BR>的outline。然后打开resourceview,以便对话框资源是可见的。最后,从<BR>fontpage.rc中拖动idd_fontpage资源到你的应用程序resourceview的资源中。</P><P> 如果你想包含fontpage资源文件,只要把“fontpage.rc”和“fontpagerc.h”<BR>文件(在下面列出)到项目目录中的“res”目录中即可。然后在该目录中已有的<BR>“rc2”文件中添加下面这段。资源图像也列在下面。</P><P>#include "fontpage.rc" <BR>listing of fontpage.rc <BR>/////////////////////////////////////////////////////////////////////////<BR>// listing of fontpage.rc<BR>//<BR>#include "winresrc.h"<BR>#include "fontpagerc.h"<BR>idd_fontpage dialog discardable 13, 54, 264, 133<BR>style ws_child | ws_caption | ws_sysmenu<BR>caption "font"<BR>font 8, "helv"<BR>begin<BR>ltext "&font:",stc1,6,3,40,9<BR>combobox idc_font,6,13,131,54,cbs_simple | cbs_autohscroll | <BR>cbs_sort | cbs_disablenoscroll | ws_vscroll | ws_tabstop<BR>ltext "font st&yle:",stc2,153,3,44,9<BR>combobox idc_style,153,13,64,54,cbs_simple | cbs_disablenoscroll | <BR>ws_vscroll | ws_tabstop<BR>ltext "&size:",stc3,224,3,30,9<BR>combobox idc_fontsize,224,13,32,54,cbs_simple | <BR>cbs_disablenoscroll | ws_vscroll | ws_tabstop<BR>groupbox "effects",grp1,6,72,84,34,ws_group<BR>control "stri&keout",idc_strikeout,"button",bs_autocheckbox | <BR>ws_tabstop,10,82,49,10<BR>control "&underline",idc_underline,"button",bs_autocheckbox,10,<BR>94,51,10<BR>groupbox "sample",grp2,98,72,160,49,ws_group<BR>ctext "aabbyyzz",idc_sample,104,81,149,37,ss_noprefix<BR>end<BR>/////////////////////////////////////////////////////////////////////////<BR>// listing of fontpagerc.h <BR>/////////////////////////////////////////////////////////////////////////<BR>#define idc_strikeout 0x0410<BR>#define idc_underline 0x0411<BR>#define grp1 0x0430<BR>#define grp2 0x0431<BR>#define stc1 0x0440<BR>#define stc2 0x0441<BR>#define stc3 0x0442<BR>#define idc_sample 0x0444<BR>#define idc_font 0x0470<BR>#define idc_style 0x0471<BR>#define idc_fontsize 0x0472<BR>#define idd_fontpage 1543<BR>/////////////////////////////////////////////////////////////////////////<BR>第二步:在你的项目中包含源文件<BR> 下面给出了头文件和实现文件。你只要简单的把它们包含到你的项目中,并且<BR>使用cfontpage类就可以了。该类的实现是比较简单的。cfontpage构造函数获取一<BR>指向logfont结构的指针。它使用该结构的信息来初始化自己。如果logfont结构没<BR>有提供,则使用窗口的当前字体。在oninitdialog()函数中,我们列出了所需字体<BR>和字体组合框。但是,任何字体特性的改变,都要调用onselchange()函数来实现。<BR>所有的信息映射入口都指向该函数。onselchange()函数更新内部信息,并且显示样<BR>本文本。</P><P>fontpage.h</P><P>#if !defined(afx_fontpage_h__de7edeb3_056d_11d1_82df_e2cdc9000000__included_)<BR>#define afx_fontpage_h__de7edeb3_056d_11d1_82df_e2cdc9000000__included_<BR>#if _msc_ver >= 1000<BR>#pragma once<BR>#endif // _msc_ver >= 1000<BR>// fontpage.h : header file<BR>//<BR>/////////////////////////////////////////////////////////////////////////////<BR>// cfontpage dialog<BR>class cfontpage : public cpropertypage<BR>{<BR> declare_dyncreate(cfontpage)<BR>// construction<BR>public:<BR> void getcurrentfont(lplogfont lplf);<BR> cfontpage(logfont* plogfont = null);<BR> ~cfontpage();<BR>// dialog data<BR>//{{afx_data(cfontpage)<BR>enum { idd = idd_fontpage };<BR>cstatic m_staticsample;<BR>ccombobox m_combostyle;<BR>ccombobox m_combosize;<BR>ccombobox m_combofont;<BR>bool m_bstrikeout;<BR>bool m_bunderline;<BR>cstring m_sfont;<BR>cstring m_ssize;<BR>cstring m_sstyle;<BR>//}}afx_data<BR>// overrides<BR>// classwizard generate virtual function overrides<BR>//{{afx_virtual(cfontpage)<BR>protected:<BR>virtual void dodataexchange(cdataexchange* pdx); // ddx/ddv support<BR>//}}afx_virtual<BR>// implementation<BR>protected:<BR>// generated message map functions<BR>//{{afx_msg(cfontpage)<BR>virtual bool oninitdialog();<BR>afx_msg void onselchange();<BR>//}}afx_msg<BR>declare_message_map()<BR>private:<BR>cfont m_fontsample;<BR>int m_cypixelsperinch;<BR>static int callback fontenumproc(enumlogfontex *lpelfe, newtextmetricex *lpntme, <BR> int fonttype, cfontpage* pfontpage );<BR>};<BR>//{{afx_insert_location}}<BR>// microsoft developer studio will insert additional declarations immediately <BR>// before the previous line.<BR>#endif // !defined(afx_fontpage_h__de7edeb3_056d_11d1_82df_e2cdc9000000__included_)<BR>fontpage.cpp</P><P>// fontpage.cpp : implementation file<BR>//<BR>#include "stdafx.h"<BR>#include "resource.h"<BR>#include "fontpage.h"<BR>#ifdef _debug<BR>#define new debug_new<BR>#undef this_file<BR>static char this_file[] = __file__;<BR>#endif<BR>/////////////////////////////////////////////////////////////////////////////<BR>// cfontpage property page<BR>implement_dyncreate(cfontpage, cpropertypage)<BR>cfontpage::cfontpage(logfont* plogfont /*= null*/) : cpropertypage(cfontpage::idd)<BR>{<BR> //{{afx_data_init(cfontpage)<BR> //}}afx_data_init<BR> logfont logfont;<BR> cwindowdc dc(getdesktopwindow() );<BR> m_cypixelsperinch = getdevicecaps(dc, logpixelsy);<BR> if( plogfont == null )<BR> {<BR> cfont *pfont = dc.getcurrentfont();<BR> pfont->getlogfont( &logfont );<BR> plogfont = &logfont;<BR> }<BR> m_fontsample.createfontindirect( plogfont );<BR> m_bstrikeout = plogfont->lfstrikeout;<BR> m_bunderline = plogfont->lfunderline;<BR> m_sfont = plogfont->lffacename;<BR> m_ssize.format( "%d", muldiv(plogfont->lfheight, 72, m_cypixelsperinch) );<BR> m_sstyle = _t("regular");<BR> if( plogfont->lfweight >= 700 && plogfont->lfitalic)<BR> m_sstyle = _t("bold italic");<BR> else if( plogfont->lfitalic )<BR> m_sstyle = _t("italic");<BR> else if ( plogfont->lfweight >= 700 )<BR> m_sstyle = _t("bold");<BR>}<BR>cfontpage::~cfontpage()<BR>{<BR>}<BR>void cfontpage::dodataexchange(cdataexchange* pdx)<BR>{<BR> cpropertypage::dodataexchange(pdx);<BR> //{{afx_data_map(cfontpage)<BR> ddx_control(pdx, idc_sample, m_staticsample);<BR> ddx_control(pdx, idc_style, m_combostyle);<BR> ddx_control(pdx, idc_fontsize, m_combosize);<BR> ddx_control(pdx, idc_font, m_combofont);<BR> ddx_check(pdx, idc_strikeout, m_bstrikeout);<BR> ddx_check(pdx, idc_underline, m_bunderline);<BR> ddx_cbstring(pdx, idc_font, m_sfont);<BR> ddx_cbstring(pdx, idc_fontsize, m_ssize);<BR> ddv_maxchars(pdx, m_ssize, lf_facesize);<BR> ddx_cbstring(pdx, idc_style, m_sstyle);<BR> //}}afx_data_map<BR>}<BR>begin_message_map(cfontpage, cpropertypage)<BR>//{{afx_msg_map(cfontpage)<BR>on_cbn_selchange(idc_font, onselchange)<BR>on_cbn_selchange(idc_style, onselchange)<BR>on_cbn_selchange(idc_fontsize, onselchange)<BR>on_bn_clicked(idc_strikeout, onselchange)<BR>on_bn_clicked(idc_underline, onselchange)<BR>on_cbn_killfocus(idc_font, onselchange)<BR>on_cbn_killfocus(idc_style, onselchange)<BR>on_cbn_killfocus(idc_fontsize, onselchange)<BR>//}}afx_msg_map<BR>end_message_map()<BR>/////////////////////////////////////////////////////////////////////////////<BR>// cfontpage message handlers<BR>bool cfontpage::oninitdialog() <BR>{<BR> cpropertypage::oninitdialog();<BR> cwindowdc dc(this);<BR> logfont logfont;<BR> logfont.lfcharset = default_charset;<BR> logfont.lffacename[0] = '\0';<BR> logfont.lfpitchandfamily = 0;<BR> enumfontfamiliesex( dc.m_hdc, &logfont, (fontenumproc)fontenumproc, (lparam) this, 0 );<BR> // fill size combobox with "common" sizes<BR> tchar* defaults[]={_t("8"),_t("9"),_t("10"),_t("11"),_t("12"),_t("14"),_t("16"),_t ("18"), <BR> _t("20"), _t("22"), _t("24"), _t("26"), _t("28"), _t("36"), _t("48") };<BR> for (int i = 0; i < (sizeof(defaults)/sizeof(defaults[0])); i++)<BR> m_combosize.addstring(defaults[i]);<BR> // fill style combobox with "common" styles<BR> m_combostyle.addstring( _t("regular") );<BR> m_combostyle.addstring( _t("bold") );<BR> m_combostyle.addstring( _t("italic") );<BR> m_combostyle.addstring( _t("bold italic") );<BR> return true; // return true unless you set the focus to a control<BR> // exception: ocx property pages should return false<BR>}<BR>int callback cfontpage::fontenumproc(enumlogfontex *lpelfe, newtextmetricex *lpntme, <BR> int fonttype, cfontpage* pfontpage )<BR>{<BR> if( pfontpage->m_combofont.findstringexact( 0, (lpctstr)lpelfe->elffullname )==cb_err )<BR> {<BR> // add to list<BR> pfontpage->m_combofont.addstring( (lpctstr)lpelfe->elffullname );<BR> }<BR> return 1;<BR>}<BR>void cfontpage::onselchange() <BR>{<BR> // the selection hasn't changed yet, so change it<BR> if( ischild( getfocus() ) && getfocus()->getparent()->iskindof( runtime_class( ccombobox ) ) )<BR> {<BR> ccombobox *cb = (ccombobox *)getfocus()->getparent();<BR> cstring stext;<BR> if( cb->getcursel() != cb_err )<BR> {<BR> cb->getlbtext( cb->getcursel(), stext );<BR> cb->setwindowtext( stext );<BR> }<BR> }<BR> updatedata(true);<BR> logfont logfont;<BR> m_fontsample.getlogfont( &logfont );<BR> logfont.lfstrikeout = m_bstrikeout;<BR> logfont.lfunderline = m_bunderline;<BR> memcpy( logfont.lffacename, m_sfont, lf_facesize );<BR> logfont.lfheight = muldiv(atoi(m_ssize), m_cypixelsperinch, 72);<BR> logfont.lfweight = 400; //regular<BR> logfont.lfitalic = false;<BR> if( m_sstyle.find( _t("italic") ) != -1 )<BR> logfont.lfitalic = true;<BR> if( m_sstyle.find( _t("bold") ) != -1 )<BR> logfont.lfweight = 700;<BR> m_fontsample.deleteobject();<BR> m_fontsample.createfontindirect( &logfont );<BR> m_staticsample.setfont(&m_fontsample);<BR>}<BR>void cfontpage::getcurrentfont(lplogfont lplf)<BR>{<BR> m_fontsample.getlogfont( lplf );<BR>}</P><P><BR></font><br>
</blockquote>
</TD></TR>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -