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

📄 monitor.cpp

📁 电脑编程技巧和源码。很不错的。
💻 CPP
字号:
// Monitor.cpp : Defines the class behaviors for the application.
//
#include <afxpriv.h>
#include "stdafx.h"
#include "Monitor.h"

#include "MainFrm.h"
#include "ChildFrm.h"
#include "MonitorDoc.h"
#include "LeftView.h"
#include "UserlistView.h"
#include "UserlistWnd.h"
#include "OleDb.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMonitorApp

BEGIN_MESSAGE_MAP(CMonitorApp, CWinApp)
	//{{AFX_MSG_MAP(CMonitorApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	ON_COMMAND(ID_FILE_NEW, OnFileNew)
	ON_COMMAND(ID_SWITCH_MONITOR, OnSwitchMonitor)
	ON_COMMAND(ID_SWITCH_USERLIST, OnSwitchUserlist)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMonitorApp construction

CMonitorApp::CMonitorApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CMonitorApp object

CMonitorApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CMonitorApp initialization

BOOL CMonitorApp::InitInstance()
{
	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(0);  // 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.

	m_pMonitorDocTemplate = new CMultiDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CMonitorDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CLeftView));
	AddDocTemplate(m_pMonitorDocTemplate);
	m_pListDocTemplate = new CMultiDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CMonitorDoc),
		RUNTIME_CLASS(CUserListWnd), // custom MDI child frame
		RUNTIME_CLASS(CUserListView));
	AddDocTemplate(m_pListDocTemplate);

	// create main MDI Frame window
	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;

	// The main window has been initialized, so show and update it.
	pMainFrame->SetWindowText("监视程序");
	m_nCmdShow=SW_SHOWMAXIMIZED;
	pMainFrame->ShowWindow(m_nCmdShow);
	pMainFrame->UpdateWindow();

	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 CMonitorApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CMonitorApp message handlers


void CMonitorApp::OnFileNew() 
{
	// TODO: Add your command handler code here
	USES_CONVERSION;
	COleDb myDb;
	cNumRows=0;
    HRESULT hr = CoInitialize(0);
	if(FAILED(hr))
	{
		AfxMessageBox("初始化COM失败,退出程序");
		CoUninitialize();
	}
	hr=myDb.OpenDB(&m_DataSource,&m_Session,"Microsoft.Jet.OLEDB.3.51",
		"C:\\My Documents\\guest.mdb","Admin","");
	if(FAILED(hr))
	{
		AfxMessageBox("OpenDB失败,退出程序");
		goto Error;
	}
	hr=myDb.Excute(&m_Session,m_pIOpenRowset,m_pICreateCommand,m_pICommandText,
		&m_pIRowset,L"SELECT * FROM totaltypes order by `编号`",&cNumRows);
    if(FAILED(hr))
    {
		AfxMessageBox("Execute失败,退出程序");
		goto Error;
	}
	hr=myDb.Binding(m_pIRowset,&m_pIAccessor,&hAccessor,&pBindings,&lNumCols);
    if(FAILED(hr))
    {
		AfxMessageBox("Binding失败,退出程序");
		goto Error;
	}
	hr=myDb.GetTypesList(m_pIRowset,hAccessor,&TypeList);
    if(FAILED(hr))
    {
		AfxMessageBox("GetData失败,退出程序");
		goto Error;
	}

	
	hr=myDb.Excute(&m_Session,m_pIOpenRowset,m_pICreateCommand,m_pICommandText,
		&m_pIRowset,L"SELECT * FROM namepass order by `用户名`",&cNumRows);
    if(FAILED(hr))
    {
		AfxMessageBox("Execute失败,退出程序");
		goto Error;
	}
	hr=myDb.Binding(m_pIRowset,&m_pIAccessor,&hAccessor,&pBindings,&lNumCols);
    if(FAILED(hr))
    {
		AfxMessageBox("Binding失败,退出程序");
		goto Error;
	}
	hr=myDb.GetAllUserData(m_pIRowset,hAccessor,&AllUserList);
    if(FAILED(hr))
    {
		AfxMessageBox("GetData失败,退出程序");
		goto Error;
	}

	{int length=AllUserList.GetSize();
	int i;
	CString strSQL="SELECT * FROM usertype WHERE `用户名` IN ";
	CString UserName;
	for(i=0;i<length;i++)
	{
		UserName=UserName+"'"+((CXhinfo*)AllUserList.GetAt(i))->Name+"',";
	}
	UserName.Delete(UserName.GetLength()-1);
	UserName="("+UserName+")";
	strSQL=strSQL+UserName+" ORDER BY `用户名`";
	hr=myDb.Excute(&m_Session,m_pIOpenRowset,m_pICreateCommand,m_pICommandText,
		&m_pIRowset,T2COLE((LPCTSTR)strSQL),&cNumRows);
    if(FAILED(hr))
	{
		AfxMessageBox("Execute失败,退出程序");
		goto Error;
	}
	hr=myDb.Binding(m_pIRowset,&m_pIAccessor,&hAccessor,&pBindings,&lNumCols);
    if(FAILED(hr))
	{
		AfxMessageBox("Binding失败,退出程序");
		goto Error;
	}
	hr=myDb.GetUserTypeData(m_pIRowset,hAccessor,&AllUserList);
	if(FAILED(hr))
    {
		AfxMessageBox("GetData失败,退出程序");
		goto Error;
	}
	}

	m_pMonitorDoc=(CMonitorDoc*)m_pMonitorDocTemplate->OpenDocumentFile(NULL);
	m_pListDoc=(CMonitorDoc*)m_pListDocTemplate->OpenDocumentFile(NULL);

	return;

Error:
	if(m_pIAccessor!=NULL) m_pIAccessor->Release();
	if(m_pIRowset!=NULL) m_pIRowset->Release();
	if(m_pIColumnsInfo!=NULL) m_pIColumnsInfo->Release();
	if(m_pICommandText!=NULL) m_pICommandText->Release();
	if(m_pICreateCommand!=NULL) m_pICreateCommand->Release();
	m_Session.Close();
	m_DataSource.Close();
	CoUninitialize();
	return;
}

void CMonitorApp::OnSwitchMonitor() 
{
	// TODO: Add your command handler code here
	CWnd *pP,*pV;
	POSITION ps;
	ps=m_pListDoc->GetFirstViewPosition();
	pV=(CWnd*)m_pListDoc->GetNextView(ps);
	pP=pV->GetParent();
	pP->ShowWindow(SW_HIDE);
	ps=m_pMonitorDoc->GetFirstViewPosition();
	pV=(CWnd*)m_pMonitorDoc->GetNextView(ps);
	pP=pV->GetParent();
	pP=pP->GetParent();
	pP->BringWindowToTop();
}

BOOL CMonitorApp::SaveData()
{
	return TRUE;
}

void CMonitorApp::OnSwitchUserlist() 
{
	// TODO: Add your command handler code here
	CWnd *pP,*pV;
	POSITION ps;
	ps=m_pMonitorDoc->GetFirstViewPosition();
	pV=(CWnd*)m_pMonitorDoc->GetNextView(ps);
	pP=pV->GetParent();
	pP=pP->GetParent();
	pP->ShowWindow(SW_HIDE);
	ps=m_pListDoc->GetFirstViewPosition();
	pV=(CWnd*)m_pListDoc->GetNextView(ps);
	pP=pV->GetParent();
	pP->BringWindowToTop();
	
}

⌨️ 快捷键说明

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