Microsoft.Office.Interop.Word.Document doc = null
object missing = System.Reflection.Missing.Value
object templateFile = Application.StartupPath + @"\word模板.doc"try
{
app = new Microsoft.Office.Interop.Word.ApplicationClass()
doc = app.Documents.Add(ref templateFile, ref missing, ref missing, ref missing)
try
{
foreach (Microsoft.Office.Interop.Word.Bookmark bm in doc.Bookmarks)
{
bm.Select()
string item = bm.Name
if (item.Equals("title")) //word中的书签名"title"
{
bm.Range.Text = title//title为要替换书签的变量, //即可以将数据库中的值读入title中
}
}
}
catch
{ } //打印 doc.PrintOut(ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing)
}
catch (Exception exp)
{
MessageBox.Show(exp.Message, this.Text)
} //结束word进程 finally
{
object saveChange = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges
if (doc != null) doc.Close(ref saveChange, ref missing, ref missing)
if (app != null) app.Quit(ref missing, ref missing, ref missing)
} break} 希望能帮到你!
如果只是为了d出一个字符串显示,用:
AfxMessageBox(_T("A String"))如果是在已有对话框显示一个字符串,那么对话框增加一个静态框,修改静态框ID为IDC_STATIC1(不能不修改,否则无法显示),然后程序的任意对话框函数里面:
GetDlgItem(IDC_STATIC1)->SetWindowText(_T("A String"))MFC里这个类叫做CToolTipCtrl,具体用法很简单。1、声明CToolTipCtrl的类对象m_ctrlTT。
2、在初始化函数中设置m_ctrlTT。
EnableToolTips(TRUE)//enable use it
m_ctrlTT.Create(this)
m_ctrlTT.Activate(TRUE)
m_ctrlTT.SetTipTextColor(RGB(0,0,255))//font color
m_ctrlTT.SetDelayTime(150)//delay time
//IDC_TEST为你想添加提示的控件IDC,"hello为想添加的提示语句"
m_ctrlTT.AddTool(GetDlgItem(IDC_TEST),(LPCTSTR)"hello")
3、在ClassWizard里添加PreTranslateMessage函数,并添加如下语句。
m_ctrlTT.RelayEvent(pMsg)
这样就能为你的控件添加显示提示语句了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)