⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 paradlg.cpp

📁 写入WORD;动态画曲线;查看磁盘资源等。
💻 CPP
字号:
// ParaDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Demo.h"
#include "ParaDlg.h"
#include "msword9.h"
//#include <mmsystem.h>
#include <AtlBase.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CParaDlg dialog
BOOL m_bCheckMode = FALSE;//检测模式(F:力检测;T:扭检测)
extern CDemoApp theApp;

CParaDlg::CParaDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CParaDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CParaDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_dataFont.CreateFont(-25,15,0,0,700,FALSE,FALSE,
		0,134,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_SWISS,"楷体_GB2312");
}


void CParaDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CParaDlg)
	DDX_Control(pDX, IDC_CONTROL1, m_chart);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CParaDlg, CDialog)
	//{{AFX_MSG_MAP(CParaDlg)
	ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart)
	ON_BN_CLICKED(IDC_RADIO_LI, OnRadioLi)
	ON_BN_CLICKED(IDC_RADIO_NIU, OnRadioNiu)
	ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
	ON_BN_CLICKED(IDC_BUTTON_GETFREE, OnButtonGetfree)
	ON_BN_CLICKED(IDC_BUTTON_WRITEWORD, OnButtonWriteword)
	ON_WM_CREATE()
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CParaDlg message handlers

void CParaDlg::OnOK() 
{
	// TODO: Add extra validation here
	
//	CDialog::OnOK();
}

BOOL CParaDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_bCheckMode = FALSE;
	((CButton *)GetDlgItem(IDC_RADIO_LI))->SetCheck(1);
	GetDlgItem(IDC_STATIC_MODENAME)->SetFont(&m_dataFont);
	CString strx="脉冲个数", stry="力(N)";	
	m_chart.Init(100, 10000, 1, -100, 0);
	m_chart.SetBGColor(RGB(255, 255, 255));
	m_chart.SetTextX(strx);
	m_chart.SetTextY(stry);
	m_chart.DrawGrad(1000, 10);
	double p[1]={0.0};
	m_chart.Draw(TRUE,p);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CParaDlg::OnButtonStart() 
{
	// TODO: Add your control notification handler code here
	if(theApp.m_strModeName == "")
	{
		MessageBox("请选择产品型号!","警告!",MB_OK|MB_ICONERROR);
		return;
	}
//	AfxMessageBox(theApp.m_strModeName);
	double p[1]={0.0};
	m_chart.SetStep(10);
	for(int i = 0; i < 1000; i ++)
	{
		p[0] = rand()%70;
		m_chart.Draw(TRUE,p);
	}
	
	m_chart.SetStep(-10);
	for(i = 0; i < 1000; i ++)
	{
		p[0] = 0-(10 + rand()%20);
		m_chart.Draw(TRUE,p);
	}
}

void CParaDlg::OnRadioLi() 
{
	// TODO: Add your control notification handler code here
	m_bCheckMode = FALSE;
	CString strx="脉冲个数", stry="力(N)";	
	m_chart.Init(100, 10000, 1, -100, 0);
	m_chart.SetBGColor(RGB(255, 255, 255));
	m_chart.SetTextX(strx);
	m_chart.SetTextY(stry);
	m_chart.DrawGrad(1000, 10);
	double p[1]={0.0};
	m_chart.Draw(TRUE,p);
}

void CParaDlg::OnRadioNiu() 
{
	// TODO: Add your control notification handler code here
	m_bCheckMode = TRUE;	
	CString strx="脉冲个数", stry="扭矩(N*M)";	
	m_chart.Init(100, 10000, 1, -100, 0);
	m_chart.SetBGColor(RGB(255, 255, 255));
	m_chart.SetTextX(strx);
	m_chart.SetTextY(stry);
	m_chart.DrawGrad(1000, 10);
	double p[1]={0.0};
	m_chart.Draw(TRUE,p);
}

void CParaDlg::OnButtonStop() 
{
	// TODO: Add your control notification handler code here GetDiskFreeSpace()

}

int CParaDlg::GetDiskFree(CString DiskName)//得到磁盘剩余容量(单位:G)
{
	CString strshow;
	int m_fFreeSpace;
	DWORD   sector,Byte,cluster,free;   
//    long   int   freespace,totalspace;   
    GetDiskFreeSpace(DiskName,&sector,&Byte,&free,&cluster);  
	if(DiskName == "C:\\")
	{
//		m_fFreeSpace = free / 1024.0 / 128.0;(单位为:G)
		m_fFreeSpace = free / 128;//(单位为:M)
	//	strshow.Format("%d- %d- %d- %d",sector,Byte,free,cluster);
	//	AfxMessageBox(strshow);
	}
	if(DiskName == "D:\\")
	{
		m_fFreeSpace = free / 128;
	//	strshow.Format("%d- %d- %d- %d",sector,Byte,free,cluster);
	//	AfxMessageBox(strshow);
	}
	if(DiskName == "E:\\")
	{
		m_fFreeSpace = free / 64;
	//	strshow.Format("%d- %d- %d- %d",sector,Byte,free,cluster);
	//	AfxMessageBox(strshow);
	}
	if(DiskName == "F:\\")
	{
		m_fFreeSpace = free / 256;
	//	strshow.Format("%d- %d- %d- %d",sector,Byte,free,cluster);
	//	AfxMessageBox(strshow);
	}
//    totalspace=(cluster)*(Byte)*(sector)/1024/1024;   
//    freespace=(free)*(Byte)*(sector)/1024/1024;
	return m_fFreeSpace;
}

void CParaDlg::OnButtonGetfree() 
{
	// TODO: Add your control notification handler code here
//////////////////////////////////////////////////////////////////////////
//得到剩余空间
	int getFree[4];
	CString strshow,Name;
	Name = "C:\\";
	getFree[0] = GetDiskFree(Name);
	Name = "D:\\";
	getFree[1] = GetDiskFree(Name);
	Name = "E:\\";
	getFree[2] = GetDiskFree(Name);
	Name = "F:\\";
	getFree[3] = GetDiskFree(Name);

	strshow.Format("C盘剩余空间为:%dM    即为:%.2fG\n\nD盘剩余空间为:%dM    即为:%.2fG\n\nE盘剩余空间为:%dM    即为:%.2fG\n\nF盘剩余空间为:%dM    即为:%.2fG\n",
		getFree[0],getFree[0]/1024.0,getFree[1],getFree[1]/1024.0,getFree[2],getFree[2]/1024.0,getFree[3],getFree[3]/1024.0);
//	AfxMessageBox(strshow);
	MessageBox(strshow,"系统信息",MB_OK);

//////////////////////////////////////////////////////////////////////////
//得到系统的分辩率
	int x = GetSystemMetrics(SM_CXSCREEN);
	int y = GetSystemMetrics(SM_CYSCREEN);

	strshow.Format("当前分辨率为:%d * %d\n",x,y);
	AfxMessageBox(strshow);
//////////////////////////////////////////////////////////////////////////
//获得Windows系统目录
	char windir[MAX_PATH];
	GetSystemDirectory(windir,MAX_PATH);
	strshow.Format("Windows的系统目录是:%s\n",windir);
	AfxMessageBox(strshow);
//////////////////////////////////////////////////////////////////////////
//获得CPU的信息
	char s[20];

//结构LPSYSTEM_INFO包含当前计算机信息,包括处理器的结构、类型和数量等。
	LPSYSTEM_INFO mysys;
	mysys = new SYSTEM_INFO;

	GetSystemInfo(mysys);

	// dwNumberOfProcessors为系统中CPU的数量。
	_itoa(mysys->dwNumberOfProcessors,s,10);
	strshow.Format("CPU的数量为:%s\n",s);
	AfxMessageBox(strshow);

	// dwProcessorType为CPU的类型。
	_itoa(mysys->dwProcessorType,s,10);
	strshow.Format("CPU的类型为:%s\n",s);
	AfxMessageBox(strshow);

	switch (mysys->wProcessorLevel)
	{
	case 3:
	    strshow = "Intel 80386";
		break;
	case 4:
		strshow = "Intel 80486"; 
		break;
	case 5:
		strshow = "Pentium";
		break;
	default:
		strshow = "未知的CPU";
		break;
	}

	strshow = "CPU的型号为:" + strshow + "\n";
	AfxMessageBox(strshow);

	// wProcessorRevision为CPU的修订版本。Windows 95/98系统不用。
	_itoa(mysys->wProcessorRevision,s,10);
	strshow.Format("CPU的修订版本为:%s\n",s);
	AfxMessageBox(strshow);

	delete mysys;

}

void CParaDlg::OnButtonWriteword() 
{
	// TODO: Add your control notification handler code here
	BeginWaitCursor();

	COleVariant vTrue((short)TRUE), vFalse((short)FALSE),
	vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

	_Application m_App;//定义Word提供的应用程序对象;
	Documents m_Docs;//定义Word提供的文档对象;
	Selection m_Sel;//定义Word提供的选择对象;
	m_Docs.ReleaseDispatch();
	m_Sel.ReleaseDispatch();
	m_App.m_bAutoRelease=true;
	if(!m_App.CreateDispatch("Word.Application"))
	{ 
		AfxMessageBox("创建Word2000服务失败!"); 
	//	exit(1); 
		return;
	}

	//下面是定义VARIANT变量;
	COleVariant varFilePath("c:\\word表格.doc");
	COleVariant varstrNull("");
	COleVariant varZero((short)0);
	COleVariant varTrue(short(1),VT_BOOL);
	COleVariant varFalse(short(0),VT_BOOL);


	m_Docs.AttachDispatch(m_App.GetDocuments());//将Documents类对象m_Docs和Idispatch接口关联起来;
	m_Docs.Open(varFilePath,varFalse,varFalse,varFalse,
	varstrNull,varstrNull,varFalse,varstrNull,
	varstrNull,varTrue,varTrue,varTrue);
	//打开Word文档; 
	m_Sel.AttachDispatch(m_App.GetSelection());//将Selection类对象m_Sel和Idispatch接口关联起来;

	m_Sel.MoveDown(COleVariant((short)4),COleVariant((short)1),COleVariant((short)0));
	m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
	m_Sel.TypeText("123456789");
	m_Sel.MoveRight(COleVariant((short)1),COleVariant((short)1),COleVariant((short)0));
	m_Sel.TypeText("李明");
	m_Sel.MoveRight(COleVariant((short)1),COleVariant((short)1),COleVariant((short)0));
	m_Sel.TypeText("25");
	m_Sel.MoveRight(COleVariant((short)1),COleVariant((short)1),COleVariant((short)0));
	m_Sel.TypeText("技术员");
	m_Sel.MoveRight(COleVariant((short)1),COleVariant((short)1),COleVariant((short)0));
	m_Sel.TypeText("本科");
	m_Sel.MoveRight(COleVariant((short)1),COleVariant((short)1),COleVariant((short)0));
	m_Sel.TypeText("上海市虹口区民主路315号");
//	m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
	m_Sel.MoveRight(COleVariant((short)1),COleVariant((short)1),COleVariant((short)0));
	m_Sel.TypeText("上海市");
	m_Sel.MoveRight(COleVariant((short)1),COleVariant((short)1),COleVariant((short)0));
	m_Sel.TypeText("上海市");
	m_Sel.MoveRight(COleVariant((short)1),COleVariant((short)1),COleVariant((short)0));
	m_Sel.TypeText("上海市");
	m_Sel.MoveRight(COleVariant((short)1),COleVariant((short)1),COleVariant((short)0));
	m_Sel.TypeText("上海市");
	m_Sel.MoveRight(COleVariant((short)1),COleVariant((short)1),COleVariant((short)0));
	m_Sel.TypeText("上海市");
	m_Sel.MoveRight(COleVariant((short)1),COleVariant((short)1),COleVariant((short)0));
	m_Sel.TypeText("上海市");
	
	m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
//	m_Sel.MoveRight(COleVariant((short)1),COleVariant((short)2),COleVariant((short)0));
	Selection sel=m_App.GetSelection();
	InlineShapes   shps;
	shps=sel.GetInlineShapes();   
    CComVariant ccc(sel.GetRange());
	shps.AddPicture("C:\\1.jpg",COleVariant((short)FALSE),COleVariant((short)TRUE),&ccc);

	//save word file
	_Document oActiveDoc; 
	oActiveDoc = m_App.GetActiveDocument(); 
	oActiveDoc.SaveAs(COleVariant("c:\\填写后表格.doc"), 
	COleVariant((short)0), 
	vFalse, COleVariant(""), vTrue, COleVariant(""), 
	vFalse, vFalse, vFalse, vFalse, vFalse);
//	m_App.SetVisible(TRUE);	
	MessageBox("word表格填写完毕!","提示",MB_ICONEXCLAMATION);	
	
	m_Docs.ReleaseDispatch();//断开关联;
	m_Sel.ReleaseDispatch();

	//退出WORD 
	m_App.Quit(vOpt, vOpt, vOpt); 
	m_App.Quit(vOpt, vOpt, vOpt);
	m_App.ReleaseDispatch();

	EndWaitCursor();

}

int CParaDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here

	return 0;
}

void CParaDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default

	CDialog::OnClose();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -