outputbar.cpp
来自「此为Insight opc client InfoServerExplorer源」· C++ 代码 · 共 212 行
CPP
212 行
/////////////////////////////////////////////////////////////////////////////
//
// OPC DataAccess VC++ Client: OutputBar.cpp
// (Source File)
//
/////////////////////////////////////////////////////////////////////////////
//
// Author: Raphael Imhof
// Initial Date: 11/04/98
// $Workfile: OutputBar.cpp $
// $Revision: 1 $
// $Date: 7/27/99 5:23p $
// Target System: Microsoft Windows NT 4.0
// Environment: Visual C++ 5.0 / OPC DataAccess 1.0/2.0
// Remarks:
//
/////////////////////////////////////////////////////////////////////////////
//
// Description: implementation of the COutputBar class.
// Coolbar content (rich edit).
//
//
/////////////////////////////////////////////////////////////////////////////
//
// History of Changes (Please remove very old comments and blank lines!)
// $Log: /IDK/OPCServer/clients/VC++/InfoServerExplorer/OutputBar.cpp $
//
// 1 7/27/99 5:23p Imhof
//
// 1 7/27/99 5:19p Imhof
//
// 4 1/15/99 6:43p Imhof
// Updated legal notice.
//
// 3 11/10/98 2:20p Imhof
// Added file header's.
//
//
// $Nokeywords:$ (To avoid useless search while checking in.)
/////////////////////////////////////////////////////////////////////////////
// Copyright (C) 1998, Siemens Building Technologies, Inc. Landis Division
//
// SIEMENS BUILDING TECHNOLOGIES, INC. IS PROVIDING THE FOLLOWING
// EXAMPLES OF CODE AS SAMPLE ONLY.
//
// SIEMENS BUILDING TECHNOLOGIES, INC. MAKES NO REPRESENTATIONS
// OR WARRANTIES OF ANY KIND WITH RESPECT TO THE VALIDTY OF THE
// CODES OR DESIRED RESULTS AND DISCLAIMS ALL SUCH
// REPRESENTATIONS AND WARRANTIES, INCLUDING FOR EXAMPLE,
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE. SIEMENS BUILIDNG TECHNOLOGIES, INC. DOES NOT
// REPRESENT OR WARRANT THAT THE FOLLOWING CODE SAMPLES ARE
// ACCURATE, VALID, COMPLETE OR CURRENT.
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "InfoServerExplorer.h"
#include "OutputBar.h"
#include "InfoServerExplorerDoc.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// COutputBar dialog
COutputBar::COutputBar(CWnd* pParent /*=NULL*/)
: CDialog(COutputBar::IDD, pParent)
{
//{{AFX_DATA_INIT(COutputBar)
//}}AFX_DATA_INIT
AfxInitRichEdit();
}
void COutputBar::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(COutputBar)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(COutputBar, CDialog)
//{{AFX_MSG_MAP(COutputBar)
ON_WM_SIZE()
ON_WM_SHOWWINDOW()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COutputBar message handlers
void COutputBar::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
CRect sz;
GetClientRect(sz);
sz.DeflateRect(5,5);
CRichEditCtrl* pedRich = (CRichEditCtrl*) GetDlgItem(IDC_OUTPUTBAR_RICHEDIT);
if(pedRich != NULL)
{
if(pedRich->m_hWnd != NULL)
pedRich->MoveWindow(sz);
}
}
void COutputBar::DisplayText(CString sText)
{
try
{
CRichEditCtrl* pedRich = (CRichEditCtrl*) GetDlgItem(IDC_OUTPUTBAR_RICHEDIT);
if(NULL != pedRich)
{
sText += _T("\n"); //new line
pedRich->ReplaceSel(sText, FALSE);
}
else
{
CString sApp;
sApp.LoadString(AFX_IDS_APP_TITLE);
::MessageBox(0, sText, sApp, MB_OK | MB_ICONEXCLAMATION);
}
}
catch(...)
{
CString sApp;
sApp.LoadString(AFX_IDS_APP_TITLE);
::MessageBox(0, _T("Exception in COutputBar::DisplayText(CString sText)."), sApp, MB_OK | MB_ICONEXCLAMATION);
::MessageBox(0, sText, sApp, MB_OK | MB_ICONEXCLAMATION);
}
}
void COutputBar::DisplayText(CString sText, HRESULT hr)
{
CString sError;
if(COutputBar::GetErrorText(hr, sError))
{
sText = sText + _T(" returned: ") + sError;
DisplayText(sText);
}
}
void COutputBar::DisplayText(HRESULT hr)
{
CString sError;
if(COutputBar::GetErrorText(hr, sError))
{
DisplayText(sError);
}
}
BOOL COutputBar::GetErrorText(HRESULT hr, CString& sText)
{
/*
TCHAR* sMsg = NULL;
CString sErrorHRESULT;
if(HRESULT_FACILITY(hr) == FACILITY_WINDOWS)
hr = HRESULT_CODE(hr);
if(0 != FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
hr,
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
(LPTSTR)&sMsg, 0, NULL ))
{
sErrorHRESULT.Format(_T(" (%#x)."), hr);
sText = CString(sMsg) + sErrorHRESULT;
LocalFree(sMsg);
return TRUE;
}
return FALSE;
*/
CMainFrame* pMainFrame = (CMainFrame*) AfxGetMainWnd();
CInfoServerExplorerDoc* pDoc = (CInfoServerExplorerDoc*) pMainFrame->GetActiveDocument();
if(!pDoc->GetInfoServer()->GetErrorString(hr, sText))
{
sText = _T("Unknown error.");
}
return TRUE;
}
BOOL COutputBar::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?