易码技术论坛

 找回密码
 加入易码
搜索
查看: 300512|回复: 8

[求助][VC菜鸟新问题:关于字体]

[复制链接]
发表于 2006-12-3 18:14:13 | 显示全部楼层
菜到没人回答?
发表于 2006-12-3 18:33:29 | 显示全部楼层
控件的类名?你添加的是什么控件难道自己不知道么...
 楼主| 发表于 2006-12-3 18:59:31 | 显示全部楼层
果然~~

打错了,不是类名是名称.
发表于 2006-12-3 21:02:03 | 显示全部楼层
我只知道:GetDlgItemText
以下cpoy来自 MSDN2003版
int GetDlgItemText(
  int nID,//这里其实是控件ID……
  LPTSTR lpStr,//其实就是char*类型吧……我不太确定……  
int nMaxCount
) const;

int GetDlgItemText(
  int nID,//这里其实是控件ID……
  CString& rString //存放控件名的字串,注意是CString类型的。
) const;

Parameters
nID
Specifies the integer identifier of the control whose title is to be retrieved.
lpStr
Points to the buffer to receive the control's title or text.
nMaxCount
Specifies the maximum length (in bytes) of the string to be copied to lpStr. If the string is longer than nMaxCount, it is truncated.
rString
A reference to a CString.
Return Value
Specifies the actual number of bytes copied to the buffer, not including the terminating null character. The value is 0 if no text is copied.

Remarks
The GetDlgItemText member function copies the text to the location pointed to by lpStr and returns a count of the number of bytes it copies.
 楼主| 发表于 2006-12-3 22:38:13 | 显示全部楼层
谢谢LS!
关于控件问题就算了吧.

第二个问题我也解决了(都是自己摸索出来的~~):
C[工程名]View::GetEditCtrl().GetWindowText (,);
GetActiveView()->GetWindowText ();

现在的问题是怎么在MainFrame类中使用其他类的函数
如TOOLBAR上一个按扭要调用CDocument派生类(C[工程名]Doc)的 OnFileOpen(),
但是竟然提示 C[工程名]Doc 类未定义~~郁闷~~只能使用C[工程名]View解决?
 楼主| 发表于 2006-12-4 18:44:56 | 显示全部楼层
新问题在1楼.
发表于 2006-12-4 19:35:38 | 显示全部楼层
那个应该传递的是lf的地址吧~ 或者说没初始化~
 楼主| 发表于 2006-12-4 20:15:33 | 显示全部楼层
像下面这样吗?:
提示一样.
CFont *font = CCompileView::GetFont();
LOGFONT lf;
if(font != NULL)
{
   font->GetObject(sizeof(LOGFONT),&lf);
}
else
{
   ::GetObject(GetStockObject(SYSTEM_FONT),sizeof(LOGFONT),&lf);
}
CFontDialog fontdlg(&lf,CF_SCREENFONTS|CF_INITTOLOGFONTSTRUCT);
if(fontdlg.DoModal() == IDOK)
{
   font->GetLogFont (&lf);
   SetFont(font);
}

要是改成这样:
if(fontdlg.DoModal() == IDOK)
{
   SetFont(&lf);
}
会提示struct LOGFONT 无法转换成 CFont *

改成SetFont((CFont *)&lf)字体没变化~~

真是晕~~
 楼主| 发表于 2006-12-3 17:28:39 | 显示全部楼层 |阅读模式
我在为视图类添加设置字体的程序时又遇到了问题:
视图类的基类为CEditView.
函数如下:
void C[工程名]View::Onlook() //一个按扭
{
  CFont *font = GetFont();
  LOGFONT *lf = new LOGFONT;
  if(font != NULL)
  {
    font->GetObject(sizeof(LOGFONT),lf);
  }
  else
  {
    ::GetObject(GetStockObject(SYSTEM_FONT),sizeof(LOGFONT),lf);
  }
  CFontDialog fontdlg(lf,CF_SCREENFONTS|CF_INITTOLOGFONTSTRUCT);
  if(fontdlg.DoModal() == IDOK)
  {
    font->GetLogFont (lf);
    SetFont(font);
  }
}

为什么在红色那行时提示:Unhandled exception in [工程名].exe: Access Violation

怎么样才能正确设置字体呢?
您需要登录后才可以回帖 登录 | 加入易码

本版积分规则

Archiver|手机版|小黑屋|EMAX Studio

GMT+8, 2024-3-29 06:01 , Processed in 0.009854 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表