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

📄 falcon_jxc.cpp

📁 面向软件工程的Visual C++网络程序开发
💻 CPP
字号:
// FALCON_JXC.cpp : Defines the class behaviors for the application.
////

#include "stdafx.h"
#include "FALCON_JXC.h"

#include "MainFrm.h"
#include "IpFrame.h"
#include "FALCON_JXCDoc.h"
#include "FALCON_JXCView.h"
#include "SkinMagicLib.h"
#include "logindlg.h"
#include "DlgBasicInfo.h"
#include "ServerAddressandPortSetting.h"
#include "TLHELP32.H"//一定要加如这个头文件
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CFALCON_JXCApp

BEGIN_MESSAGE_MAP(CFALCON_JXCApp, CWinApp)
	//{{AFX_MSG_MAP(CFALCON_JXCApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CFALCON_JXCApp construction

CFALCON_JXCApp::CFALCON_JXCApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
	m_ProcessIndex=0;
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CFALCON_JXCApp object

CFALCON_JXCApp theApp;

// This identifier was generated to be statistically unique for your app.
// You may change it if you prefer to choose a specific identifier.

// {5EABF381-AACE-4CC2-9B7B-E735A9E94806}
static const CLSID clsid =
{ 0x5eabf381, 0xaace, 0x4cc2, { 0x9b, 0x7b, 0xe7, 0x35, 0xa9, 0xe9, 0x48, 0x6 } };

/////////////////////////////////////////////////////////////////////////////
// CFALCON_JXCApp initialization

BOOL CFALCON_JXCApp::InitInstance()
{
	if (!AfxSocketInit())
	{
		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
		return FALSE;
	}

	// Initialize OLE libraries
	if (!AfxOleInit())
	{
		AfxMessageBox(IDP_OLE_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
	//限定此程序只能运行一次,用互斥量来判断程序是否已运行
    HANDLE m_hMutex=CreateMutex(NULL,TRUE, m_pszAppName); 
    if(GetLastError()==ERROR_ALREADY_EXISTS) 
	{
		ReleaseMutex(m_hMutex);
		AfxMessageBox("已有一个本程序的进程在运行!");
//-------------------------------------------------------------------sxg
		HANDLE Snapshot;
		Snapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
		//获得某一时刻系统的进程、堆(heap)、模块(module)或线程的快照信息
		PROCESSENTRY32 processListStr;
		processListStr.dwSize=sizeof(PROCESSENTRY32);
		BOOL return_value;
		return_value=Process32First(Snapshot,&processListStr);
		//获得系统进程链表中第一个进程的信息
		int i=0;//item index
		while(return_value)
		{

			int memory=processListStr.cntThreads;
			CString sss=processListStr.szExeFile;
			if(sss=="FALCON_JXC.exe")
			{
				m_ProcessIndex=processListStr.th32ProcessID;//save ID into array to teminate 
				break;
			}
			return_value=Process32Next(Snapshot,&processListStr);
			//获得系统进程链表中下一个进程的信息
			i++;
		}

		CString FileBuffer;//获得进程的可执行文件的文件名
		FileBuffer=CString(TEXT("确实要终止进程:FALCON_JXC.exe?"));
		if(AfxMessageBox(FileBuffer,MB_OKCANCEL,0)==IDOK)
		{//先获得该进程句柄,通过进程标识
			HANDLE ProcessHandle;
			ProcessHandle=OpenProcess(PROCESS_ALL_ACCESS,FALSE,m_ProcessIndex);
			//利用数组ID指定的获得存在的一个进程的句柄
			if(ProcessHandle)
			{
				TerminateProcess(ProcessHandle,0);
				AfxMessageBox("指定进程已终止!");
				
			}
			else
			{
				AfxMessageBox("系统不允许终止指定进程!");
				return FALSE;
			}
		}

//-------------------------------------------------------------------
	}
	

	// 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.

	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CFALCON_JXCDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CFALCON_JXCView));
	pDocTemplate->SetServerInfo(
		IDR_SRVR_EMBEDDED, IDR_SRVR_INPLACE,
		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, TRUE);
		// Note: SDI applications register server objects only if /Embedding
		//   or /Automation is present on the command line.

	// 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)
	{
		// Register all OLE server (factories) as running.  This enables the
		//  OLE libraries to create objects from other applications.
		COleTemplateServer::RegisterAll();

		// 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);

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;
	VERIFY( 1 == InitSkinMagicLib( AfxGetInstanceHandle(), "Demo" , 
		NULL,
		NULL ) );
	
	VERIFY( 1 == LoadSkinFromResource( AfxGetInstanceHandle(), "devior","SKINMAGIC") ); 
	
	VERIFY( 1 == SetWindowSkin( m_pMainWnd->m_hWnd , "MainFrame"));
//	SetWindowSkin( m_pMainWnd->m_hWnd , "MainFrame");
	VERIFY( 1 == SetDialogSkin( "Dialog" ) );
	((CMainFrame*)m_pMainWnd)->m_bSkinned = TRUE;
	((CMainFrame*)m_pMainWnd)->m_nIndex = 0;
	// The one and only window has been initialized, so show and update it.
//	m_pMainWnd->SetWindowText("方恒进销存客户端");//-Falcon Soft

	m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
	m_pMainWnd->UpdateWindow();
	// Enable drag/drop open
	m_pMainWnd->DragAcceptFiles();
	OpenDocumentFile("1.fjxc");
	m_pMainWnd->SetWindowText("方恒进销存客户端");//-Falcon Soft
	
	CFALCON_JXCDoc* pDoc=(CFALCON_JXCDoc*)((CMainFrame*)m_pMainWnd)->GetActiveView()->GetDocument();

	CServerAddressandPortSetting sap;
	if(sap.DoModal()==IDOK)
	{
		pDoc->m_strAddress=sap.m_sServerAddress;
		pDoc->m_nPort=sap.m_nPort;
	}
	

	CLoginDlg ld;
	if(ld.DoModal()==IDOK)
	{
		if(!pDoc->GetQuanXian(ld.m_sUserName))return false;
		if(pDoc->m_sQuanXianArray[1]!=ld.m_sPassword)
		{
			AfxMessageBox("密码错误!系统将退出。");
			return false;
		}

	}
	else
		return false;




//		
/*	CMainFrame* pwnd=(CMainFrame*)AfxGetApp()->m_pMainWnd;
	CFALCON_JXCView* pView=(CFALCON_JXCView*)pwnd->GetActiveView();
	CDlgBasicInfo dlg;
	if(dlg.DoModal() == IDOK)
	{
		pView->m_sShangchangmingcheng = dlg.m_sShangchangmingcheng;
		pView->m_sShouyinyuan = dlg.m_sShouyinyuan;
	}
	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 CFALCON_JXCApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CFALCON_JXCApp message handlers

/*
void CFALCON_JXCApp::OnFileOpen() 
{
	CString strFilter;
	strFilter = _T("所有图象文件( *.fjxc)|*.fjxc|Windows 位图(*.bmp)|*.bmp|所有文件(*.*)|*.*||");
	
	CFileDialog dlg(TRUE, "bmp", "*.bmp", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, (LPCTSTR)strFilter);
	if(dlg.DoModal() == IDCANCEL) return ;	
//	OnFileNew();

	CString strFileName=dlg.GetPathName();	
	CFALCON_JXCDoc* pDoc=(CFALCON_JXCDoc*)((CMainFrame*)m_pMainWnd)->GetActiveView()->GetDocument();
	pDoc->OnOpenDocument(strFileName);
//	OpenDocumentFile(strFileName);
	m_pMainWnd->SetWindowText("方恒进销存客户端");//-FALCON SOFT
//	m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
}
*/

⌨️ 快捷键说明

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