CDocument *,m_pDocument,CArchive,CFile [英] CDocument*, m_pDocument, CArchive, CFile

查看:91
本文介绍了CDocument *,m_pDocument,CArchive,CFile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了具有文档/视图支持&的可序列化 SDI 应用程序.我想从主菜单&只需单击一下即可打开安静地的某个文件(无需调用提示CFileDialog的类).然后在virtual void Serialize(CArchive& ar);函数中执行其余代码. &当然,请在关闭或下次重新打开时清除当前文档.
我想知道应该使用什么代码序列来确保此&我应该实现(CWinAppCDocumentCFrameWndCView)类的哪个类.

请帮助我解决此问题. :sigh:

I created a serializable SDI application with Document/View support & I want to Open a certain file Silently (Without having to call the prompting CFileDialog Class) in just one click from the main menu & then do the rest of code in the virtual void Serialize(CArchive& ar); function. & of course clear the current document on closing it or on the next reopening.
I am wondering what sequence of code should I use to ensure this & what class of the (CWinApp, CDocument, CFrameWnd or the CView) classes should I implement that code.

Help me please to solve this issue. :sigh:

推荐答案

我猜CWinApp :: OpenDocumentFile应该可以完成工作
I guess CWinApp::OpenDocumentFile should do the job


这是一个可能的开始:):
Here is a possible start :) :
class CYourDoc : public CDocument
{
  DECLARE_DYNCREATE(CYourDoc)

private:
  COLORREF m_clrBackColor; // some content :)

protected:
  CYourDoc();

public:
  virtual ~CYourDoc();
  
  virtual void Serialize(CArchive& ar);
};

IMPLEMENT_DYNCREATE(CYourDoc, CDocument)

void CYourDoc::Serialize(CArchive& ar)
{
  if (ar.IsStoring()) {
    ar << m_clrBackColor;
  } else {
    ar >> m_clrBackColor;
  } 
}


这篇关于CDocument *,m_pDocument,CArchive,CFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆