ATL-连接点和接口方法的使用

前言

在做COMDLL, 用MFC测试程序插入注册好的ATL控件.
测试连接点的添加, 控件方法的添加,测试程序被控件调用连接点函数, 测试程序去调用控件的接口方法.

效果图

这里写图片描述

工程下载点

srcUserLoginComControl.zip
编译环境 : vc6sp6 + win7x64 + ATL(复合控件) + MFC(测试程序)

工程预览

COMDLL

// MyLoginControl.idl : IDL source for MyLoginControl.dll
//

// This file will be processed by the MIDL tool to
// produce the type library (MyLoginControl.tlb) and marshalling code.

import "oaidl.idl";
import "ocidl.idl";
#include "olectl.h"


    [
        object,
        uuid(8FFDD35F-7B31-4823-9119-F990A31A5F79),
        dual,
        helpstring("IMyUserLogin Interface"),
        pointer_default(unique)
    ]
    interface IMyUserLogin : IDispatch
    {
        [id(1), helpstring("得到背景位图size")] HRESULT GetBgBmpRect([out]long* lWidth, [out]long* lHeight);
        [id(2), helpstring("得到用户输入的用户名")] HRESULT GetUserName([out] BSTR* pbstrName);
        [id(3), helpstring("得到用户输入的口令")] HRESULT GetUserPwd([out] BSTR* pbstrPwd);
    };

[
    uuid(F0DC71B3-B356-4373-8152-2E29460B1479),
    version(1.0),
    helpstring("MyLoginControl 1.0 Type Library")
]
library MYLOGINCONTROLLib
{
    importlib("stdole32.tlb");
    importlib("stdole2.tlb");

    [
        uuid(E9E6B623-99BE-4356-9B3D-B4C2CAF5BDB4),
        helpstring("_IMyUserLoginEvents Interface")
    ]
    dispinterface _IMyUserLoginEvents
    {
        properties:
        methods:
        [id(1), helpstring("method Event_OnChangeEdit_user_name")] HRESULT Event_OnChangeEdit_user_name(void);
        [id(2), helpstring("method Event_OnChangeEdit_pwd")] HRESULT Event_OnChangeEdit_pwd(void);
        [id(3), helpstring("method Event_OnClickedButton_login")] HRESULT Event_OnClickedButton_login(void);
    };

    [
        uuid(1A1178A1-5D7D-4138-B93E-4DFA32DF748B),
        helpstring("MyUserLogin Class")
    ]
    coclass MyUserLogin
    {
        [default] interface IMyUserLogin;
        [default, source] dispinterface _IMyUserLoginEvents;
    };
};
// MyUserLogin.cpp : Implementation of CMyUserLogin

#include "stdafx.h"
#include "MyLoginControl.h"
#include "MyUserLogin.h"

/////////////////////////////////////////////////////////////////////////////
// CMyUserLogin


STDMETHODIMP CMyUserLogin::GetBgBmpRect(long *lWidth, long *lHeight)
{
    if (NULL != lWidth) {
        *lWidth = m_BgBmp_lWidth;
    }

    if (NULL != lHeight) {
        *lHeight = m_BgBmp_lHeight;
    }

    return S_OK;
}

STDMETHODIMP CMyUserLogin::GetUserName(BSTR *pbstrName)
{
    if (NULL != pbstrName) {
        *pbstrName = m_bstrtName.copy();
    }

    return S_OK;
}

STDMETHODIMP CMyUserLogin::GetUserPwd(BSTR *pbstrPwd)
{
    if (NULL != pbstrPwd) {
        *pbstrPwd = m_bstrtPwd.copy();
    }

    return S_OK;
}
#ifndef _MYLOGINCONTROLCP_H_
#define _MYLOGINCONTROLCP_H_

template <class T>
class CProxy_IMyUserLoginEvents : public IConnectionPointImpl<T, &DIID__IMyUserLoginEvents, CComDynamicUnkArray>
{
    //Warning this class may be recreated by the wizard.
public:
    HRESULT Fire_Event_OnChangeEdit_user_name()
    {
        CComVariant varResult;
        T* pT = static_cast<T*>(this);
        int nConnectionIndex;
        int nConnections = m_vec.GetSize();

        for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
        {
            pT->Lock();
            CComPtr<IUnknown> sp = m_vec.GetAt(nConnectionIndex);
            pT->Unlock();
            IDispatch* pDispatch = reinterpret_cast<IDispatch*>(sp.p);
            if (pDispatch != NULL)
            {
                VariantClear(&varResult);
                DISPPARAMS disp = { NULL, NULL, 0, 0 };
                pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL);
            }
        }
        return varResult.scode;

    }
    HRESULT Fire_Event_OnChangeEdit_pwd()
    {
        CComVariant varResult;
        T* pT = static_cast<T*>(this);
        int nConnectionIndex;
        int nConnections = m_vec.GetSize();

        for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
        {
            pT->Lock();
            CComPtr<IUnknown> sp = m_vec.GetAt(nConnectionIndex);
            pT->Unlock();
            IDispatch* pDispatch = reinterpret_cast<IDispatch*>(sp.p);
            if (pDispatch != NULL)
            {
                VariantClear(&varResult);
                DISPPARAMS disp = { NULL, NULL, 0, 0 };
                pDispatch->Invoke(0x2, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL);
            }
        }
        return varResult.scode;

    }
    HRESULT Fire_Event_OnClickedButton_login()
    {
        CComVariant varResult;
        T* pT = static_cast<T*>(this);
        int nConnectionIndex;
        int nConnections = m_vec.GetSize();

        for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
        {
            pT->Lock();
            CComPtr<IUnknown> sp = m_vec.GetAt(nConnectionIndex);
            pT->Unlock();
            IDispatch* pDispatch = reinterpret_cast<IDispatch*>(sp.p);
            if (pDispatch != NULL)
            {
                VariantClear(&varResult);
                DISPPARAMS disp = { NULL, NULL, 0, 0 };
                pDispatch->Invoke(0x3, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL);
            }
        }
        return varResult.scode;

    }
};
#endif
// MyUserLogin.h : Declaration of the CMyUserLogin

#ifndef __MYUSERLOGIN_H_
#define __MYUSERLOGIN_H_

#define MAX_LOADSTRING 0x100

#include "resource.h"       // main symbols
#include <atlctl.h>
#include <Atlwin.h>
#include <comdef.h>
#include "MyLoginControlCP.h"

/////////////////////////////////////////////////////////////////////////////
// CMyUserLogin
class ATL_NO_VTABLE CMyUserLogin : 
public CComObjectRootEx<CComSingleThreadModel>,
public IDispatchImpl<IMyUserLogin, &IID_IMyUserLogin, &LIBID_MYLOGINCONTROLLib>,
public CComCompositeControl<CMyUserLogin>,
public IPersistStreamInitImpl<CMyUserLogin>,
public IOleControlImpl<CMyUserLogin>,
public IOleObjectImpl<CMyUserLogin>,
public IOleInPlaceActiveObjectImpl<CMyUserLogin>,
public IViewObjectExImpl<CMyUserLogin>,
public IOleInPlaceObjectWindowlessImpl<CMyUserLogin>,
public IConnectionPointContainerImpl<CMyUserLogin>,
public IPersistStorageImpl<CMyUserLogin>,
public ISpecifyPropertyPagesImpl<CMyUserLogin>,
public IQuickActivateImpl<CMyUserLogin>,
public IDataObjectImpl<CMyUserLogin>,
public IProvideClassInfo2Impl<&CLSID_MyUserLogin, &DIID__IMyUserLoginEvents, &LIBID_MYLOGINCONTROLLib>,
public IPropertyNotifySinkCP<CMyUserLogin>,
public CComCoClass<CMyUserLogin, &CLSID_MyUserLogin>,
    public CProxy_IMyUserLoginEvents< CMyUserLogin >
{
public:
    CMyUserLogin()
    {
        m_bWindowOnly = TRUE;
        CalcExtent(m_sizeExtent);

        m_BgBmp_lWidth = 435;
        m_BgBmp_lHeight = 337;

        m_bstrtName = OLESTR("");
        m_bstrtPwd = OLESTR("");
    }

    DECLARE_REGISTRY_RESOURCEID(IDR_MYUSERLOGIN)

        DECLARE_PROTECT_FINAL_CONSTRUCT()

        BEGIN_COM_MAP(CMyUserLogin)
        COM_INTERFACE_ENTRY(IMyUserLogin)
        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(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(CMyUserLogin)
        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(CMyUserLogin)
        CONNECTION_POINT_ENTRY(IID_IPropertyNotifySink)
        CONNECTION_POINT_ENTRY(DIID__IMyUserLoginEvents)
        END_CONNECTION_POINT_MAP()

        BEGIN_MSG_MAP(CMyUserLogin)
        CHAIN_MSG_MAP(CComCompositeControl<CMyUserLogin>)
        MESSAGE_HANDLER(WM_DRAWITEM, OnDrawItem)
        MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
        MESSAGE_HANDLER(WM_PAINT, OnPaint)
        MESSAGE_HANDLER(WM_SIZE, OnSize)
        COMMAND_HANDLER(IDC_BUTTON_LOGIN, BN_CLICKED, OnClickedButton_login)
        COMMAND_HANDLER(IDC_EDIT_PWD, EN_CHANGE, OnChangeEdit_pwd)
        COMMAND_HANDLER(IDC_EDIT_USER_NAME, EN_CHANGE, OnChangeEdit_user_name)
        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(CMyUserLogin)
        //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<CMyUserLogin>::OnAmbientPropertyChange(dispid);
    }



    // IViewObjectEx
    DECLARE_VIEW_STATUS(0)

        // IMyUserLogin
public:
    STDMETHOD(GetUserPwd)(/*[out]*/ BSTR* pbstrPwd);
    STDMETHOD(GetUserName)(/*[out]*/ BSTR* pbstrName);
    STDMETHOD(GetBgBmpRect)(/*[out]*/long* lWidth, /*[out]*/long* lHeight);

    enum { IDD = IDD_MYUSERLOGIN };
    LRESULT OnDrawItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
        // TODO : Add Code for message handler. Call DefWindowProc if necessary.
        return 0;
    }
    LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
        // TODO : Add Code for message handler. Call DefWindowProc if necessary.
        return 0;
    }
    LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
        // TODO : Add Code for message handler. Call DefWindowProc if necessary.
        CWindow myWindow;
        PAINTSTRUCT ps;
        HDC hDC = NULL;
        HDC hCompatibleDC = NULL;
        HBITMAP hBitmap = NULL;
        HGDIOBJ hOldGdi = NULL;
        RECT rt;

        myWindow.Attach(m_hWnd);
        hDC = myWindow.BeginPaint(&ps);
        //Use the hDC as much as you want

        hCompatibleDC = ::CreateCompatibleDC(hDC);
        hBitmap = ::LoadBitmap(_Module.m_hInst, MAKEINTRESOURCE(IDB_BITMAP_BG));
        hOldGdi = ::SelectObject(hCompatibleDC, hBitmap);

        GetClientRect(&rt);
        ::BitBlt(hDC, 0, 0, rt.right - rt.left, rt.bottom - rt.top, hCompatibleDC, 0, 0, SRCCOPY);

        ::SelectObject(hCompatibleDC, hOldGdi);
        DeleteObject(hBitmap);
        myWindow.EndPaint(&ps);

        return 0;
    }
    LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
        // TODO : Add Code for message handler. Call DefWindowProc if necessary.
        return 0;
    }

private:
    /// 背景位图size
    long m_BgBmp_lWidth;
    long m_BgBmp_lHeight;
    /// 用户输入信息
    _bstr_t m_bstrtName;
    _bstr_t m_bstrtPwd;

    LRESULT OnClickedButton_login(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
    {
        // TODO : Add Code for control notification handler.
        Fire_Event_OnClickedButton_login();
        return 0;
    }
    LRESULT OnChangeEdit_pwd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
    {
        // TODO : Add Code for control notification handler.
        CWindow win;
        BSTR bstrText = NULL;

        win.Attach(m_hWnd);

        if (win.GetDlgItemText(IDC_EDIT_PWD, bstrText)) {
            m_bstrtPwd = bstrText;
            SysFreeString(bstrText);
            bstrText = NULL;

            Fire_Event_OnChangeEdit_pwd();
        }

        return 0;
    }
    LRESULT OnChangeEdit_user_name(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
    {
        // TODO : Add Code for control notification handler.
        CWindow win;
        BSTR bstrText = NULL;

        win.Attach(m_hWnd);

        if (win.GetDlgItemText(IDC_EDIT_USER_NAME, bstrText)) {
            m_bstrtName = bstrText;
            SysFreeString(bstrText);
            bstrText = NULL;

            Fire_Event_OnChangeEdit_user_name();
        }

        return 0;
    }
};

#endif //__MYUSERLOGIN_H_

测试工程

// Machine generated IDispatch wrapper class(es) created by Microsoft Visual C++

// NOTE: Do not modify the contents of this file.  If this class is regenerated by
//  Microsoft Visual C++, your modifications will be overwritten.


#include "stdafx.h"
#include "myuserlogin.h"

/////////////////////////////////////////////////////////////////////////////
// CMyUserLogin

IMPLEMENT_DYNCREATE(CMyUserLogin, CWnd)

/////////////////////////////////////////////////////////////////////////////
// CMyUserLogin properties

/////////////////////////////////////////////////////////////////////////////
// CMyUserLogin operations

void CMyUserLogin::GetBgBmpRect(long* lWidth, long* lHeight)
{
    static BYTE parms[] =
        VTS_PI4 VTS_PI4;
    InvokeHelper(0x1, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
         lWidth, lHeight);
}

void CMyUserLogin::GetUserName_(BSTR* pbstrName)
{
    static BYTE parms[] =
        VTS_PBSTR;
    InvokeHelper(0x2, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
         pbstrName);
}

void CMyUserLogin::GetUserPwd(BSTR* pbstrPwd)
{
    static BYTE parms[] =
        VTS_PBSTR;
    InvokeHelper(0x3, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
         pbstrPwd);
}
// testcaseDlg.cpp : implementation file
//

#include "stdafx.h"
#include "testcase.h"
#include "testcaseDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class 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()

/////////////////////////////////////////////////////////////////////////////
// CTestcaseDlg dialog

CTestcaseDlg::CTestcaseDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CTestcaseDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CTestcaseDlg)
        // 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);

    m_strName = OLESTR("");
    m_strPwd = OLESTR("");
}

void CTestcaseDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CTestcaseDlg)
    DDX_Control(pDX, IDC_MYUSERLOGIN3, m_CtrlMyUserLogin);
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTestcaseDlg, CDialog)
    //{{AFX_MSG_MAP(CTestcaseDlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestcaseDlg message handlers

BOOL CTestcaseDlg::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

    /// @todo 应该从控件m_CtrlMyUserLogin方法中得到size
    this->MoveWindow(0, 0, 435 + 7 * 4, 337 + 7 * 7, TRUE);

    return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTestcaseDlg::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 CTestcaseDlg::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 CTestcaseDlg::OnQueryDragIcon()
{
    return (HCURSOR) m_hIcon;
}

BEGIN_EVENTSINK_MAP(CTestcaseDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CTestcaseDlg)
    ON_EVENT(CTestcaseDlg, IDC_MYUSERLOGIN3, 1 /* Event_OnChangeEdit_user_name */, OnOnChangeEditusernameMyuserlogin3, VTS_NONE)
    ON_EVENT(CTestcaseDlg, IDC_MYUSERLOGIN3, 2 /* Event_OnChangeEdit_pwd */, OnOnChangeEditpwdMyuserlogin3, VTS_NONE)
    ON_EVENT(CTestcaseDlg, IDC_MYUSERLOGIN3, 3 /* Event_OnClickedButton_login */, OnOnClickedButtonloginMyuserlogin3, VTS_NONE)
    //}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()


void CTestcaseDlg::OnOnChangeEditusernameMyuserlogin3() 
{
    BSTR bstrVal = NULL;

    m_CtrlMyUserLogin.GetUserName_(&bstrVal);
    if (NULL != bstrVal) {
        m_strName = (WCHAR*)bstrVal;
        SysFreeString(bstrVal);
        bstrVal = NULL;
    } else {
        m_strName = OLESTR("");
    }
}

void CTestcaseDlg::OnOnChangeEditpwdMyuserlogin3() 
{
    BSTR bstrVal = NULL;

    m_CtrlMyUserLogin.GetUserPwd(&bstrVal);
    if (NULL != bstrVal) {
        m_strPwd = (WCHAR*)bstrVal;
        SysFreeString(bstrVal);
        bstrVal = NULL;
    } else {
        m_strPwd = OLESTR("");
    }
}

void CTestcaseDlg::OnOnClickedButtonloginMyuserlogin3() 
{
    CString str;

    str.Format("name[%s], pwd[%s]", (char*)m_strName, (char*)m_strPwd);
    AfxMessageBox(str);
}
#if !defined(AFX_MYUSERLOGIN_H__4D343549_CC6C_4EB7_BE3B_AD5EE4314E9E__INCLUDED_)
#define AFX_MYUSERLOGIN_H__4D343549_CC6C_4EB7_BE3B_AD5EE4314E9E__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Machine generated IDispatch wrapper class(es) created by Microsoft Visual C++

// NOTE: Do not modify the contents of this file.  If this class is regenerated by
//  Microsoft Visual C++, your modifications will be overwritten.

/////////////////////////////////////////////////////////////////////////////
// CMyUserLogin wrapper class

class CMyUserLogin : public CWnd
{
protected:
    DECLARE_DYNCREATE(CMyUserLogin)
public:
    CLSID const& GetClsid()
    {
        static CLSID const clsid
            = { 0x1a1178a1, 0x5d7d, 0x4138, { 0xb9, 0x3e, 0x4d, 0xfa, 0x32, 0xdf, 0x74, 0x8b } };
        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); }

// Attributes
public:

// Operations
public:
    void GetBgBmpRect(long* lWidth, long* lHeight);
    void GetUserName_(BSTR* pbstrName);
    void GetUserPwd(BSTR* pbstrPwd);
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MYUSERLOGIN_H__4D343549_CC6C_4EB7_BE3B_AD5EE4314E9E__INCLUDED_)
// testcaseDlg.h : header file
//
//{{AFX_INCLUDES()
#include "myuserlogin.h"
//}}AFX_INCLUDES

#if !defined(AFX_TESTCASEDLG_H__C1C999C4_77FD_4780_9BDB_3F455A85ABCA__INCLUDED_)
#define AFX_TESTCASEDLG_H__C1C999C4_77FD_4780_9BDB_3F455A85ABCA__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <comdef.h>

/////////////////////////////////////////////////////////////////////////////
// CTestcaseDlg dialog

class CTestcaseDlg : public CDialog
{
// Construction
public:
    CTestcaseDlg(CWnd* pParent = NULL); // standard constructor

// Dialog Data
    //{{AFX_DATA(CTestcaseDlg)
    enum { IDD = IDD_TESTCASE_DIALOG };
    CMyUserLogin    m_CtrlMyUserLogin;
    //}}AFX_DATA

    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CTestcaseDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL

// Implementation
protected:
    HICON m_hIcon;

    // Generated message map functions
    //{{AFX_MSG(CTestcaseDlg)
    virtual BOOL OnInitDialog();
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    afx_msg void OnOnChangeEditusernameMyuserlogin3();
    afx_msg void OnOnChangeEditpwdMyuserlogin3();
    afx_msg void OnOnClickedButtonloginMyuserlogin3();
    DECLARE_EVENTSINK_MAP()
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()

private:
    _bstr_t m_strName;
    _bstr_t m_strPwd;
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_TESTCASEDLG_H__C1C999C4_77FD_4780_9BDB_3F455A85ABCA__INCLUDED_)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值