📄 oleviewerdoc.cpp
字号:
// OLEViewerDoc.cpp : implementation of the COLEViewerDoc class
//
#include "stdafx.h"
#include "OLEViewer.h"
#include "OLEViewerDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// COLEViewerDoc
IMPLEMENT_DYNCREATE(COLEViewerDoc, CDocument)
BEGIN_MESSAGE_MAP(COLEViewerDoc, CDocument)
//{{AFX_MSG_MAP(COLEViewerDoc)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COLEViewerDoc construction/destruction
COLEViewerDoc::COLEViewerDoc()
{
m_pListView = NULL;
m_pTreeView = NULL;
}
COLEViewerDoc::~COLEViewerDoc()
{
m_pListView = NULL;
m_pTreeView = NULL;
}
BOOL COLEViewerDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// COLEViewerDoc serialization
void COLEViewerDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// COLEViewerDoc diagnostics
#ifdef _DEBUG
void COLEViewerDoc::AssertValid() const
{
CDocument::AssertValid();
}
void COLEViewerDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// COLEViewerDoc commands
BOOL COLEViewerDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
//如果会话对象有打开的行集,则调用智能指针的
//Release()函数释放
if (m_Session.m_spOpenRowset != NULL)
m_Session.m_spOpenRowset.Release();
m_strConnect = _T("");
//一种弹出属性链接对话框的方式,若链接正确,则打开一个数据源
if( m_Connect.Open( AfxGetMainWnd()->GetSafeHwnd() ) != S_OK)
{
AfxMessageBox(_T("Unable to connect to data source"));
return FALSE;
}
else
{
USES_CONVERSION;
//创建会话对象
if (m_Session.Open(m_Connect) != S_OK)
{
AfxMessageBox(_T("Couldn't create session on data source"));
return FALSE;
}
//由属性得到所数据源的名字
CComVariant var;
m_Connect.GetProperty(DBPROPSET_DATASOURCEINFO, DBPROP_DATASOURCENAME, &var);
m_strConnect = OLE2T(var.bstrVal);
//使视的m_pSession指针指向上面创建的会话对象
m_pTreeView->m_pSession = &m_Session;
m_pListView->m_pSession = &m_Session;
RefreshViews();
return TRUE;
}
return FALSE;
}
CString COLEViewerDoc::GetDSN()
{
CString string = m_strConnect;
return string;
}
void COLEViewerDoc::OnFileOpen()
{
OnOpenDocument(NULL);
}
void COLEViewerDoc::RefreshViews()
{
//刷新左视
if (m_pTreeView)
m_pTreeView->PopulateTree();
//刷新右视
if (m_pListView)
m_pListView->EraseList();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -