📄 richtest.cpp
字号:
// richtest.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "richtest.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "IpFrame.h"
#include "richtestDoc.h"
#include "richtestView.h"
#include "myplot_idl.h"
#include "myplot_idl_i.c"
#include "myform.h"
#include "Splash.h"
#include <initguid.h>
#include "Richtest_i.c"
#include "systeminfo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//记录主任务和辅助任务
UINT g_nCurTask=0;
UINT g_nStep=0;
UINT g_nOpqTask=0;
UINT g_nOpqStep=0;
//记录对象捕捉
BOOL g_bOSnapped=FALSE;
//记录当前颜色和线性
UINT g_nCurColor=RGB(0,0,0);
UINT g_nCurLineType=PS_SOLID;
//记录当前鼠标状态
UINT g_nFlags=0;
double g_dCurX=0;
double g_dCurY=0;
double g_dPreX=0;
double g_dPreY=0;
double g_dOrgX=0;
double g_dOrgY=0;
//记录GRID,ORTHO,SNAP状态
BOOL g_bGrid=FALSE;
BOOL g_bOrtho=FALSE;
BOOL g_bSnap=FALSE;
//记录Grid大小和Snap大小
double g_dGrid=0.5;
double g_dSnap=0.5;
//记录对象捕捉类型和屏幕象素点距离
int g_nOSnapType=0;
int g_nOSnapSize=20;
//记录当前图形所在区域
double g_dMaxX=1;
double g_dMaxY=1;
double g_dMinX=-1;
double g_dMinY=-1;
double g_length=10;
class CCadView;
//记录当前活动视指针
CCadView* g_pCurView=NULL;
Imyplot* iplot;
/////////////////////////////////////////////////////////////////////////////
// CRichtestApp
BEGIN_MESSAGE_MAP(CRichtestApp, CWinApp)
//{{AFX_MSG_MAP(CRichtestApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_ADD_MOUDLE, OnAddMoudle)
ON_COMMAND(ID_REMOVE_MOUDLE, OnRemoveMoudle)
ON_UPDATE_COMMAND_UI(ID_ADD_MOUDLE, OnUpdateAddMoudle)
ON_COMMAND(ID_SYSINFO, OnSysinfo)
ON_COMMAND(ID_UPGRADE_MOUDLE, OnUpgradeMoudle)
ON_UPDATE_COMMAND_UI(ID_UPGRADE_MOUDLE, OnUpdateUpgradeMoudle)
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
void assign(command* op0,command& op,int);
/////////////////////////////////////////////////////////////////////////////
// CRichtestApp construction
CRichtestApp::CRichtestApp()
{unsigned lth=sizeof(command);
lth=sizeof(mydata);
for(unsigned int j=0;j<PROCESS_CNT;j++)
{
pcmd[j]=new command[COUNT_LIMIT];
for(int i=0;i<COUNT_LIMIT;i++)
pcmd[j][i].conector_cnt=0;
}
for(j=0;j<PROCESS_CNT;j++)
cmd_count[j]=0;
totalcnt=0;
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
//////////////////////////////// /////////////////////////////////////////////
// The one and only CRichtestApp object
CRichtestApp theApp;
CRichtestDoc* thedoc;
// This identifier was generated to be statistically unique for your app.
// You may change it if you prefer to choose a specific identifier.
// {F9B8EC34-A291-476C-80BC-C2ED500E0A74}
static const CLSID clsid =
{ 0xf9b8ec34, 0xa291, 0x476c, { 0x80, 0xbc, 0xc2, 0xed, 0x50, 0xe, 0xa, 0x74 } };
/////////////////////////////////////////////////////////////////////////////
// CRichtestApp initialization
BOOL CRichtestApp::InitInstance()
{
// CG: The following block was added by the Splash Screen component.\ {\ CCommandLineInfo cmdInfo;\ ParseCommandLine(cmdInfo);\\ CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);\ }
{ // BLOCK: doc template registration // Register the document template. Document templates serve // as the connection between documents, frame windows and views. // Attach this form to another document or frame window by changing // the document or frame class in the constructor below. // CMultiDocTemplate* pNewDocTemplate = new CMultiDocTemplate( // IDR_MYFORM_TMPL,// RUNTIME_CLASS(CRichtestDoc), // document class// RUNTIME_CLASS(CMDIChildWnd), // frame class// RUNTIME_CLASS(CRichtestView)); // view class// AddDocTemplate(pNewDocTemplate); }
// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
}
if (!InitATL())
return FALSE;
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
LPCSTR INIFILE=".\\richtest.ini";
WritePrivateProfileString("form","caption","mycaption",INIFILE);//初始化信息的保存读却
WritePrivateProfileString("form","index","1",INIFILE);
CString caption;
GetPrivateProfileString("form","caption","Default Caption",\
caption.GetBuffer(MAX_PATH),MAX_PATH,INIFILE);
int index=GetPrivateProfileInt("form","index",0,INIFILE);//
SYSTEMTIME time;
// GetLocalTime(&time);//获得系统时间";
// CString str_time;
// str_time.Format("%u/%u/%u %u %u:%u:%u:%u\n",time.wYear,time.wMonth,time.wDay,time.wDayOfWeek,time.wHour,\
// time.wMinute,time.wSecond,time.wMilliseconds);
// AfxMessageBox(str_time);
char buf[MAX_PATH];
unsigned drive_cnt=GetLogicalDriveStrings(MAX_PATH,buf);//获得逻辑驱动器,形如:A:\ c:\
if(this->loadcommand()!=S_OK)
AfxMessageBox("没有加载任何模块");
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_RICHTETYPE,
RUNTIME_CLASS(CRichtestDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CRichtestView));
pDocTemplate->SetContainerInfo(IDR_RICHTETYPE_CNTR_IP);
pDocTemplate->SetServerInfo(
IDR_RICHTETYPE_SRVR_EMB, IDR_RICHTETYPE_SRVR_IP,
RUNTIME_CLASS(CInPlaceFrame));
AddDocTemplate(pDocTemplate);
// Connect the COleTemplateServer to the document template.
// The COleTemplateServer creates new documents on behalf
// of requesting OLE containers by using information
// specified in the document template.
m_server.ConnectTemplate(clsid, pDocTemplate, FALSE);
// Register all OLE server factories as running. This enables the
// OLE libraries to create objects from other applications.
COleTemplateServer::RegisterAll();
_Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER,
REGCLS_MULTIPLEUSE);
// Note: MDI applications register all server objects without regard
// to the /Embedding or /Automation on the command line.
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
// Enable drag/drop open
m_pMainWnd->DragAcceptFiles();
// Enable DDE Execute open
EnableShellOpen();
RegisterShellFileTypes(TRUE);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Check to see if launched as OLE server
if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
{
// Application was run with /Embedding or /Automation. Don't show the
// main window in this case.
return TRUE;
}
// When a server application is launched stand-alone, it is a good idea
// to update the system registry in case it has been damaged.
m_server.UpdateRegistry(OAT_INPLACE_SERVER);
_Module.UpdateRegistryFromResource(IDR_RICHTEST, TRUE);
_Module.RegisterServer(TRUE);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The main window has been initialized, so show and update it.
pMainFrame->ShowWindow(SW_SHOWMAXIMIZED);
pMainFrame->UpdateWindow();
if(FAILED(CoInitialize(NULL)))//初始化组件
AfxMessageBox("组件库初试化错误");
IUnknown* up;
HRESULT hr=CoCreateInstance(CLSID_myplot,NULL,CLSCTX_INPROC,IID_IUnknown,(void**)&up);
if(!(FAILED(hr)))
hr=up->QueryInterface(IID_Imyplot,(void**)&iplot);
if(FAILED(hr))
{
AfxMessageBox("没有找到绘图组件");
}
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
// No message handlers
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CRichtestApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CRichtestApp message handlers
command** CRichtestApp::getcmd()
{
return pcmd;
}
unsigned int* CRichtestApp::getcmdcnt()
{return cmd_count;
}
unsigned int CRichtestApp::getcmd_cnt(unsigned int level)
{
return cmd_count[level];
}
int CRichtestApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
this->unloadcommand();
for(unsigned int i=0;i<PROCESS_CNT;i++)
if(pcmd!=NULL)
delete[] pcmd[i];
//pcmd=NULL;
if (m_bATLInited)
{
_Module.RevokeClassObjects();
_Module.Term();
}
CoUninitialize();
return CWinApp::ExitInstance();
}
//CRichtestApp::
//void add_moudle(char* name,int name_length,char* info,int info_length,char* where,int size)
//{
// (pcmd+cmd_count)->attach(cmd_count,name,name_length,info,info_length,where,size);
// cmd_count++;
//}
void CRichtestApp::OnAddMoudle()
{
// TODO: Add your command handler code here
//readmoduleinfo item(pcmd+cmd_count,cmd_count++);
command tempcmd;
unsigned int tempcnt=0;
readmoduleinfo item(&tempcmd,tempcnt);
CString tempname,cmdname;
int ok=item.InputData();
if(ok==-1)
goto over;
if(ok==0)
AfxMessageBox("错误的模块导入文件");
else
{
grade level=tempcmd.level;
for(unsigned int i=0;i<cmd_count[level];i++)//模块是否已经存在或者明明冲突
{
tempname=CString(tempcmd.cmd_name);
cmdname=CString(pcmd[level][i].cmd_name);
if(cmdname==tempname)
{
AfxMessageBox("导入模块名称与以前导入的模块重复,加载无效");
goto over;
}
else if(pcmd[level][i].clsid==tempcmd.clsid)
{
AfxMessageBox("模块以前已经加载,加载无效");
goto over;
}
}
assign(pcmd[level]+i,tempcmd,cmd_count[level]++);
totalcnt++;
int c=0;
AfxMessageBox("模块加载成功");
return;
}
over:
AfxMessageBox("模块加载失败");;
return;
}
void CRichtestApp::OnRemoveMoudle()
{
// TODO: Add your command handler code here
}
void CRichtestApp::OnUpdateAddMoudle(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
unsigned int CRichtestApp::loadcommand()
{
CFile* filebin;
CString cmdfilename="commands.cmds";
filebin=new CFile(cmdfilename,CFile::modeRead);
if(filebin!=NULL)
{
CArchive ar(filebin,CArchive::load);
unsigned long i=filebin->GetLength();
if(i>(unsigned long)0)
{for(unsigned int i=0;i<PROCESS_CNT;i++)
{ar>>cmd_count[i];
for(unsigned int j=0;j<cmd_count[i];j++)
ar>>pcmd[i][j];
}
}
ar.Close();
filebin->Close();
for(i=0;i<PROCESS_CNT;i++)
totalcnt+=cmd_count[i];
return S_OK;
}
return S_FALSE;
}
void CRichtestApp::unloadcommand()
{static char* bag0,*bag;
CString cmdfilename="commands.cmds";
CFile* filebin=new CFile(cmdfilename,CFile::modeCreate|CFile::modeWrite);
if(filebin!=NULL&&cmd_count!=0)
{
CArchive ar(filebin,CArchive::store);
for(unsigned int i=0;i<PROCESS_CNT;i++)
{ar<<cmd_count[i];
for(unsigned int j=0;j<cmd_count[i];j++)
ar<<pcmd[i][j];
}
ar.Close();
filebin->Close();
}
}
BOOL CRichtestApp::PreTranslateMessage(MSG* pMsg)
{
// CG: The following lines were added by the Splash Screen component. if (CSplashWnd::PreTranslateAppMessage(pMsg)) return TRUE; return CWinApp::PreTranslateMessage(pMsg);
}
CRichtestModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
END_OBJECT_MAP()
LONG CRichtestModule::Unlock()
{
AfxOleUnlockApp();
return 0;
}
LONG CRichtestModule::Lock()
{
AfxOleLockApp();
return 1;
}
BOOL CRichtestApp::InitATL()
{
m_bATLInited = TRUE;
_Module.Init(ObjectMap, AfxGetInstanceHandle());
_Module.dwThreadID = GetCurrentThreadId();
return TRUE;
}
void CRichtestApp::OnSysinfo()
{
// TODO: Add your command handler code here
systeminfo item;
item.DoModal();
}
void CRichtestApp::OnUpgradeMoudle()
{
// TODO: Add your command handler code here
command tempcmd;
unsigned int tempcnt=0;
int index=-1;
readmoduleinfo item(&tempcmd,tempcnt);
CString tempname,cmdname;
int ok=item.InputData();
if(ok==-1)
goto over;
if(ok==0)
AfxMessageBox("错误的模块导入文件,升级无效");
else
{
grade level=tempcmd.level;
for(unsigned int i=0;i<cmd_count[level];i++)
{
tempname=CString(tempcmd.cmd_name);
cmdname=CString(pcmd[level][i].cmd_name);
if(pcmd[level][i].clsid==tempcmd.clsid)
{
index=i;
goto goon;
}
else if(cmdname==tempname)
{
index=i;
goto goon;
}
}
goon:
assign(pcmd[level]+index,tempcmd,pcmd[level][index].cmd_id);
int c=0;
AfxMessageBox("模块升级成功");
return;
}
over:
AfxMessageBox("模块升级无效");
return;
;
}
void CRichtestApp::OnUpdateUpgradeMoudle(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -