ImageGear Professional for Windows ActiveX
Adding the Code
  1. As described above, we have found that the wizard-generated wrapper classes are not the best way to use ActiveX controls in an MFC application. However, because the wizard forces you to generate at least 5 such wrapper classes, you'll first need to remove those files from your project. If you select "File View" mode in Visual Studio, you'll see the various files created by the wizards. Remove the following files from the project:
    • igcorectl.cpp
    • igcorectl.h
    • igdisplayctl.cpp
    • igdisplayctl.h
    • igdlgsctl.cpp
    • igdlgsctl.h
    • igformatsctl.cpp
    • igformatsctl.h
    • igpageviewctl.cpp
    • igpageviewctl.h

    Then open the header file created for your application's dialog (if you named your project IG_MFC, then the dialog header file will be IG_MFCDlg.h), and add five import statements near the top, as follows:

     
    Copy Code
    #if _MSC_VER > 1000 
    #pragma once 
    #endif // _MSC_VER > 1000 
    #import "C:\Program Files\Accusoft\ImageGear
    v18\...\Shared\Bin\igcore18a.ocx" 
    #import "C:\Program Files\Accusoft\ImageGear
    18\...\Shared\Bin\igformats18a.ocx" 
    #import "C:\Program Files\Accusoft\ImageGear
    v18\...\Shared\Bin\igdisplay18a.ocx" 
    #import "C:\Program Files\Accusoft\ImageGear
    v18\...\Shared\Bin\igdlgs18a.ocx" 
    #import "C:\Program Files\Accusoft\ImageGear
    v18\...\Shared\Bin\igview18a.ocx"
    

    This will cause .tlh and .thi files to be generated when your application is compiled. We have found that the wrapper classes defined in .tlh files are easier to use.

  2. Add private member variables for the various ImageGear ActiveX controls and COM objects to your dialog header file:
     
    Copy Code
    protected: 
            HICON m_hIcon; 
            GearCORELib::IIGPagePtr m_pPage; 
            GearDISPLAYLib::IIGPageDisplayPtr m_pPageDisplay; 
            GearDISPLAYLib::IIGDisplayCtlPtr m_pDisplayCtl; 
            GearVIEWLib::IIGPageViewCtlPtr m_pPageViewCtl; 
            GearFORMATSLib::IIGFormatsCtlPtr m_pFormatsCtl; 
            GearCORELib::IIGCoreCtlPtr m_pCoreCtl; 
            GearDIALOGSLib::IIGDlgsCtlPtr m_pDlgsCtl; 
            GearDIALOGSLib::IIGFileDlgPtr m_pFileDialog; 
            // Generated message map functions
            virtual BOOL OnInitDialog();
            afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
            afx_msg void OnPaint();
            afx_msg HCURSOR OnQueryDragIcon();
         DECLARE_MESSAGE_MAP() 
    
  3. Add initializers for these member variables to the constructor for your Dialog class:
     
    Copy Code
    CIG_MFCDlg::CIG_MFCDlg(CWnd* pParent /*=NULL*/) 
            : CDialog(CIG_MFCDlg::IDD, pParent) 
            , m_pPage(NULL) 
            , m_pPageDisplay(NULL) 
            , m_pDisplayCtl(NULL) 
            , m_pPageViewCtl(NULL) 
            , m_pFormatsCtl(NULL) 
            , m_pCoreCtl(NULL) 
            , m_pDlgsCtl(NULL) 
            , m_pFileDialog(NULL) 
    { 
            //{{AFX_DATA_INIT(CIG_MFCDlg) 
                    // NOTE: the ClassWizard will add member
    initialization 
    here 
            //}}AFX_DATA_INIT 
            // Note that LoadIcon does not require a subsequent 
    DestroyIcon in Win32 
            m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
    } 
    
  4. Add the following code to the Init_Dialog() method for your Dialog class:
    Example Title
    Copy Code
    BOOL CIG_MFCDlg::OnInitDialog() 
    { 
            CDialog::OnInitDialog();
            // Set the icon for this dialog.  The framework does this 
            //  when the application's main window is not a dialog 
            SetIcon(m_hIcon, True); // Set big icon 
            SetIcon(m_hIcon, False); // Set small icon 
            CWnd *coreWnd, *formatsWnd, *displayWnd, *pageviewWnd, 
    *dlgsWnd; 
            coreWnd = GetDlgItem(IDC_IGCORECTL1); 
            formatsWnd = GetDlgItem(IDC_IGFORMATSCTL1); 
            dlgsWnd = GetDlgItem(IDC_IGDLGSCTL1); 
            displayWnd = GetDlgItem(IDC_IGDISPLAYCTL1); 
            pageviewWnd = GetDlgItem(IDC_IGPAGEVIEWCTL1); 
            //Create the different controls 
            m_pCoreCtl = (GearCORELib::IIGCoreCtlPtr)  
                                    coreWnd->GetControlUnknown(); 
            m_pFormatsCtl = (GearFORMATSLib::IIGFormatsCtlPtr)  
                                    formatsWnd->GetControlUnknown(); 
            m_pDlgsCtl = (GearDIALOGSLib::IIGDlgsCtlPtr)  
                                    dlgsWnd->GetControlUnknown(); 
            m_pDisplayCtl = (GearDISPLAYLib::IIGDisplayCtlPtr)  
                                    displayWnd->GetControlUnknown(); 
            m_pPageViewCtl = (GearVIEWLib::IIGPageViewCtlPtr)  
                                    pageviewWnd->GetControlUnknown(); 
            m_pCoreCtl->GetLicense()->SetSolutionName("Accusoft"); 
            m_pCoreCtl->GetResult()->NotificationFlags = 
                                     GearCORELib::IG_ERR_OLE_ERROR; 
            try 
            { 
                    m_pCoreCtl->AssociateComponent(  
                                    m_pFormatsCtl->ComponentInterface ); 
                    m_pCoreCtl->AssociateComponent(  
                                    m_pDisplayCtl->ComponentInterface ); 
                    m_pDlgsCtl->GearFormats = m_pFormatsCtl-
    >ComponentInterface; 
                    m_pDlgsCtl->GearCore = m_pCoreCtl-
    >ComponentInterface; 
                    m_pDlgsCtl->GearDisplay = m_pDisplayCtl-
    >ComponentInterface; 
                    m_pFileDialog = m_pDlgsCtl->CreateFileDlg(); 
                    m_pPage = m_pCoreCtl->CreatePage(); 
                    m_pPageDisplay = m_pDisplayCtl-
    >CreatePageDisplay(m_pPage); 
                    m_pPageViewCtl->PageDisplay = m_pPageDisplay; 
            } 
            catch( _com_error err ) 
            { 
                    AfxMessageBox(err.Description()); 
            } 
            return True;  // return True  unless you set the focus to
    a 
    control 
    }
    

    The code above includes:

    IGCoreCtl Control License.SetSolutionName This method of the IGLicense Object sets the solution name for the ImageGear license.
      Result.NotificationFlag This method of the IGResult Object tells ImageGear to report errors using the VB On Error mechanism.
      AssociateComponent This method associates ImageGear components with the Core control.
      CreatePage This method creates and returns a new IGPage Object.
      Result.isOk This property of the IGResult Object tells if there are any errors on the error stack.
    IGDlgsCtl Control GearFormats This property sets the current Formats control used by the Dialog control.
      GearCore This property sets the current Core control used by the Dialog control.
    IGDisplayCtl Control CreatePageDisplay This method creates a new IGPageDisplay Object for the specified IGPage Object.
    IGPageViewCtl Control PageDisplay This property sets the current Page Display object displayed by the Page View control.
      UpdateView This method causes the Page View control to redraw itself.
  5. In the Class View window, click to select the CIG_MFC node. Right click to display Properties dialog box, click the Messages icon button to show the Windows messages that this class can handle.

    In the Properties dialog box, click to select the WM_SIZE message, click the drop-down arrow, and then click the <ADD> OnSize option to create the WM_SIZE message handler method.

     
    Copy Code
    void CIG_MFCDlg::OnSize(UINT nType, int cx, int cy)
    {
            CDialog::OnSize(nType, cx, cy);
            // TODO: Add your message handler code here
            if (m_pPageViewCtl != NULL) 
            { 
                    HWND hWnd = (HWND) m_pPageViewCtl->hWnd; 
                    ::SetWindowPos(hWnd, HWND_TOP, 0, 20,  
                            cx, cy-20, SWP_NOZORDER | SWP_NOACTIVATE); 
            } 
    }
    
  6. Next, create a click procedure for the Open button by double-clicking it in the Dialog Editor. Then copy the following code into the OnBnClickedOpen() method:
    Example Title
    Copy Code
    void CIG_MFCDlg::OnBnClickedOpen() 
    {
            try
            {
                    GearDIALOGSLib::IIGFileDlgPageLoadOptionsPtr
    dlgLoadOptions;
                    dlgLoadOptions =
    (GearDIALOGSLib::IIGFileDlgPageLoadOptionsPtr)
                             m_pDlgsCtl->CreateFileDlgOptions(
                                    GearDIALOGSLib::IG_FILEDLGOPTIONS_PAGELOADOBJ
    );
                    if(m_pFileDialog->Show(
                            (GearDIALOGSLib::IIGFileDlgOptionsPtr)
    dlgLoadOptions) )
                    {
                            m_pFormatsCtl->LoadPageFromFile( 
                                    m_pPage, 
                                    dlgLoadOptions->FileName, 
                                    dlgLoadOptions->PageNum);
                    }
                    m_pPageViewCtl->UpdateView();
            }
            catch( _com_error err )
            {
                    AfxMessageBox(err.Description());
            }
    }
    

    The code above includes:

    IGDlgsCtl Control CreateFileDlgOptions This method creates a file dialog options object that will contain for example the filename and page number
    IGFileDlg Object Show This method shows the file dialog and returns True if the user clicked OK.
    IGFormatsCtl Control LoadPageFromFile This method loads an image into the specified IGPage Object from the specified filename.
  7. Finally, create click procedures for the Zoom In and Zoom Out buttons by double-clicking each of them in the Dialog Editor. Then copy the following code into the OnBnClickedZoomin() and OnBnClickedZoomout() methods:
     
    Copy Code
    void CIG_MFCDlg::OnBnClickedZoomin() 
    {
            try
            {
                    GearDISPLAYLib::IIGDisplayZoomInfoPtr zoominfo;
                    zoominfo = (GearDISPLAYLib::IIGDisplayZoomInfoPtr)
                            m_pPageDisplay->GetZoomInfo( m_pPageViewCtl->hWnd
    );
                    zoominfo->HZoom = zoominfo->HZoom * 1.25;
                    zoominfo->VZoom = zoominfo->VZoom * 1.25;
                    zoominfo->Mode =
    (GearDISPLAYLib::enumIGDsplZoomModes)
                            (GearDISPLAYLib::IG_DSPL_ZOOM_H_FIXED |
                             GearDISPLAYLib::IG_DSPL_ZOOM_V_FIXED);
                    m_pPageDisplay->UpdateZoomFrom(zoominfo);
                    m_pPageViewCtl->UpdateView();
            }
            catch( _com_error err )
            {
                    AfxMessageBox(err.Description());
            }
    }
    

    The above code zooms the image to 125 percent, or 5/4ths, of its size (zoom in by 25 percent).

     
    Copy Code
    void CIG_MFCDlg::OnBnClickedZoomout() 
    {
            try
            {
                    GearDISPLAYLib::IIGDisplayZoomInfoPtr zoominfo;
                    zoominfo = (GearDISPLAYLib::IIGDisplayZoomInfoPtr)
                            m_pPageDisplay->GetZoomInfo( m_pPageViewCtl->hWnd
    );
                    zoominfo->HZoom = zoominfo->HZoom * 0.80;
                    zoominfo->VZoom = zoominfo->VZoom * 0.80;
                    zoominfo->Mode =
    (GearDISPLAYLib::enumIGDsplZoomModes)
                            (GearDISPLAYLib::IG_DSPL_ZOOM_H_FIXED |
                             GearDISPLAYLib::IG_DSPL_ZOOM_V_FIXED);
                    m_pPageDisplay->UpdateZoomFrom(zoominfo);
                    m_pPageViewCtl->UpdateView();
            }
            catch( _com_error err )
            {
                    AfxMessageBox(err.Description());
            }
    }
    

    The above code zooms "out", decreasing the image to 4/5ths of its size, thereby canceling the effect of the zoom in above.

    The code above includes:

    IGPageDisplay Object GetZoomInfo This method creates and returns a new IGDisplayZoomInfo Object that contains zoom mode and values.
      UpdateZoomFrom This method sets zoom mode and values from the specified IGDisplayZoomInfo Object.

 

 


©2016. Accusoft Corporation. All Rights Reserved.

Send Feedback