【VC开源代码栏目提醒】:本文主要为网学会员提供IniFileView.cpp,希望对需要IniFileView.cpp网友有所帮助,学习一下!
// IniFileView.cpp : implementation of the CIniFileView class
//
#include "stdafx.h"
#include "IniFile.h"
#include "IniFileDoc.h"
#include "IniFileView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CIniFileView
IMPLEMENT_DYNCREATE(CIniFileView, CView)
BEGIN_MESSAGE_MAP(CIniFileView, CView)
//{{AFX_MSG_MAP(CIniFileView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CIniFileView construction/destruction
CIniFileView::CIniFileView()
{
// TODO: add construction code here
m_nXPos = 0;
m_nXPos = 0;
m_strText = "";
}
CIniFileView::~CIniFileView()
{
}
BOOL CIniFileView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CIniFileView drawing
void CIniFileView::OnDraw(CDC* pDC)
{
CIniFileDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDC->TextOut(m_nXPos, m_nYPos, m_strText);
}
/////////////////////////////////////////////////////////////////////////////
// CIniFileView printing
BOOL CIniFileView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CIniFileView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CIniFileView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CIniFileView diagnostics
#ifdef _DEBUG
void CIniFileView::AssertValid() const
{
CView::AssertValid();
}
void CIniFileView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CIniFileDoc* CIniFileView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CIniFileDoc)));
return (CIniFileDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CIniFileView message handlers
void CIniFileView::OnInitialUpdate()
{
CView::OnInitialUpdate();
TCHAR exeFullPath[MAX_PATH]; // MAX_PATH在API中有定义,为128
int len=GetModuleFileName(NULL,
exeFullPath, // 应用程序的全路径存放地址
MAX_PATH);
CString path = "\\IniFile.ini"; // 配置文件名
::strcpy(exeFullPath + len - 12,path); // 组合出配置文件的全路径
path = CString(exeFullPath);
m_nXPos = GetPrivateProfileInt("SECTION1", // 节名
"XPos", // 项名
0, // 没找到此项时的缺省返回值
path); // 配置文件的准确路径
m_nYPos = GetPrivateProfileInt("SECTION 1","YPos",0,path);
char buf[256];
len = GetPrivateProfileString("SECTION2", // 节名
"Text", // 项名
"No Text", // 没找到此项时的返回值
buf, // 目标缓冲区地址
256, // 目标缓冲区长度
path); // 配置文件的准确路径
for (int i=0;i<len;i++)
{
CString str;
str.Format("%c",buf[i]);
m_strText+=str;
}
Invalidate();
}
上一篇:
Frm_Gszl.frm
下一篇:
科研管理杂志简介