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

📄 stracegui.cpp

📁 Strace: Webcrazy原来写的很好的代码
💻 CPP
字号:

#include "stdafx.h"
#include "StraceGui.h"

#include "MainFrm.h"
#include "StraceGuiDoc.h"
#include "ListCtrlEx.h"
#include "ListVwEx.h"
#include "ProcFilterDlg.h"
#include "StraceGuiView.h"

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



CString& GetLastErrorText(CString& buf)
{
    DWORD dwRet;
    LPTSTR lpszTemp = NULL;
    DWORD dwLastError = GetLastError();

    dwRet = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ARGUMENT_ARRAY,
                           NULL,
                           dwLastError,
                           LANG_NEUTRAL,
                           (LPTSTR)&lpszTemp,
                           0,
                           NULL );

    lpszTemp[lstrlen(lpszTemp)-2] = TEXT('\0');  //remove cr and newline character

    buf.Format(TEXT("%s (errorcode = %d)"), lpszTemp, dwLastError );
    
    if ( lpszTemp )
        LocalFree((HLOCAL) lpszTemp );

    return buf;
}


/////////////////////////////////////////////////////////////////////////////
// CStraceGuiApp

BEGIN_MESSAGE_MAP(CStraceGuiApp, CWinApp)
	//{{AFX_MSG_MAP(CStraceGuiApp)
	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)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStraceGuiApp construction

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

/////////////////////////////////////////////////////////////////////////////
// The one and only CStraceGuiApp object

CStraceGuiApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CStraceGuiApp initialization

BOOL CStraceGuiApp::InitInstance()
{
	if(AlreadyRunning())
	{
		AfxMessageBox(IDS_ALREADY_RUNNING,MB_OK|MB_ICONWARNING);
		return(FALSE);
	}

	AfxEnableControlContainer();
	char Path[MAX_PATH];


	GetCurrentDirectory( sizeof(Path), Path );

	sprintf( Path + strlen(Path), "\\%s", SYS_FILE );
	if ( ! LoadDeviceDriver( SYS_NAME, Path, &hDevice) )  {
		CString error;
		GetLastErrorText(error);
		AfxMessageBox(CString("装载Strace.sys时出错:")+error);
		return FALSE;

	}

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

	
	//SetRegistryKey(_T("Local AppWizard-Generated Applications"));
	//LoadStdProfileSettings();  

	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CStraceGuiDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CStraceGuiView));
	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_SHOW);
	m_pMainWnd->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)
	afx_msg void OnWeb();
	virtual BOOL OnInitDialog();
	//}}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
}

void CAboutDlg::OnWeb() 
{
	SHELLEXECUTEINFO shex;
	shex.cbSize = sizeof SHELLEXECUTEINFO;
	shex.fMask = SEE_MASK_NOCLOSEPROCESS;
	shex.hwnd = NULL;
	shex.lpVerb = _T("Open");
	shex.lpFile = WEBCRAZY_WEB_SITE;
	shex.lpParameters = NULL;
	shex.lpDirectory = NULL;
	shex.nShow = SW_NORMAL; 
	shex.hInstApp = 0;
	shex.lpIDList = NULL;
	shex.lpClass = NULL;
	shex.hkeyClass = 0;
	shex.dwHotKey = 0;
	shex.hIcon = 0; 
	shex.hProcess = 0; 
	ShellExecuteEx(&shex);	
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	ON_BN_CLICKED(IDOK2, OnWeb)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void CStraceGuiApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CStraceGuiApp commands

int CStraceGuiApp::ExitInstance() 
{
	// TODO: Add your specialized code here and/or call the base class
	CloseHandle(hDevice);
	if ( ! UnloadDeviceDriver( SYS_NAME ) )  {
		CString error;
		GetLastErrorText(error);
		AfxMessageBox(CString("卸载Strace.sys时出错: ")+error);
		return FALSE;
	}
	
	return CWinApp::ExitInstance();
}


void CStraceGuiApp::DoWaitCursor(int nCode) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	CWinApp::DoWaitCursor(nCode);
}

HANDLE CStraceGuiApp::GetDevice()
{
	return hDevice;
}


BOOL CStraceGuiApp::AlreadyRunning()
{
	BOOL bFound = FALSE;

	// Try to create a mutex with the app's name
	HANDLE hMutexOneInstance = ::CreateMutex(NULL,TRUE,_T(AfxGetAppName()));

	// Already there...means that we are already running an instance
	if(::GetLastError() == ERROR_ALREADY_EXISTS)
		bFound = TRUE;

	// Release the mutex
	if(hMutexOneInstance)
		::ReleaseMutex(hMutexOneInstance);

	return(bFound);
}

BOOL CAboutDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	char str[100];
    sprintf(str,__DATE__);
	strcat(str," ");
	strcat(str,__TIME__);
	strcat(str,"!");
	SetDlgItemText(IDC_DATETIME,str);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

⌨️ 快捷键说明

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