www.pudn.com > DSPSample.rar > DSPSampleDlg.cpp


// DSPSampleDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "DSPSample.h" 
#include "DSPSampleDlg.h" 
#include "FileSendDlg.h" 
#include "DSP.h" 
#include "HGF.h" 
#include "PPQ.h" 
#include "DSPFile.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// DSPSampleDlg dialog 
 
DSPSampleDlg::DSPSampleDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(DSPSampleDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(DSPSampleDlg) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void DSPSampleDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(DSPSampleDlg) 
		// NOTE: the ClassWizard will add DDX and DDV calls here 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(DSPSampleDlg, CDialog) 
	//{{AFX_MSG_MAP(DSPSampleDlg) 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1) 
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// DSPSampleDlg message handlers 
 
BOOL DSPSampleDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	// Set the icon for this dialog.  The framework does this automatically 
	//  when the application's main window is not a dialog 
	SetIcon(m_hIcon, TRUE);			// Set big icon 
	SetIcon(m_hIcon, FALSE);		// Set small icon 
	 
	// TODO: Add extra initialization here 
	 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
// If you add a minimize button to your dialog, you will need the code below 
//  to draw the icon.  For MFC applications using the document/view model, 
//  this is automatically done for you by the framework. 
 
void DSPSampleDlg::OnPaint()  
{ 
	if (IsIconic()) 
	{ 
		CPaintDC dc(this); // device context for painting 
 
		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); 
 
		// Center icon in client rectangle 
		int cxIcon = GetSystemMetrics(SM_CXICON); 
		int cyIcon = GetSystemMetrics(SM_CYICON); 
		CRect rect; 
		GetClientRect(&rect); 
		int x = (rect.Width() - cxIcon + 1) / 2; 
		int y = (rect.Height() - cyIcon + 1) / 2; 
 
		// Draw the icon 
		dc.DrawIcon(x, y, m_hIcon); 
	} 
	else 
	{ 
		CDialog::OnPaint(); 
	} 
} 
 
// The system calls this to obtain the cursor to display while the user drags 
//  the minimized window. 
HCURSOR DSPSampleDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
void DSPSampleDlg::OnButton1()  
{ 
	// TODO: Add your control notification handler code here 
	FileSendDlg dlg; 
	dlg.DoModal(); 
} 
 
void DSPSampleDlg::OnButton2()  
{ 
	// TODO: Add your control notification handler code here 
	DSP::RegisterAct("PPQ.DSP",&PPQ::GetDSPObject); 
 
	ofstream ofs; 
	DSP::OpenOfstreamForWrite(ofs,"testObject.txt",ios::app); 
//	DSP::OpenOfstreamForWrite(ofs,"testObject.txt"); 
 
	PPQ	pp; 
	pp.m_bBOOL	=TRUE; 
	pp.m_bBool	=true; 
	pp.m_byValue=111; 
	pp.m_cValue	=23; 
	pp.m_dwValue=456789; 
	pp.m_iValue	=-456789; 
	pp.m_sValue	=-23456; 
	pp.m_wValue	=23456; 
	pp.m_str	="this is test2dfsd.中华人民共和国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共this"; 
	pp.m_str.append("和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国sec"); 
	pp.m_str.append("和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国国中华人民共和国中华人民共和国中华人民共和国中华人民共和国this is end."); 
	pp.m_hgf.m_byValue			=45; 
	pp.m_hgf.m_sValue			=-12345; 
	pp.m_hgf.m_wValue			=12345; 
	pp.m_hgf.m_hCVB.bEnd		=TRUE; 
	pp.m_hgf.m_hCVB.bFlag		=FALSE; 
	pp.m_hgf.m_hCVB.bReset		=FALSE; 
	pp.m_hgf.m_hCVB.byCount		=57; 
	pp.m_hgf.m_hCVB.byType		=198; 
	pp.m_hgf.m_hCVB.dwSum		=9876543; 
	pp.m_hgf.m_hCOMB.bEnd		=FALSE; 
	pp.m_hgf.m_hCOMB.byCount	=97; 
	pp.m_hgf.m_hCOMB.byType		=79; 
	pp.m_hgf.m_hCOMB.strDetail	="this is string var in struct.这是一个在结构中的字符串变量."; 
	pp.m_hgf.m_hCOMB.strApp		="这是一个CString变量,测试读出和保存。"; 
 
	bool bRun	=true; 
	DSP::_DSPPACKET dp(bRun); 
	dp.SetParameter(FALSE,FALSE); 
	dp.WriteObject(ofs,pp); 
 
	ofs.flush(); 
	ofs.close(); 
 
	ifstream ifs; 
	DSP::OpenIfstreamForRead(ifs,"testObject.txt"); 
 
	dp.Empty(); 
	DSPACT* pAct	=dp.ReadObject(ifs); 
 
	DSP::_DSPERROR* error	=dp.GetLastError(); 
 
	PPQ* pq	=(PPQ*)pAct; 
	int size	=pq->m_str.length(); 
 
	HGF hf; 
	pAct	=dp.ReadObject(ifs,&hf); 
 
	while(true) 
	{ 
		pAct	=dp.ReadObject(ifs); 
		if(ifs.eof() || pAct!=NULL) 
			break; 
	} 
	 
	pq	=(PPQ*)pAct; 
 
	ifs.close(); 
}