// LoginActivex.h : Declaration of the CLoginActivex#ifndef __LOGINACTIVEX_H_
#define __LOGINACTIVEX_H_#include "resource.h"       // main symbols
#include <atlctl.h>
#include "LoginCP.h"
/////////////////////////////////////////////////////////////////////////////
// CLoginActivex
class ATL_NO_VTABLE CLoginActivex : 
public CComObjectRootEx<CComSingleThreadModel>,
public IDispatchImpl<ILoginActivex, &IID_ILoginActivex, &LIBID_LOGINLib>,
public CComCompositeControl<CLoginActivex>,
public IPersistStreamInitImpl<CLoginActivex>,
public IOleControlImpl<CLoginActivex>,
public IOleObjectImpl<CLoginActivex>,
public IOleInPlaceActiveObjectImpl<CLoginActivex>,
public IViewObjectExImpl<CLoginActivex>,
public IOleInPlaceObjectWindowlessImpl<CLoginActivex>,
public ISupportErrorInfo,
public IConnectionPointContainerImpl<CLoginActivex>,
public IPersistStorageImpl<CLoginActivex>,
public ISpecifyPropertyPagesImpl<CLoginActivex>,
public IQuickActivateImpl<CLoginActivex>,
public IDataObjectImpl<CLoginActivex>,
public IProvideClassInfo2Impl<&CLSID_LoginActivex, &DIID__ILoginActivexEvents, &LIBID_LOGINLib>,
public IPropertyNotifySinkCP<CLoginActivex>,
public CComCoClass<CLoginActivex, &CLSID_LoginActivex>,
public CProxy_ILoginActivexEvents< CLoginActivex >
{
public:
CLoginActivex()
{
bstrLoginName=SysAllocString(OLESTR(""));
bstrPassword=SysAllocString(OLESTR("")); m_bWindowOnly = TRUE;
CalcExtent(m_sizeExtent);
}DECLARE_REGISTRY_RESOURCEID(IDR_LOGINACTIVEX)DECLARE_PROTECT_FINAL_CONSTRUCT()BEGIN_COM_MAP(CLoginActivex)
COM_INTERFACE_ENTRY(ILoginActivex)
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(ISupportErrorInfo)
COM_INTERFACE_ENTRY(IConnectionPointContainer)
COM_INTERFACE_ENTRY(ISpecifyPropertyPages)
COM_INTERFACE_ENTRY(IQuickActivate)
COM_INTERFACE_ENTRY(IPersistStorage)
COM_INTERFACE_ENTRY(IDataObject)
COM_INTERFACE_ENTRY(IProvideClassInfo)
COM_INTERFACE_ENTRY(IProvideClassInfo2)
COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
END_COM_MAP()BEGIN_PROP_MAP(CLoginActivex)
PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
// Example entries
// PROP_ENTRY("Property Description", dispid, clsid)
// PROP_PAGE(CLSID_StockColorPage)
END_PROP_MAP()BEGIN_CONNECTION_POINT_MAP(CLoginActivex)
CONNECTION_POINT_ENTRY(IID_IPropertyNotifySink)
CONNECTION_POINT_ENTRY(DIID__ILoginActivexEvents)
END_CONNECTION_POINT_MAP()BEGIN_MSG_MAP(CLoginActivex)
CHAIN_MSG_MAP(CComCompositeControl<CLoginActivex>)
COMMAND_HANDLER(IDC_EDIT1, EN_KILLFOCUS, OnKillfocusEdit1)
COMMAND_HANDLER(IDC_EDIT2, EN_KILLFOCUS, OnKillfocusEdit2)
COMMAND_HANDLER(IDC_BUTTON1, BN_CLICKED, OnClickedButton1)
COMMAND_HANDLER(IDC_BUTTON2, BN_CLICKED, OnClickedButton2)
COMMAND_HANDLER(IDC_EDIT1, EN_CHANGE, OnChangeEdit1)
COMMAND_HANDLER(IDC_EDIT2, EN_CHANGE, OnChangeEdit2)
END_MSG_MAP()
// Handler prototypes:
//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
//  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
//  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);BEGIN_SINK_MAP(CLoginActivex)
//Make sure the Event Handlers have __stdcall calling convention
END_SINK_MAP() STDMETHOD(OnAmbientPropertyChange)(DISPID dispid)
{
if (dispid == DISPID_AMBIENT_BACKCOLOR)
{
SetBackgroundColorFromAmbient();
FireViewChange();
}
return IOleControlImpl<CLoginActivex>::OnAmbientPropertyChange(dispid);
}// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid)
{
static const IID* arr[] = 
{
&IID_ILoginActivex,
};
for (int i=0; i<sizeof(arr)/sizeof(arr[0]); i++)
{
if (InlineIsEqualGUID(*arr[i], riid))
return S_OK;
}
return S_FALSE;
}// IViewObjectEx
DECLARE_VIEW_STATUS(0)// ILoginActivex
public:
STDMETHOD(get_Password)(/*[out, retval]*/ BSTR *pVal);
STDMETHOD(put_Password)(/*[in]*/ BSTR newVal);
STDMETHOD(get_LoginName)(/*[out, retval]*/ BSTR *pVal);
STDMETHOD(put_LoginName)(/*[in]*/ BSTR newVal); enum { IDD = IDD_LOGINACTIVEX };
BSTR bstrLoginName,bstrPassword;
LRESULT OnKillfocusEdit1(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
// TODO : Add Code for control notification handler.


return 0;
}
LRESULT OnKillfocusEdit2(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
// TODO : Add Code for control notification handler.


return 0;
}
LRESULT OnClickedButton1(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
// TODO : Add Code for control notification handler.
Fire_Login();
//SetDlgItemText(IDC_EDIT1,"");
//SetDlgItemText(IDC_EDIT2,"");
return 0;
}
LRESULT OnClickedButton2(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
// TODO : Add Code for control notification handler.
Fire_Cancel();
return 0;
}
LRESULT OnChangeEdit1(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
// TODO : Add Code for control notification handler.
GetDlgItemText(IDC_EDIT1,bstrLoginName);
return 0;
}
LRESULT OnChangeEdit2(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
// TODO : Add Code for control notification handler.
GetDlgItemText(IDC_EDIT2,bstrPassword);
return 0;
}
};#endif //__LOGINACTIVEX_H_

解决方案 »

  1.   

    这是测试端// testDlg.cpp : implementation file
    //#include "stdafx.h"
    #include "test.h"
    #include "testDlg.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog
    {
    public:
    CAboutDlg();// Dialog Data
    //{{AFX_DATA(CAboutDlg)
    enum { IDD = IDD_ABOUTBOX };
    //}}AFX_DATA // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CAboutDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    //{{AFX_MSG(CAboutDlg)
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
    {
    //{{AFX_DATA_INIT(CAboutDlg)
    //}}AFX_DATA_INIT
    }void CAboutDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CAboutDlg)
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
    // No message handlers
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CTestDlg dialogCTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CTestDlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CTestDlg)
    // 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);
    }void CTestDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CTestDlg)
    DDX_Control(pDX, IDC_LOGINACTIVEX1, m_login);
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
    //{{AFX_MSG_MAP(CTestDlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CTestDlg message handlersBOOL CTestDlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    } // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon

    // TODO: Add extra initialization here

    return TRUE;  // return TRUE  unless you set the focus to a control
    }void CTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
    {
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
    CAboutDlg dlgAbout;
    dlgAbout.DoModal();
    }
    else
    {
    CDialog::OnSysCommand(nID, lParam);
    }
    }// If you add a minimize button to your dialog, you will need the code below
    //  to draw the icon.  For MFC applications using the document/view model,
    //  this is automatically done for you by the framework.void CTestDlg::OnPaint() 
    {
    if (IsIconic())
    {
    CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
    CDialog::OnPaint();
    }
    }// The system calls this to obtain the cursor to display while the user drags
    //  the minimized window.
    HCURSOR CTestDlg::OnQueryDragIcon()
    {
    return (HCURSOR) m_hIcon;
    }BEGIN_EVENTSINK_MAP(CTestDlg, CDialog)
        //{{AFX_EVENTSINK_MAP(CTestDlg)
    ON_EVENT(CTestDlg, IDC_LOGINACTIVEX1, 1 /* Login */, OnLoginLoginactivex1, VTS_NONE)
    ON_EVENT(CTestDlg, IDC_LOGINACTIVEX1, 2 /* Cancel */, OnCancelLoginactivex1, VTS_NONE)
    //}}AFX_EVENTSINK_MAP
    END_EVENTSINK_MAP()void CTestDlg::OnLoginLoginactivex1() 
    {
    // TODO: Add your control notification handler code here
    CString strPassword;
    CString strUsername;
    strUsername = m_login.GetLoginName();
    strPassword = m_login.GetPassword();
    MessageBox("Login Result: Username = " + strUsername + ",Password = " + strPassword);

    }void CTestDlg::OnCancelLoginactivex1() 
    {
    // TODO: Add your control notification handler code here

    }
      

  2.   

    m_login为控件变量,用class wizard添加的
      

  3.   

    另外在VB下测试也是一样的症状,第一次能取得正确的属性,可是连续点击登陆按钮时连续取时,从第二次开始,取得的结果全变成了第一个属性的值,怪事,帮忙呀,CSDN的各位兄弟姐妹
      

  4.   

    看不出来,给你个例子m_ServerPort为我定义的变量.
    void CWebOfficeCtrl::DoPropExchange(CPropExchange* pPX)
    {
    ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
    COleControl::DoPropExchange(pPX); // TODO: Call PX_ functions for each persistent custom property.
    PX_String(pPX,"ServerPort",m_ServerPort,"ServerPort");
    }
    BSTR CWebOfficeCtrl::GetServerPort(void)
    {
    AFX_MANAGE_STATE(AfxGetStaticModuleState()); // TODO: 在此添加调度处理程序代码
    return m_ServerPort.AllocSysString();
    }void CWebOfficeCtrl::SetServerPort(LPCTSTR newVal)
    {
    AFX_MANAGE_STATE(AfxGetStaticModuleState()); // TODO: 在此添加属性处理程序代码
    if(m_ServerPort.Compare(newVal)!=0)
    {
    m_ServerPort=newVal;
    }
    SetModifiedFlag();
    }
    应该没有问题了.
      

  5.   

    BEGIN_PROP_MAP(CLoginActivex)
    PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
    PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
    // Example entries
    // PROP_ENTRY("Property Description", dispid, clsid)
    // PROP_PAGE(CLSID_StockColorPage)
    END_PROP_MAP()里面没有加入对属性的映射!!
      

  6.   

    CString strPassword;
    CString strUsername;
    strUsername = m_login.GetLoginName();
    strPassword = m_login.GetPassword();
    MessageBox("Login Result: Username = " + strUsername + ",Password = " + strPassword);