
在Ccopyright 类NewDocument()方法中的代码,主要就是增加必要的版权信息到文档中,此处主要是说明怎样操作VC环境中文档,大家也得到具体的Windows来修改窗口的形状和属性,怎么修改就要看各自的想象力了。
| HRESULT CCopyright::NewDocument(IDispatch* theDocument) { CComQIPtr <ITextDocument,&IID_ITextDocument> pTextDoc(theDocument); HRESULT hr = S_OK; CComBSTR bstrLang; if (pTextDoc == NULL) return hr; hr = pTextDoc->get_Language(&bstrLang); if (FAILED(hr)) return hr; //µÃµ½Îļ þÀàÐÍ£¬²¢ µÃ³ö¶ÔÓ¦µÄ ×¢ÊÍ·û CComBSTR bstrComment; if (bstrLang == DS_CPP) bstrComment = L"//"; else if (bstrLang == DS_HTML_IE3 || bstrLang == DS_HTML_RFC1866) bstrComment = L"<!--"; else if (bstrLang == DS_IDL) bstrComment = L"//"; else if (bstrLang == DS_VBS) bstrComment = L"\'"; else if (bstrLang == DS_JAVA) bstrComment = L"//"; else bstrComment = L";"; CComBSTR bstrType; hr = pTextDoc->get_Type(&bstrType); if(FAILED(hr)) return hr; if(bstrType == DS_TEXT_DOCUMENT) { CComQIPtr <ITextSelection,&IID_ITextSelection> pTextSel; CComPtr<IDispatch> pDisp; hr = pTextDoc->get_Selection(&pDisp); if(FAILED(hr)) return hr; pTextSel = pDisp; hr = pTextSel->StartOfDocument(CComVariant()); return hr; SYSTEMTIME st; GetLocalTime(&st); TCHAR strDate[30]; TCHAR strYear[5]; wsprintf(strYear,_T("%ld"),st.wYear); wsprintf(strDate,_T("%ldÄê%ldÔÂ%ldÈÕ"),st.wYear,st.wMonth,st.wDay); CComBSTR bstrText; bstrText = bstrComment; bstrText += "\n"; if (!(bstrLang == DS_HTML_IE3 || bstrLang == DS_HTML_RFC1866)) bstrText += bstrComment; bstrText += L" °æÈ¨ËùÓÐ(C) Robin Hohai University "; bstrText += strYear; bstrText += L"\n"; if (!(bstrLang == DS_HTML_IE3 || bstrLang == DS_HTML_RFC1866)) bstrText += bstrComment; bstrText += L"\n"; if (!(bstrLang == DS_HTML_IE3 || bstrLang == DS_HTML_RFC1866)) bstrText += bstrComment; bstrText += L" ×÷ Õߣº"; bstrText += m_bstrName; bstrText += L" E-mail£º"; bstrText += m_bstrEmail; bstrText += L"\n"; if (!(bstrLang == DS_HTML_IE3 || bstrLang == DS_HTML_RFC1866)) bstrText += bstrComment; bstrText += L"\n"; if (!(bstrLang == DS_HTML_IE3 || bstrLang == DS_HTML_RFC1866)) bstrText += bstrComment; bstrText += L" ´´½¨ÈÕÆÚ£º"; bstrText += strDate; bstrText += L"\n"; if (!(bstrLang == DS_HTML_IE3 || bstrLang == DS_HTML_RFC1866)) bstrText += bstrComment; if (bstrLang == DS_HTML_IE3 || bstrLang == DS_HTML_RFC1866) bstrText += L" -->"; bstrText += L"\n"; hr = pTextSel->put_Text(bstrText); } return hr; } |