home *** CD-ROM | disk | FTP | other *** search
- // ole_vbx.cpp : Defines the class behaviors for the application.
- //
-
- #include "stdafx.h"
- #include "ole_vbx.h"
-
- #include "mainfrm.h"
- #include "ole_vdoc.h"
- #include "ole_vvw.h"
-
- #include "abcauto.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // COle_vbxApp
-
- BEGIN_MESSAGE_MAP(COle_vbxApp, CWinApp)
- //{{AFX_MSG_MAP(COle_vbxApp)
- 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()
-
- /////////////////////////////////////////////////////////////////////////////
- // COle_vbxApp construction
-
- COle_vbxApp::COle_vbxApp()
- {
- // TODO: add construction code here,
- // Place all significant initialization in InitInstance
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // The one and only COle_vbxApp object
-
- COle_vbxApp NEAR theApp;
-
- // This identifier was generated to be statistically unique for your app.
- // You may change it if you prefer to choose a specific identifier.
- static const CLSID BASED_CODE clsid =
- { 0x76513a60, 0xa596, 0x101b, { 0x99, 0xa9, 0x0, 0x0, 0xc0, 0xb5, 0x8e, 0x81 } };
-
- /////////////////////////////////////////////////////////////////////////////
- // COle_vbxApp initialization
-
- BOOL COle_vbxApp::InitInstance()
- {
- // Initialize OLE 2.0 libraries
- if (!AfxOleInit())
- {
- AfxMessageBox(IDP_OLE_INIT_FAILED);
- 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.
-
- SetDialogBkColor(); // Set dialog background color to gray
- LoadStdProfileSettings(); // Load standard INI file options (including MRU)
- EnableVBX(); // Initialize VBX support
-
- // 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(COle_vbxDoc),
- RUNTIME_CLASS(CMainFrame), // main SDI frame window
- RUNTIME_CLASS(COle_vbxView));
- 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.
-
- // 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 2.0 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_DISPATCH_OBJECT);
- COleObjectFactory::UpdateRegistryAll();
-
- // Check to see that the VBX control is present
- if(LoadVBXFile("ABCAUTO.VBX") > HINSTANCE_ERROR)
- UnloadVBXFile("ABCAUTO.VBX");
- else
- {
- AfxMessageBox("Cannot Load ABCAUTO.VBX\nPlace the file in your \\WINDOWS\\SYSTEM directory.",
- MB_OK | MB_ICONEXCLAMATION);
- return FALSE;
- }
-
- // pull up the about box immediately
- OnAppAbout();
-
- return TRUE;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
-
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
-
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- CVBControl* m_pABCVBX;
- //}}AFX_DATA
-
- Application m_ABCApp;
-
- // Implementation
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //{{AFX_MSG(CAboutDlg)
- virtual BOOL OnInitDialog();
- afx_msg void OnShapePal();
- afx_msg void OnDoubleclicksubclassAbc1(UINT, int, CWnd*, LPVOID);
- afx_msg void OnDeletesubclassAbc1(UINT, int, CWnd*, LPVOID);
- afx_msg void OnHideShapePal();
- afx_msg void OnShowShapePal();
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
-
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- m_pABCVBX = NULL;
- //}}AFX_DATA_INIT
- }
-
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- DDX_VBControl(pDX, IDC_ABC1, m_pABCVBX);
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- ON_VBXEVENT(VBN_DOUBLECLICKSUBCLASS, IDC_ABC1, OnDoubleclicksubclassAbc1)
- ON_VBXEVENT(VBN_DELETESUBCLASS, IDC_ABC1, OnDeletesubclassAbc1)
- ON_BN_CLICKED(IDC_HIDE_SHAPE_PAL, OnHideShapePal)
- ON_BN_CLICKED(IDC_SHOW_SHAPE_PAL, OnShowShapePal)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- // App command to run the dialog
- void COle_vbxApp::OnAppAbout()
- {
- CAboutDlg aboutDlg;
-
- aboutDlg.DoModal();
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // VB-Event registration
- // (calls to AfxRegisterVBEvent will be placed here by ClassWizard)
-
- //{{AFX_VBX_REGISTER_MAP()
- UINT NEAR VBN_DOUBLECLICKSUBCLASS = AfxRegisterVBEvent("DOUBLECLICKSUBCLASS");
- UINT NEAR VBN_DELETESUBCLASS = AfxRegisterVBEvent("DELETESUBCLASS");
- //}}AFX_VBX_REGISTER_MAP
-
- /////////////////////////////////////////////////////////////////////////////
- // COle_vbxApp commands
-
- BOOL CAboutDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- m_ABCApp.CreateDispatch("ABCFlow.application");
- m_ABCApp.SetVisible(TRUE);
-
- // Register the event with ABC ProcessAnalyzer 1.1
-
- // NOTE: MFC included with Visual C++ 1.5 does not support
- // LPDISPATCH VBX properties.
- //
- // To allow the ABCFLOW.VBX to work with MFC some redundant properties
- // were added that are "Num"(long) properties.
- // YOU MUST cast them to (LPDISPATCH) before using them...
- //
- // App -> lApp
- // Chart -> lChart
- // Object -> lObject
- // FieldValue -> lFieldValue
- // Menu -> lMenu
- // MenuItem -> lMenuItem
- // VBX -> lVBX
- //
- LPDISPATCH lpVBXDisp = (LPDISPATCH)m_pABCVBX->GetNumProperty("lVBX");
- VARIANT vEmpty;
-
- VariantInit(&vEmpty);
- m_ABCApp.RegisterEvent(lpVBXDisp, "C++ Events Sample", "DoubleClickSUBCLASS", vEmpty);
- m_ABCApp.RegisterEvent(lpVBXDisp, "C++ Events Sample", "DeleteSUBCLASS", vEmpty);
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
-
- void CAboutDlg::OnDoubleclicksubclassAbc1(UINT, int, CWnd*, LPVOID)
- {
- // TODO: Add your VBX event notification handler code here
-
- // Setup the ABCObject
- Object ABCObject;
-
- // You MUST call AttachDispatch with FALSE only when
- // attaching an LPDISPATCH from the ABC VBX
- ABCObject.AttachDispatch((LPDISPATCH)m_pABCVBX->GetNumProperty("lObject"), FALSE);
-
- // Set the passed object to Green
- ABCObject.SetColor(RGB(0,0xff,0));
-
- ABCObject.SetText("C++ is easy.");
-
- m_pABCVBX->SetNumProperty("Override", TRUE);
- }
-
- void CAboutDlg::OnDeletesubclassAbc1(UINT, int, CWnd*, LPVOID)
- {
- // TODO: Add your VBX event notification handler code here
-
- // Setup the ABCChart
- Chart ABCChart;
- Objects ABCObjects;
- Object SelectedObject;
-
- // Get the Chart that the delete occured in
-
- // You MUST call AttachDispatch with FALSE only when
- // attaching an LPDISPATCH from the ABC VBX
- ABCChart.AttachDispatch((LPDISPATCH)m_pABCVBX->GetNumProperty("lChart"), FALSE);
-
- // Get the Objects Collection
- ABCObjects.AttachDispatch(ABCChart.GetObjects());
-
- do
- {
- // Get a selected object
- SelectedObject.AttachDispatch(ABCObjects.ItemFromSelection());
-
- // Set the object to Dark Gray
- SelectedObject.SetColor(m_ABCApp.GetDk_gray());
- }
- while (SelectedObject.GetValid());
-
- m_pABCVBX->SetNumProperty("Override", TRUE);
- }
-
- void CAboutDlg::OnHideShapePal()
- {
- // TODO: Add your control notification handler code here
- m_ABCApp.SetShapePaletteVisible(FALSE);
-
- BringWindowToTop();
- GotoDlgCtrl(GetDlgItem(IDC_HIDE_SHAPE_PAL));
- }
-
- void CAboutDlg::OnShowShapePal()
- {
- // TODO: Add your control notification handler code here
- m_ABCApp.SetShapePaletteVisible(TRUE);
-
- BringWindowToTop();
- GotoDlgCtrl(GetDlgItem(IDC_SHOW_SHAPE_PAL));
- }
-