📄 filemasys.cpp
字号:
// FileMaSys.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "FileMaSys.h"
#include "FileMaSysDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFileMaSysApp
BEGIN_MESSAGE_MAP(CFileMaSysApp, CWinApp)
//{{AFX_MSG_MAP(CFileMaSysApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFileMaSysApp construction
CFileMaSysApp::CFileMaSysApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CFileMaSysApp object
CFileMaSysApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CFileMaSysApp initialization
BOOL CFileMaSysApp::InitInstance()
{
// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
}
if (!AfxInitRichEdit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
}
AfxEnableControlContainer();
CoInitialize(NULL);
//获得程序启动路径
CHAR exePath[MAX_PATH];
GetModuleFileName(NULL,exePath,MAX_PATH);
CString StartPath;
StartPath=exePath;
int index=StartPath.ReverseFind('\\');
index++;
StartPath=StartPath.Left(index);
StartPath+="ProjectManageSys.mdb";
_bstr_t b=(_bstr_t)StartPath;
m_pConnection.CreateInstance("ADODB.Connection");
try
{
m_pConnection->ConnectionTimeout = 8;
m_pConnection->PutCursorLocation(adUseClient);
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='"+b+"'",
"","",adModeUnknown);
}
catch (_com_error &e)
{
AfxMessageBox("数据库连接失败!");
return FALSE;
}
//判断控件是否注册
if (!IsInstalled())
{
AfxMessageBox("控件没有注册");
if (RegControl())
{
AfxMessageBox("控件注册成功");
}
}
// 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
// Parse the command line to see if launched as OLE server
if (RunEmbedded() || RunAutomated())
{
// Register all OLE server (factories) as running. This enables the
// OLE libraries to create objects from other applications.
COleTemplateServer::RegisterAll();
}
else
{
// When a server application is launched stand-alone, it is a good idea
// to update the system registry in case it has been damaged.
COleObjectFactory::UpdateRegistryAll();
}
CFileMaSysDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
BOOL CFileMaSysApp::IsInstalled()
{
HKEY hKey;
BOOL bPresent;
TCHAR szPath[MAX_PATH];
DWORD dwRegType;
DWORD cbData = sizeof(szPath) *sizeof (TCHAR) ;
hKey = NULL;
bPresent = FALSE;
::RegOpenKey(HKEY_CLASSES_ROOT,_T("CLSID\\{CDE57A43-8B86-11D0-B3C6-00A0C90AEA82}\\InprocServer32"),&hKey);
if(hKey)
{
HANDLE hfile;
szPath[0] = 0;
::RegQueryValueEx(hKey,NULL,NULL,&dwRegType,(LPBYTE)szPath,&cbData);
::RegCloseKey(hKey);
hfile=::CreateFile(szPath,0,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);
if(INVALID_HANDLE_VALUE != hfile)
{
bPresent = TRUE;
::CloseHandle(hfile);
}
}
return bPresent;
}
//注册控件
BOOL CFileMaSysApp::RegControl()
{
TCHAR AppFullPath[MAX_PATH];
GetModuleFileName(NULL,AppFullPath,MAX_PATH);
CString m_AppPath;
m_AppPath=AppFullPath;
int iAppPosition;
iAppPosition=m_AppPath.ReverseFind('\\');
m_AppPath=m_AppPath.Mid(0,iAppPosition+1);
char pOCXPath[100];
FARPROC lpDllEntryPoint;
HINSTANCE hLib;
CString m_OCXFileName("MSDATGRD.OCX");
sprintf(pOCXPath,"%s%s",m_AppPath,m_OCXFileName);
CString strDes("C:\\WINDOWS\\system32\\");
//把控件拷贝C盘系统目录下
strDes +=m_OCXFileName;
CopyFile(pOCXPath,strDes,FALSE);
ShellExecute(NULL,"open","Regsvr32.exe","/s MSDATGRD.OCX",NULL,SW_SHOW);
return TRUE;
/* hLib=LoadLibrary(strDes);
if(hLib)
{
lpDllEntryPoint=(FARPROC)GetProcAddress(hLib,_T("DllRegisterServer"));
if(lpDllEntryPoint!=NULL)
{
(*lpDllEntryPoint)();
FreeLibrary(hLib);
return TRUE;
}
else
{
return FALSE;
}
}*/
// return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -