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

📄 opcset.cpp

📁 VC++实现的预测控制
💻 CPP
📖 第 1 页 / 共 2 页
字号:
   if( SUCCEEDED(hr) )
   {
      m_itemID = pName;
      CoTaskMemFree( pName );
   
   }

   UpdateData( FALSE );
}

void COPCSet::OnSelchangedOpcTree(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	USES_CONVERSION;
   if( !browse.IsOk() )
      return;

   CWaitCursor wait;
   HTREEITEM item = m_tree.GetSelectedItem( );
   HRESULT hr = BrowseHere( item );    // move browse position here
   if( SUCCEEDED(hr) )
   {
      // get the tags
      m_tags.ResetContent();
      IEnumString* pEnumString = NULL;
      hr = browse.BrowseOPCItemIDs(OPC_LEAF,
                                   T2OLE(m_filter.GetBuffer(0)),
                                   m_vt,
                                   0,  // no filtering (or OPC_READABLE|OPC_WRITEABLE)
                                   &pEnumString);
      if( hr == S_OK )
      {
         LPWSTR pName[NEXT_COUNT];
         ULONG count = 0;
         do
         {
            hr = pEnumString->Next(NEXT_COUNT, &pName[0], &count);
            // CString does translation from UNICODE to native type
            // (depends on the way the application is built)
            for( ULONG index=0; index<count; index++ )
            {
               CString name( pName[index] );
               m_tags.AddString( name );
               CoTaskMemFree( pName[index] );
            }
         }
         while( hr == S_OK );
         pEnumString->Release();
      }
   }
   hr = S_OK;
   for( int i=0; i<10 && SUCCEEDED(hr); i++ )
      hr = browse.ChangeBrowsePosition( OPC_BROWSE_UP, empty );

   if( pResult )
	   *pResult = 0;
}

void COPCSet::OnSelchangeOpcPropertiesList() 
{
	// TODO: Add your control notification handler code here
   USES_CONVERSION;
   if( !browse.IsOk() )
      return;

   CWaitCursor wait;
   HTREEITEM item = m_tree.GetSelectedItem( );
   HRESULT hr = BrowseHere( item );    // move browse position here

   m_itemID.Empty();
   
   int nSel;
   if ((nSel = m_tags.GetCurSel()) != LB_ERR)
   {
      m_tags.GetText(nSel,m_itemID);
   }
   else
      return;

   // Ask the server for the itemID
   LPWSTR pName = NULL;
   hr = browse.GetItemID( T2OLE(m_itemID.GetBuffer(0)), &pName );
   if( SUCCEEDED(hr) )
   {
      m_itemID = pName;
      CoTaskMemFree( pName );
      //GetDlgItem(ID_OPC_ITEMPARAMETERS)->EnableWindow(TRUE);
   }

   UpdateData( FALSE );

   // return browse position to root
   hr = S_OK;
   for( int i=0; i<10 && SUCCEEDED(hr); i++ )
      hr = browse.ChangeBrowsePosition( OPC_BROWSE_UP, empty );
}

void COPCSet::OnSelchangeAolist() 
{
	// TODO: Add your control notification handler code here
	int h  = m_aolist.GetCurSel();
	if ( h != LB_ERR )
    {
      m_aolist.GetText(h,m_stringname);
    }
    else
       return;
	if(m_samename.Compare(m_stringname)==0)
		return;
	m_relist.InsertString(CountItem,m_stringname);
	CountItem++;
	m_relist.SetCurSel(CountItem);
	m_samename = m_stringname;
	m_select =1;
}

void COPCSet::OnDblclkAolist() 
{
	// TODO: Add your control notification handler code here
	
}

BOOL COPCSet::OnInitDialog() 
{
   CDialog::OnInitDialog();
   USES_CONVERSION;
   CWaitCursor wait;
  

   //这里应改进为对复合框的初始化
   //CheckRadioButton( IDC_USENATIVE, IDC_STRING, IDC_USENATIVE );
   
   // Fill the tree with the server's hierarchy
   if( !browse.IsOk() )
   {
      m_tree.ShowWindow( FALSE );
      m_tags.ShowWindow( FALSE );
      m_flat.ShowWindow( TRUE );
      m_flat.AddString( _T("Browsing not supported") );
      return TRUE;
   }

   HRESULT hr = browse.QueryOrganization(&nameSpaceType);
   if( FAILED(hr) )
   {
      browse.Detach();
      return TRUE;
   }

   if( nameSpaceType == OPC_NS_HIERARCHIAL ) // show a tree
   {
      HTREEITEM Root = m_tree.InsertItem( _T("Root") );
      m_tree.SetItemData( Root, 1 );
      IEnumString* pEnumString = NULL;
      hr = browse.BrowseOPCItemIDs(OPC_BRANCH,
                                  L"*",
                                  m_vt,
                                  0,  // no filtering (or OPC_READABLE|OPC_WRITEABLE)
                                  &pEnumString);
      if( SUCCEEDED(hr) )
      {
         LPWSTR pName[NEXT_COUNT];
         ULONG count = 0;
         do
         {
            hr = pEnumString->Next(NEXT_COUNT, &pName[0], &count);
            // CString does translation from UNICODE to native type
            // (depends on the way the application is built)
            for( ULONG index=0; index<count; index++ )
            {
                CString name( pName[index] );
                HTREEITEM item = m_tree.InsertItem( name, Root );
                m_tree.SetItemData( item, 0 );
                m_tree.InsertItem( _T("Dummy"), item );
                CoTaskMemFree( pName[index] );
            }
         }
         while( hr == S_OK );
         pEnumString->Release();
      }
      m_tree.SelectItem( Root );
      m_tree.Expand( Root, TVE_EXPAND );
   }
   else  // namespace must be flat, only display in one listbox
   {
      m_tree.ShowWindow( FALSE );
      m_tags.ShowWindow( FALSE );
      m_flat.ShowWindow( TRUE );
      UpdateFlat();
   }
	HMODULE hDll;
    typedef BOOL (*pShow)();
	hDll=::LoadLibrary(DllPathname);//加载链接库
	if(hDll==NULL){ 
		AfxMessageBox("找不到PIDDLL.dll,加载动态链接库失败"); 
		return FALSE;} 
	pShow Show=(pShow)::GetProcAddress(hDll,"OutPutFile"); 
	Show();
	if(Show==NULL)
	{
		AfxMessageBox("函数调用失败"); //调用加载动态链接库失败
		return FALSE;
	}
    IniPathName = ".\\ConfigureFile.ini";
	// TODO: Add extra initialization here
	if(IniPathName.Compare("")==0)
	 return -1;
	CString strSection       = "Section1";
	CString strSectionKey    = "FileName";
	CString strValue       = _T("");
	char inBuf[80];
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, IniPathName); 
	strValue=inBuf;
	
	if(strValue.Compare("")==0)//这里是算法名
	{
		AfxMessageBox("选择的配置文件不正确,请从新选择");
		return -1;
	}

	strSection       = "Section1";
	strSectionKey    = "explain";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, IniPathName); 
	strValue=inBuf;
	
	strSection       = "Section2";
	strSectionKey    = "Functionname";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, IniPathName); 
	strValue=inBuf;
	functionname = strValue;	
	strSection       = "Section2";
	strSectionKey    = "explain";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, IniPathName); 
	strValue=inBuf;

	strSection       = "Section3";
	strSectionKey    = "Dialogname";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, IniPathName); 
	strValue=inBuf;
	dialogname = strValue;
	strSection       = "Section3";
	strSectionKey    = "explain";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, IniPathName); 
	strValue=inBuf;

	strSection       = "Section4";
	strSectionKey    = "AI";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, IniPathName); 
	strValue=inBuf;
	
	int k =atoi(strValue);
	strSection       = "Section4";
	strSectionKey    = "explain";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, IniPathName); 
	strValue=inBuf;
	
	strSection       = "Section5";
	strSectionKey    = "AO";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, IniPathName); 
	strValue=inBuf;
	int l = atoi(strValue);   
	strSection       = "Section5";
	strSectionKey    = "explain";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, IniPathName); 
	strValue=inBuf;
    
    for(int index =0;index<k;index++)
	{
	strSection.Format("Section%d",6+index);
	strSectionKey.Format("AI%d",1+index);
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, IniPathName); 
	strValue=inBuf;
	
	strSection.Format("Section%d",6+index);
	strSectionKey    = "explain";
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, IniPathName); 
	strValue = strValue+inBuf;

	m_ailist.AddString(strValue);
    
    }
	for(index =0;index<l;index++)
	{
	strSection.Format("Section%d",6+k+index);
	strSectionKey.Format("AO%d",1+index);
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, IniPathName); 
	strValue=inBuf;
	    
	strSection.Format("Section%d",6+k+index);
	strSectionKey    = "explain";
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, IniPathName); 
	strValue+=inBuf;
	m_aolist.AddString(strValue);

    }
    m_ailist.SetCurSel(0);
	m_aolist.SetCurSel(0);
	UpdateData();
	m_relist.SetCurSel(0);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
void COPCSet::OnItemexpandingOpcTree(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
   USES_CONVERSION;
   if( !browse.IsOk() )
      return;

   CWaitCursor wait;
   NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
   HTREEITEM start = pNMTreeView->itemNew.hItem;
   DWORD expanded = m_tree.GetItemData( start );
   if( !expanded )
   {
      m_tree.SetItemData( start, 1 );  // mark this item expanded
      // remove existing children
      HTREEITEM hItem = m_tree.GetNextItem (start, TVGN_CHILD);
      while (hItem)
      {
         m_tree.DeleteItem( hItem );
         hItem = m_tree.GetNextItem(start, TVGN_CHILD);
      }
      // browse new children
      HRESULT hr = BrowseHere( start );    // move browse position here
      if( SUCCEEDED(hr) )
      {
         IEnumString* pEnumString = NULL;
         hr = browse.BrowseOPCItemIDs( OPC_BRANCH,
                                       L"*",
                                       VT_EMPTY,
                                       0,  // no filtering (or OPC_READABLE|OPC_WRITEABLE)
                                       &pEnumString);
         if( SUCCEEDED(hr) )
         {
            LPWSTR pName[NEXT_COUNT];
            ULONG count = 0;
            do
            {
               hr = pEnumString->Next(NEXT_COUNT, &pName[0], &count);
               // CString does translation from UNICODE to native type
               // (depends on the way the application is built)
               for( ULONG index=0; index<count; index++ )
               {
                   CString name( pName[index] );
                   HTREEITEM item = m_tree.InsertItem( name, start );
                   m_tree.SetItemData( item, 0 );
                   m_tree.InsertItem( _T("Dummy"), item );
                   CoTaskMemFree( pName[index] );
               }
            }
            while( hr == S_OK );
            pEnumString->Release();
         }
      }
      // return browse position to root
      hr = S_OK;
      for( int i=0; i<10 && SUCCEEDED(hr); i++ )
         hr = browse.ChangeBrowsePosition( OPC_BROWSE_UP, empty );
   }
	*pResult = 0;
}

void COPCSet::OnItemdelete() 
{
	// TODO: Add your control notification handler code here
	CString m_string;
	if(Itemedit==-1)
		return;
	CountItem = CountItem-1;
    m_relist.GetText(Itemedit,m_string);
	CString h = m_string.Right(1);
	if(h.Compare("I")==0)
		AITagList->RemoveAt(Itemedit);
	if(h.Compare("O")==0)
		AOTagList->RemoveAt(Itemedit);
	m_relist.DeleteString(Itemedit);
	int k = pDoc->items.GetCount();
	if(k==Itemedit+1)
	{
	POSITION pos = pDoc->items.GetHeadPosition();
	for(int index=0;index<Itemedit;index++)
		pDoc->items.GetNext(pos);
	pDoc->items.RemoveAt(pos);
	}
	else
		return;
	
}

void COPCSet::OnSelchangeRelist() 
{
	// TODO: Add your control notification handler code here
	Itemedit = m_relist.GetCurSel();
	if ( Itemedit != LB_ERR )
    {
      m_relist.GetText(Itemedit,m_stringname);
    }
    else
       return;
}

void COPCSet::OnItemmoveup() 
{
	// TODO: Add your control notification handler code here
	Itemedit = m_relist.GetCurSel();
	if(Itemedit-1>=0&&Itemedit !=LB_ERR)
	{
		m_relist.SetCurSel(Itemedit-1);
	}
	else
		return;
}

void COPCSet::OnItemmovedown() 
{
	// TODO: Add your control notification handler code here
	Itemedit = m_relist.GetCurSel();
	if(Itemedit+1<=m_relist.GetCount()&&Itemedit !=LB_ERR)
	{
		m_relist.SetCurSel(Itemedit+1);
	}
	else
		return;
}

⌨️ 快捷键说明

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