Figure 8

Figure 8 AvantGo Channels Information Path

Figure 8 AvantGo Channels Information Path
Figure 11 FileEditBox

  // FileEditBox.h : Declaration of the CFileEditBox

#ifndef __FILEEDITBOX_H_
#define __FILEEDITBOX_H_

#include "resource.h"            // main symbols
#include <atlctl.h>              // ATL support for ActiveX controls

#include <commdlg.h>             // Common dialogs
#pragma comment (lib, "comdlg32.lib")

/////////////////////////////////////////////////////////////////////////////
// CFileEditBox
class ATL_NO_VTABLE CFileEditBox : 
    public CComObjectRootEx<CComSingleThreadModel>,
    public IDispatchImpl<IFileEditBox, &IID_IFileEditBox,      
                         &LIBID_POCKETMSDNLib>,
    public CComCompositeControl<CFileEditBox>,
    public IPersistStreamInitImpl<CFileEditBox>,
    public IOleControlImpl<CFileEditBox>,
    public IOleObjectImpl<CFileEditBox>,
    public IOleInPlaceActiveObjectImpl<CFileEditBox>,
    public IViewObjectExImpl<CFileEditBox>,
    public IOleInPlaceObjectWindowlessImpl<CFileEditBox>,
    public IPersistStorageImpl<CFileEditBox>,
    public ISpecifyPropertyPagesImpl<CFileEditBox>,
    public IQuickActivateImpl<CFileEditBox>,
    public IDataObjectImpl<CFileEditBox>,
    public IProvideClassInfo2Impl<&CLSID_FileEditBox, NULL, 
                                  &LIBID_POCKETMSDNLib>,
    public CComCoClass<CFileEditBox, &CLSID_FileEditBox>
{
public:
    CFileEditBox()
    {
        m_bWindowOnly = TRUE;
        CalcExtent(m_sizeExtent);

        m_strPath.Append(_T("")); 
        m_strFilter.Append(_T("All Files|*.*|"));
    }

DECLARE_REGISTRY_RESOURCEID(IDR_FILEEDITBOX)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CFileEditBox)
    COM_INTERFACE_ENTRY(IFileEditBox)
    COM_INTERFACE_ENTRY(IDispatch)
    COM_INTERFACE_ENTRY(IViewObjectEx)
    COM_INTERFACE_ENTRY(IViewObject2)
    COM_INTERFACE_ENTRY(IViewObject)
    COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
    COM_INTERFACE_ENTRY(IOleInPlaceObject)
    COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
    COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
    COM_INTERFACE_ENTRY(IOleControl)
    COM_INTERFACE_ENTRY(IOleObject)
    COM_INTERFACE_ENTRY(IPersistStreamInit)
    COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
    COM_INTERFACE_ENTRY(ISpecifyPropertyPages)
    COM_INTERFACE_ENTRY(IQuickActivate)
    COM_INTERFACE_ENTRY(IPersistStorage)
    COM_INTERFACE_ENTRY(IDataObject)
    COM_INTERFACE_ENTRY(IProvideClassInfo)
    COM_INTERFACE_ENTRY(IProvideClassInfo2)
END_COM_MAP()

BEGIN_PROP_MAP(CFileEditBox)
    PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
    PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
END_PROP_MAP()

BEGIN_MSG_MAP(CFileEditBox)
    CHAIN_MSG_MAP(CComCompositeControl<CFileEditBox>)
    MESSAGE_HANDLER(WM_SIZE, OnSize)
    MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
    COMMAND_HANDLER(IDC_OPEN, BN_CLICKED, OnClickedOpen)
    COMMAND_HANDLER(IDC_FILENAME, EN_CHANGE, OnChangeFileName)
END_MSG_MAP()BEGIN_SINK_MAP(CFileEditBox)
END_SINK_MAP()

    STDMETHOD(OnAmbientPropertyChange)(DISPID dispid)
    {
      if (dispid == DISPID_AMBIENT_BACKCOLOR)
      {
          SetBackgroundColorFromAmbient();
          FireViewChange();
      }
        return IOleControlImpl<CFileEditBox>::OnAmbientPropertyChange(dispid);
    }
// IViewObjectEx
    DECLARE_VIEW_STATUS(0)

// IFileEditBox
public:

    enum { IDD = IDD_FILEEDITBOX };

    LRESULT OnClickedOpen(WORD wNotifyCode, WORD wID, HWND hWndCtl,
                          BOOL& bHandled)
    {
        USES_CONVERSION;
        OPENFILENAME ofn;        
        ZeroMemory(&ofn, sizeof(OPENFILENAME));
        ofn.lStructSize = sizeof(OPENFILENAME);

        TCHAR szFile[MAX_PATH] = {0};
        ofn.lpstrFile = szFile;
        ofn.nMaxFile = MAX_PATH;

        ofn.lpstrInitialDir = OLE2T(m_strPath);

        ofn.hwndOwner = ::GetParent(m_hwndEdit);
        
        // Sets the filter string replacing pipes with nulls
        TCHAR szFilter[MAX_PATH];
        lstrcpy(szFilter, OLE2T(m_strFilter));
        LPTSTR psz = szFilter;
        int i=0;
        while(psz[i] != 0) {
            if (psz[i]=='|')
                psz[i]=0;
            i++;
        }
        ofn.lpstrFilter = szFilter;

        if (GetOpenFileName(&ofn)) {
            m_strPath.Empty();
            m_strPath.Attach(T2OLE(ofn.lpstrFile));
            ::SetWindowText(m_hwndEdit, ofn.lpstrFile);
        }
        return 0;
    }

    LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
        int nButtonWidth = LOWORD(lParam)*15/100;

        ::MoveWindow(m_hwndEdit, 0,0, LOWORD(lParam)-nButtonWidth, 
            HIWORD(lParam), TRUE);
        ::MoveWindow(m_hwndGo, LOWORD(lParam)-nButtonWidth-1, 0, 
            nButtonWidth, HIWORD(lParam), TRUE);
        return 0;
    }

    LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, 
                         BOOL& bHandled)
    {
        USES_CONVERSION;
        m_hwndEdit = GetDlgItem(IDC_FILENAME);
        m_hwndGo = GetDlgItem(IDC_OPEN);
        ::SetWindowText(m_hwndEdit, OLE2T((BSTR)m_strPath));
        return 0;
    }
    LRESULT OnChangeFileName(WORD wNotifyCode, WORD wID, HWND hWndCtl, 
                             BOOL& bHandled)
    {
        USES_CONVERSION;
        TCHAR szDir[MAX_PATH];
        ::GetWindowText(m_hwndEdit, szDir, MAX_PATH);

        // Sets the new value
        m_strPath.Empty();
        m_strPath.Attach(T2BSTR(szDir));
        return 0;
    }

private:
    CComBSTR m_strPath, m_strFilter;
    HWND m_hwndEdit, m_hwndGo;
};

#endif //__FILEEDITBOX_H_