📄 processdir.cpp
字号:
/*
+------------------------------------------------------------+
| |
| (c) Copyright 2002, bigwhite, Inc. |
| |
| ALL RIGHTS RESERVED |
| |
+------------------------------------------------------------+
*/
/*==================================================================*
* processdir.cpp : Defines the class behaviors for the application.| |
* Version 1.1 |
*=================================================================*/
#include "stdafx.h"
#include "processdir.h"
#include "MainFrm.h"
#include "processdirDoc.h"
#include "processdirView.h"
#include "Splash.h"
#include "HyperLink.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CProcessdirApp
BEGIN_MESSAGE_MAP(CProcessdirApp, CWinApp)
//{{AFX_MSG_MAP(CProcessdirApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CProcessdirApp construction
CProcessdirApp::CProcessdirApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
GetModuleFileName(NULL,m_strFileName.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CProcessdirApp object
CProcessdirApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CProcessdirApp initialization
BOOL CProcessdirApp::InitInstance()
{
CString strClassName="CProcessdirApp";
m_hMutex=OpenMutex(MUTEX_ALL_ACCESS,FALSE,strClassName);
if(m_hMutex==NULL)//Verdict whether there has been an instance running in the system
{
m_hMutex=CreateMutex(NULL,TRUE,strClassName);
}
else{::AfxMessageBox("There has been an instance running in the system!",MB_OK|MB_ICONEXCLAMATION);
return FALSE;}
// CG: The following block was added by the Splash Screen component.\ {\ CCommandLineInfo cmdInfo;\ ParseCommandLine(cmdInfo);\\ CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);\ }
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.
SetDialogBkColor(RGB(166,166,190),RGB(123,0,0));
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CProcessdirDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CProcessdirView));
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_HIDE);//hide the mainframe
m_pMainWnd->UpdateWindow();
//CopyFile();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
void DrawTitleBar(CDC *pDC);
void DrawXPBmp(CDC *pDC,int ID,CPoint pt1,CPoint pt2);
public:
CRect m_rtButtExit; //关闭按钮位置
CRect m_rtIcon; //程序图标位置
private:
CHyperLink m_MyMailAddr;
// 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)
virtual BOOL OnInitDialog();
afx_msg void OnCancelMode();
//}}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)
DDX_Control(pDX, IDC_HYPERLINK_TEXT, m_MyMailAddr);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_WM_CANCELMODE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CProcessdirApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CProcessdirApp message handlers
BOOL CProcessdirApp::PreTranslateMessage(MSG* pMsg)
{
// CG: The following lines were added by the Splash Screen component. if (CSplashWnd::PreTranslateAppMessage(pMsg)) return TRUE; return CWinApp::PreTranslateMessage(pMsg);
}
int CProcessdirApp::ExitInstance()
{
BOOL bResult=TRUE;
HKEY hRegKey=NULL;
CString str;
str="Software\\Microsoft\\Windows\\CurrentVersion\\Run";
if(RegOpenKey(HKEY_LOCAL_MACHINE,str,&hRegKey)!=ERROR_SUCCESS)
bResult=FALSE;
else
{
_splitpath(m_strFileName.GetBuffer(0),NULL,NULL,str.GetBufferSetLength(MAX_PATH+1),NULL);
m_strFileName.ReleaseBuffer();
str.ReleaseBuffer();
//Modify the information of the Registry
if(::RegSetValueEx(hRegKey,str,0,REG_SZ,(CONST BYTE*)m_strFileName.GetBuffer(0),m_strFileName.GetLength())!=ERROR_SUCCESS)
bResult=FALSE;
else {bResult=TRUE;}
m_strFileName.ReleaseBuffer();
}
VERIFY(bResult);
if(m_hMutex!=NULL)
ReleaseMutex(m_hMutex);//需成对出现的,放在构造函数和析构函数中比较好
return CWinApp::ExitInstance();
}
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_MyMailAddr.SetURL(_T("mailto:loveyoubaiming@163.net"));
m_MyMailAddr.SetUnderline(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CAboutDlg::OnCancelMode()
{
CDialog::OnCancelMode();
}
////////////////////////////////
void CProcessdirApp::CopyFile()
{
SHFILEOPSTRUCT lpFileOp;
CString strToFilePath;
//CString strToFilePath="c:\\Windows";
//GetSystemDirectory( LPTSTR(strToFilePath),MAX_PATH);
GetSystemDirectory( strToFilePath.GetBuffer(0),MAX_PATH);
/*char FromFileName[MAX_PATH]="\0";
char ToFileName[MAX_PATH]="\0";
strcpy(FromFileName,m_strFileName);
strcpy(ToFileName,strToFilePath);
char*pos=strrchr(FromFileName,'//');
strcat(ToFileName,pos);
strcat(FromFileName,"\0");
strcat(ToFileName,"\0");*/
m_strFileName=m_strFileName+"\0";
strToFilePath=strToFilePath+"\\processdir.exe\0";
lpFileOp.hwnd=m_pMainWnd->GetSafeHwnd();
lpFileOp.wFunc=FO_COPY;
lpFileOp.pFrom=m_strFileName.GetBuffer(0);
lpFileOp.pTo=strToFilePath.GetBuffer(0);
lpFileOp.fFlags =FOF_ALLOWUNDO||FOF_SILENT ;
lpFileOp.fAnyOperationsAborted=FALSE;
lpFileOp.hNameMappings=NULL;
lpFileOp.lpszProgressTitle =NULL;
int rval=SHFileOperation(&lpFileOp);
if(rval==0)
{
if(lpFileOp.fAnyOperationsAborted==TRUE)
{
AfxMessageBox("put off",MB_OK);
}
else
{
AfxMessageBox("success",MB_OK);
}
}
else
{
AfxMessageBox("failure",MB_OK);
return;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -