⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usemultdlg.cpp

📁 Thinkinc++English 电子书籍,英文版
💻 CPP
字号:
// UseMultDlg.cpp : implementation file
//

#include "stdafx.h"
#include "UseMult.h"
#include "UseMultDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CUseMultDlg dialog

CUseMultDlg::CUseMultDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CUseMultDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CUseMultDlg)
	m_n1 = 0;
	m_n2 = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CUseMultDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUseMultDlg)
	DDX_Control(pDX, IDC_EDIT4, m_time);
	DDX_Control(pDX, IDC_EDIT3, m_edit);
	DDX_Text(pDX, IDC_EDIT1, m_n1);
	DDX_Text(pDX, IDC_EDIT2, m_n2);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CUseMultDlg, CDialog)
	//{{AFX_MSG_MAP(CUseMultDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_ADVISE, OnAdvise)
	ON_BN_CLICKED(IDC_UNADVISE, OnUnadvise)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUseMultDlg message handlers

BOOL CUseMultDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 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
	m_dwCookie = 0;
	m_dwCookieTime = 0;
	HRESULT hr = m_spObj.CreateInstance( _T("MultConnect.DispConnect.1") );
	if( FAILED( hr ) )
	{
		AfxMessageBox( _T("没有注册还是没有初始化?") );
		CDialog::OnCancel();
	}

	GetDlgItem( IDC_UNADVISE )->EnableWindow( FALSE );
	GetDlgItem( IDC_ADVISE )->EnableWindow( TRUE );

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

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

void CUseMultDlg::OnAdvise() 
{
	HRESULT hr;
	CComQIPtr<IConnectionPointContainer> spContainer( m_spObj );
	ASSERT( spContainer );		// 组件没有提供连接点功能

	spContainer->FindConnectionPoint(
		__uuidof(_IDispConnectEvents), &m_spCP );
	ASSERT( m_spCP );			// 没有找到连接点接口

	hr = m_spCP->Advise( &m_sink, &m_dwCookie );
	ASSERT( SUCCEEDED( hr ) );	// 连接失败
	
	spContainer->FindConnectionPoint(
		__uuidof(_IDispConnectEvents2), &m_spCPTime );
	ASSERT( m_spCPTime );		// 没有找到连接点接口

	hr = m_spCPTime->Advise( &m_sinkTime, &m_dwCookieTime );
	ASSERT( SUCCEEDED( hr ) );	// 连接失败

	m_sink.SetResultWnd( &m_edit );
	m_sinkTime.SetResultWnd( &m_time );

	m_spObj->SetTimer( 1000 );

	GetDlgItem( IDC_UNADVISE )->EnableWindow( TRUE );
	GetDlgItem( IDC_ADVISE )->EnableWindow( FALSE );
}

void CUseMultDlg::OnUnadvise() 
{
	if( m_spCP )
	{
		m_spCP->Unadvise( m_dwCookie );
		m_spCP.Release();
	}
	if( m_spCPTime )
	{
		m_spObj->KillTimer();
		m_spCPTime->Unadvise( m_dwCookieTime );
		m_spCPTime.Release();
	}

	GetDlgItem( IDC_UNADVISE )->EnableWindow( FALSE );
	GetDlgItem( IDC_ADVISE )->EnableWindow( TRUE );
}

void CUseMultDlg::OnOK() 
{
	UpdateData();
	m_spObj->Add( m_n1, m_n2 );
}

void CUseMultDlg::OnCancel() 
{
	if( m_spCP )
		m_spCP->Unadvise( m_dwCookie );
	if( m_spCPTime )
	{
		m_spObj->KillTimer();
		m_spCPTime->Unadvise( m_dwCookieTime );
	}

	CDialog::OnCancel();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -