📄 parksys.cpp
字号:
// ParkSys.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "ParkSys.h"
#include "MainFrm.h"
#include "ParkSysDoc.h"
#include "ParkSysView.h"
#include "DlgLogin.h"
#include "syncclock.h"
#include "led.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CParkSysApp
BEGIN_MESSAGE_MAP(CParkSysApp, CWinApp)
//{{AFX_MSG_MAP(CParkSysApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_SYNCCLOCK, OnSyncclock)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CParkSysApp construction
CParkSysApp::CParkSysApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
hMutex = 0;
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CParkSysApp object
CParkSysApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CParkSysApp initialization
BOOL CParkSysApp::InitInstance()
{
hMutex = CreateMutex(NULL, TRUE, "ParkSysRunExclusively");
if(!(hMutex != 0 && GetLastError() != ERROR_ALREADY_EXISTS))
//an instance is running now, so exit this instance
{
AfxMessageBox("程序已经在运行,请用ALT+TAB切换到活动的系统!");
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
//打开数据库
TRY
{
database.Open( "DSN_Vicaly",
FALSE, FALSE,
"ODBC;UID=sa;PWD=" );
//database.SetSynchronousMode(TRUE);
}
CATCH(CDBException, e)
{
TRY
{
CString str;
str.LoadString(IDS_DATABASE_DSN);
database.OpenEx(str,
CDatabase::useCursorLib | CDatabase::forceOdbcDialog);
}
CATCH_ALL(e1)
{
AfxMessageBox(_T("不能打开系统数据库!\n"), MB_ICONSTOP);
return FALSE;
}
END_CATCH_ALL
}
END_CATCH
//Victor Lee Add the following code, in order to
//synchronize the clocks on server and workstation
CSyncClock SyncClock(&theApp.database);
SyncClock.Open();
CTime dtServer = SyncClock.m_datetimeServer;
SyncClock.Close();
CTime dtClient = CTime::GetCurrentTime();
CString strMsg = "本机时间与服务器上的不一致。\n\r 服务器:";
strMsg += dtServer.Format("%Y-%m-%d %H:%M:%S");
strMsg += "\n\r 本机:";
strMsg += dtClient.Format("%Y-%m-%d %H:%M:%S");
strMsg += "\n\r确认后,系统会自动同步!";
CTimeSpan timeSpan = dtServer - dtClient;
if ( timeSpan.GetTotalSeconds() > 30 )
//误差小于30秒认为是同步。
{
if (AfxMessageBox(strMsg, MB_OKCANCEL | MB_ICONINFORMATION) == IDOK)
{
SyncClock.Open();
CTime dtServer = SyncClock.m_datetimeServer;
SyncClock.Close();
//将本机时间设成与服务器同步
CSyncClock::SetSystemTime(dtServer);
}
else
return FALSE;
}
CDlgLogin dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
}
else if (nResponse == IDCANCEL)
{
return FALSE;
}
// Change the registry key under which our settings are stored.
// 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.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CParkSysDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CParkSysView));
AddDocTemplate(pDocTemplate);
// 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;
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
m_pMainWnd->UpdateWindow();
CMainFrame* p = (CMainFrame*)AfxGetMainWnd();
p_view = p->GetActiveView();
AfxGetMainWnd()->SetWindowText("停车场管理系统");
//阅读器
CParkSysView* p1=(CParkSysView*)p_view;
//显示视频
//计算位置
CRect staticClient;
CWnd* pWnd = p_view->GetDlgItem(IDC_STATICENINFO);
pWnd->GetWindowRect(&staticClient);
CRect rcClip;
p_view->GetWindowRect(&rcClip);
BOOL rel = avi.capInit((CWnd*)p_view,staticClient.left+18,
staticClient.top - rcClip.top + 20,270,200,
AVI_WINDOW_INID, 0);
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)
//}}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)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CParkSysApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CParkSysApp commands
CString CParkSysApp::ExtractFilePath()
{
TCHAR exeFullPath[MAX_PATH]; // MAX_PATH在API中定义了吧,好象是128
GetModuleFileName(NULL,exeFullPath,MAX_PATH);
CString strFullPath(exeFullPath);
strFullPath.TrimRight();
strFullPath.TrimLeft();
return strFullPath.Left(strFullPath.ReverseFind('\\') + 1);
}
int CParkSysApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
ASSERT(hMutex);
CloseHandle(hMutex); //Close the mutex for next time running
return CWinApp::ExitInstance();
}
void CParkSysApp::OnSyncclock()
{
// TODO: Add your command handler code here
CSyncClock syncClock(&theApp.database);
syncClock.Open();
CTime dtServer = syncClock.m_datetimeServer;
syncClock.Close();
//将本机时间设成与服务器同步
CSyncClock::SetSystemTime(dtServer);
AfxMessageBox("本地机器的时钟被服务器同步。");
}
HANDLE CParkSysApp::ExecApp(const CString& strCommandLine, LPPROCESS_INFORMATION lpProcessinfo, LPSTARTUPINFO lpStartinfo)
{
STARTUPINFO startinfo;
ZeroMemory(&startinfo, sizeof(STARTUPINFO));
startinfo.cb = sizeof(STARTUPINFO);
if(lpStartinfo == NULL)
{
lpStartinfo = &startinfo;
}
PROCESS_INFORMATION processinfo;
if(lpProcessinfo == NULL)
{
lpProcessinfo = &processinfo;
}
// TODO: Add your control notification handler code here
char szCmd[300];
wsprintf(szCmd, "%s", strCommandLine);
if (!CreateProcess(NULL,
szCmd,
NULL,
NULL,
FALSE,
CREATE_NEW_PROCESS_GROUP,
NULL,
NULL,
lpStartinfo,
lpProcessinfo))
{
AfxMessageBox("调用失败,参数为: " + strCommandLine);
AfxThrowUserException();
return HANDLE(0);
}
else
{
return HANDLE(lpProcessinfo->hProcess);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -