📄 gpssc.cpp
字号:
// GpsSC.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "GpsSC.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "GpsSCDoc.h"
#include "GpsSCView.h"
#include "SmscnumbSetDlg.h"
#include "MainWTNumberSetDlg.h"
#include "PassWordDlg.h"
#include "Splash.h"
#include "afxdb.h"
#include "odbcinst.h"
#include "GetHardDriveID.h"
#include "Registry.h"
#include "MyDlg.h"
#include "IniFile.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGpsSCApp
CString str_GetTreeItemText; //全局变量(获取树形控件子项)
extern BOOL GetHardDiskID(char szBuff[128]);
BEGIN_MESSAGE_MAP(CGpsSCApp, CWinApp)
//{{AFX_MSG_MAP(CGpsSCApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_SMSCNUMBERSETTING, OnSmscnumbersetting)
ON_UPDATE_COMMAND_UI(ID_SMSCNUMBERSETTING, OnUpdateSmscnumbersetting)
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGpsSCApp construction
CGpsSCApp::CGpsSCApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
strPassWord = "";
password = FALSE;
str_GetTreeItemText.Empty();
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CGpsSCApp object
CGpsSCApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CGpsSCApp initialization
extern BOOL GetHardDiskID(char szBuff[128]);
BOOL CGpsSCApp::InitInstance()
{
/* //注册用
char szBuff[20]="";
CString strBuff=GetCDiskID();
for(int nIndex=0;nIndex<8;nIndex++)
{
szBuff[nIndex]=strBuff.GetAt(nIndex);
}
szBuff[8]='\0';
if(RegiesterNow(szBuff)==false)
return false;
*/
//////////////////////////////////////////////////////////////////////////////////////////////////
// CG: The following block was added by the Splash Screen component.
//------------------注册DSN------------------------------
CString sPath;
char CurrPath[500];
long FatLen = 0;
long j;
for(j = 0; j < 500; j++) {
CurrPath[j] = 0;
}
//获取工程目录
::GetCurrentDirectory(500,CurrPath);
sPath = CurrPath;
m_strCurrPath = sPath;
m_strCurrPath += "\\Log\\";
CString lpszFile = sPath + "\\DataBase" + "\\CenterDataBase.mdb";
if (!IsFileExist(lpszFile))
{
AfxMessageBox("数据库文件路径不对!");
return FALSE;
}
SetFileReadOnly(lpszFile,false);
char* szDesc;
int mlen;
szDesc=new char[256];
sprintf(szDesc,"DSN=%s? DESCRIPTION=TOC support source? DBQ=%s? FIL=MicrosoftAccess? DEFAULTDIR=%s?? ","CenterDataBase",lpszFile,sPath);
mlen = strlen(szDesc);
for (int i=0; i<mlen; i++)
{
if (szDesc[i] == '?')
szDesc[i] = '\0';
}
CDatabase m_DB;
if (FALSE == SQLConfigDataSource(NULL,ODBC_ADD_DSN,"Microsoft Access Driver (*.mdb)\0",(LPCSTR)szDesc))
AfxMessageBox("SQLConfigDataSource Failed");
try
{
CString strConnect;
strConnect.Format("DSN=CenterDataBase;");
if(!m_DB.OpenEx(strConnect,CDatabase::useCursorLib))
{
AfxMessageBox("不能连接数据库!");
return FALSE ;
}
}
catch(CDBException *pE)
{
AfxMessageBox(pE->ReportError());
pE->Delete();
return FALSE;
}
//-------------------------------------------------------
CString FileName = m_strCurrPath+"log.ini";
SetFileStatus(FileName,false);
ReadLog(); //读日志
\
{
\
CCommandLineInfo cmdInfo;
\
ParseCommandLine(cmdInfo);
\
CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);
\
\
}
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
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)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_GPSSCTYPE,
RUNTIME_CLASS(CGpsSCDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CGpsSCView));
AddDocTemplate(pDocTemplate);
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
m_bUserType = true;
CPassWordDlg dlg;
if(dlg.DoModal() != IDOK)
return FALSE;
// The main window has been initialized, so show and update it.
pMainFrame->ShowWindow(SW_SHOWMAXIMIZED);
pMainFrame->UpdateWindow();
return TRUE;
}
//文件是否存在
long CGpsSCApp::IsFileExist(CString FileName)
{
long Flength = 0;
CFile f;
if(f.Open(FileName,CFile::modeRead,NULL)) {
Flength = f.GetLength();
f.Close();
}
return Flength;
}
void CGpsSCApp::SetFileReadOnly(CString FileName,bool ReadOnly)
{
if(!IsFileExist(FileName)) return;
CFileStatus fStatus;
CFile f;
if(!CFile::GetStatus(FileName,fStatus)) {
AfxMessageBox("出错!");
}
if(ReadOnly) {
fStatus.m_attribute = fStatus.m_attribute | 0x01;
}
else {
fStatus.m_attribute = fStatus.m_attribute & 0xfe;
}
CFile::SetStatus(FileName,fStatus);
}
/////////////////////////////////////////////////////////////////////////////
// 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 CGpsSCApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CGpsSCApp message handlers
//////////////////////////////////////////////////////////////////////////////
//名称:ExitInstance
//功能:退出时清除工作
/////////////////////////////////////////////////////////////////////////////
int CGpsSCApp::ExitInstance()
{
SaveLog(); //保存日志
CString FileName = m_strCurrPath+"log.ini";
SetFileStatus(FileName,true);
return CWinApp::ExitInstance();
}
void CGpsSCApp::OnSmscnumbersetting()
{
CSmscnumbSetDlg smnumdlg;
smnumdlg.m_sSMSCNumber = m_sSMNum;
if(smnumdlg.DoModal()==IDOK)
{
m_sSMNum = smnumdlg.m_sSMSCNumber;
}
m_sSMNum = smnumdlg.m_sSMSCNumber;
}
void CGpsSCApp::OnUpdateSmscnumbersetting(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
//create the password dialog
BOOL CGpsSCApp::CreatePassWordDlg()
{
CString strpass = GetProjectInDir();
strpass += "sysinit.ini";
CString str1 = GetPassWord(strpass);
CPassWordDlg dlg;
if(dlg.DoModal() == IDOK)
{
if(dlg.m_strPassWord == str1)
{
return TRUE;
}
else
return FALSE;
}
else
return FALSE;
}
//get the password
CString CGpsSCApp::GetPassWord(const CString strpassderectory)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -