MFC ActiveX容器类
/***************************************************************************** Description: ActiveX control view in the mfc Frame Author: liangjc Version: 1.0 Create Date: 2014.3.12 15:40 History: null ---------------------------------------------------------------------- Revise Date: // 修改日期 Revise Author: // 修改者 Revise Content: // 修改内容 ---------------------------------------------------------------------- *****************************************************************************/ #define IDC_SHOWCTL 10000 class CActiveXControl : public CWnd { protected: DECLARE_DYNCREATE(CActiveXControl); CDialog * ParentWndPtr; public: CLSID const& GetClsid() { static CLSID const clsid = { 0x651722ed, 0xc80b, 0x4d7f, { 0x86, 0xb9, 0x32, 0xdf, 0x30, 0x37, 0xa8, 0xbe } }; return clsid; } virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL) { return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID); } BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CFile* pPersist = NULL, BOOL bStorage = FALSE, BSTR bstrLicKey = NULL) { return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID, pPersist, bStorage, bstrLicKey); } public: CActiveXControl(CDialog *CwndPtr); CActiveXControl(); ~CActiveXControl(void); short Load(); BOOL SetProp(LPCTSTR type, long operation,long operation2=0); long FindPnt(short type, LPCTSTR strFindTz, LPCTSTR strFindTag); void PrintPreview(); };
#include "stdafx.h" #include "dblstctl.h" ///////////////////////////////////////////////////////////////////////////// // CDbLstCtl IMPLEMENT_DYNCREATE(CActiveXControl, CWnd) ///////////////////////////////////////////////////////////////////////////// // CDbLstCtl properties ///////////////////////////////////////////////////////////////////////////// // CDbLstCtl operations short CActiveXControl::Load() { CRect rectEdit(0,0,200,500); short result = -1; if(this->Create(NULL,WS_CHILD|WS_VISIBLE|WS_MAXIMIZEBOX,rectEdit,ParentWndPtr,IDC_SHOWCTL)) { InvokeHelper(0x1, DISPATCH_METHOD, VT_I2, (void*)&result, NULL); } return result; } //BOOL CDbLstCtl::SetProp(LPCTSTR type, long operation) BOOL CActiveXControl::SetProp(LPCTSTR type, long operation,long operation2) { BOOL result; static BYTE parms[] = VTS_BSTR VTS_I4; InvokeHelper(0x2, DISPATCH_METHOD, VT_BOOL, (void*)&result, parms,type, operation); return result; } long CActiveXControl::FindPnt(short type, LPCTSTR strFindTz, LPCTSTR strFindTag) { long result; static BYTE parms[] = VTS_I2 VTS_BSTR VTS_BSTR; InvokeHelper(0x3, DISPATCH_METHOD, VT_I4, (void*)&result, parms,type, strFindTz, strFindTag); return result; } void CActiveXControl::PrintPreview() { InvokeHelper(0x4, DISPATCH_METHOD, VT_EMPTY, NULL, NULL); } CActiveXControl::~CActiveXControl() { CWnd::~CWnd(); } CActiveXControl::CActiveXControl() { CWnd::CWnd(); } CActiveXControl::CActiveXControl(CDialog *CwndPtr) { ParentWndPtr = CwndPtr; CWnd::CWnd(); }
调用方式:
/* * add the ActiveX control view */ m_ActiveXControl_View = NULL; m_ActiveXControl_View = new CActiveXControl(this); if(-1 == m_ActiveXControl_View->Load()) { delete m_ActiveXControl_View; m_ActiveXControl_View = NULL; } ModifyStyle(0,WS_THICKFRAME,0); MoveWindow(200,100,1000,600,TRUE);
单进程:
::CreateMutex(NULL, TRUE, "XDCNET XDbList.exe"); if(GetLastError()==ERROR_ALREADY_EXISTS) { //关闭原进程 HANDLE handle = NULL; HWND hand = NULL; DWORD dProcessID = 0; dProcessID = GetPIDByName("XDbList.exe");//Get Process by ProcessName handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dProcessID); TerminateProcess(handle, 0); } DWORD CDialogApp::GetPIDByName(CString Name) { PROCESSENTRY32 pe32; pe32.dwSize = sizeof(pe32); HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if(hProcessSnap == INVALID_HANDLE_VALUE) { return 0; } BOOL bMore = ::Process32First(hProcessSnap, &pe32); while(bMore) { if(_stricmp(pe32.szExeFile,Name)==0) { return pe32.th32ProcessID; ::CloseHandle(hProcessSnap); } bMore = ::Process32Next(hProcessSnap, &pe32); } ::CloseHandle(hProcessSnap); return 0; }