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

📄 initdlg.cpp

📁 VC++串口通信设。本书详细说明讲解了在VC++环境下编写串口通信得过程。值得一看
💻 CPP
字号:
// Get needed include files
#include "InitDlg.h"
#include "Resource.h"
#include "Utility.h"


// Constructor
CInitialDialog::CInitialDialog(CSharedData&         NewSharedData,
                               CComponentAssocList& NewAssocList)
     : CPropertyPage(IDD_INITIAL),
       m_pSharedData(&NewSharedData),
       m_pAssociationList(&NewAssocList)
{ }


void CInitialDialog::DoDataExchange(CDataExchange* pDX)
{
   CPropertyPage::DoDataExchange(pDX);
   DDX_Control(pDX, IDS_TITLE,       m_Title);
   DDX_Control(pDX, IDC_SERVER_LIST, m_ComponentList);
}


BOOL CInitialDialog::OnInitDialog()
{
   CPropertyPage::OnInitDialog();

   // Set the font
   if (m_LargeArialFont.CreatePointFont(100, "Arial Bold"))
      m_Title.SetFont(&m_LargeArialFont);

   // Add the known components to the component selection listbox
   POSITION posCurrent = m_pAssociationList->GetHeadPosition();
   CStringToCLSIDAssoc* pAssociation = NULL;
   while (posCurrent) {
      pAssociation = m_pAssociationList->GetNext(posCurrent);
      m_ComponentList.AddString(pAssociation->m_strComponentDesc);
   }

   // Select the first component in the list
   m_ComponentList.SetCurSel(0);

   return TRUE;
}


BOOL CInitialDialog::OnSetActive()
{
   CPropertyPage::OnSetActive();

   CPropertySheet* pSheet = DYNAMIC_DOWNCAST(CPropertySheet, GetParent());
   if (pSheet != NULL)
      pSheet->SetWizardButtons(PSWIZB_NEXT);

   return TRUE;
}


BOOL CInitialDialog::OnKillActive()
{
   HRESULT hResult;
   ASSERT(m_pSharedData);

   CPropertyPage::OnKillActive();

   // Retrieve the component requested
   CString strSelComponentDesc;
   INT     iCurrSelection = m_ComponentList.GetCurSel();
   m_ComponentList.GetText(iCurrSelection, strSelComponentDesc);

   // Find the component entry
   POSITION posCurrent = m_pAssociationList->GetHeadPosition();
   CStringToCLSIDAssoc* pAssociation = NULL;
   while (posCurrent) {
      pAssociation = m_pAssociationList->GetNext(posCurrent);
      if (pAssociation->m_strComponentDesc == strSelComponentDesc)
         break;
   }

   // Now create the appropriate server object
   IPizzaOrderTaker* pInterface = NULL;
   hResult = CoCreateInstance(pAssociation->m_ComponentCLSID,
                              NULL, CLSCTX_SERVER,
                              IID_IPizzaOrderTaker,
                              (PPVOID) &pInterface);
   if (FAILED(hResult)) {
      ReportError("Could not create a new COM PizzaOrderTaker object.", hResult);
      return FALSE;
   }

   // Place the interface pointer into the shared data object
   m_pSharedData->SetPizzaOrderTaker(pInterface);

   // We're done with this interface pointer
   pInterface->Release();

   return TRUE;
}

⌨️ 快捷键说明

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