www.pudn.com > ObjectInspector_demo.rar > ObjectInspectorTestDlg.cpp
// ObjectInspectorTestDlg.cpp
//
#include "stdafx.h"
#include "ObjectInspectorTest.h"
#include "ObjectInspectorTestDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CObjectInspectorTestDlg::CObjectInspectorTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CObjectInspectorTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CObjectInspectorTestDlg)
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CObjectInspectorTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CObjectInspectorTestDlg)
DDX_Control(pDX, IDC_OI, m_OI);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CObjectInspectorTestDlg, CDialog)
//{{AFX_MSG_MAP(CObjectInspectorTestDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CObjectInspectorTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
CObjectInspector::CProperty *pProp;
// Prepare stringlist
m_slBorderStyles.AddTail ("bsNone");
m_slBorderStyles.AddTail ("bsSingle");
m_slBorderStyles.AddTail ("bsLowered");
m_slBorderStyles.AddTail ("bsRaised");
// Prepare control's appearance
m_szBorderStyle = "bsLowered";
m_bHotTrack = true;
m_b3dFocus = false;
m_szValueHeader = _T("Value");
m_szPropertyHeader = _T("Property");
m_clBackColor = ::GetSysColor(COLOR_BTNFACE);
m_clVTColor = RGB(0,0,255);
m_clPTColor = (COLORREF)0;
m_clGridLineColor = RGB(80,80,80);
m_nMinPropertyColWidth = 50;
m_nMinValueColWidth = 50;
m_clFocusLineColor = RGB(100,100,255);
m_nStyle = 1;
// Add groups and properties
m_OI.AddProperty (pProp = new CObjectInspector::CProperty("Appearance"));
pProp->Expand ();
pProp->AddProperty (new CObjectInspector::CProperty("Borderstyle", &m_szBorderStyle, &m_slBorderStyles , -1, CBS_DROPDOWNLIST));
pProp->AddProperty (new CObjectInspector::CProperty("Hot-Track", &m_bHotTrack));
pProp->AddProperty (new CObjectInspector::CProperty("3D-Focus", &m_b3dFocus));
m_OI.AddProperty (pProp = new CObjectInspector::CProperty("Style"));
pProp->Expand ();
pProp->AddProperty (new CObjectInspector::CProperty("Normal", true, &m_nStyle));
pProp->AddProperty (new CObjectInspector::CProperty("W2K", true, &m_nStyle));
m_OI.AddProperty (pProp = new CObjectInspector::CProperty("Colors"));
pProp->Expand ();
pProp->AddProperty (new CObjectInspector::CProperty("Back", &m_clBackColor));
pProp->AddProperty (new CObjectInspector::CProperty("Property-Text", &m_clPTColor));
pProp->AddProperty (new CObjectInspector::CProperty("Value-Text", &m_clVTColor));
pProp->AddProperty (new CObjectInspector::CProperty("Grid-Line", &m_clGridLineColor));
pProp->AddProperty (new CObjectInspector::CProperty("Focus-Line", &m_clFocusLineColor));
m_OI.AddProperty (pProp = new CObjectInspector::CProperty("Misc."));
pProp->Expand ();
pProp->AddProperty (new CObjectInspector::CProperty("Property-Column Title", &m_szPropertyHeader));
pProp->AddProperty (new CObjectInspector::CProperty("Value-Column Title", &m_szValueHeader));
pProp->AddProperty (new CObjectInspector::CProperty("Min. property col. width", &m_nMinPropertyColWidth));
pProp->AddProperty (new CObjectInspector::CProperty("Min. value col. width", &m_nMinValueColWidth,20,100));
UpdateControl();
return TRUE;
}
void CObjectInspectorTestDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // Gerätekontext für Zeichnen
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Symbol in Client-Rechteck zentrieren
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;
// Symbol zeichnen
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
HCURSOR CObjectInspectorTestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CObjectInspectorTestDlg::UpdateControl()
{
if (m_szBorderStyle == "bsNone")
m_OI.SetBorderStyle (CObjectInspector::bsNone);
if (m_szBorderStyle == "bsSingle")
m_OI.SetBorderStyle (CObjectInspector::bsSingle);
if (m_szBorderStyle == "bsLowered")
m_OI.SetBorderStyle (CObjectInspector::bsLowered);
if (m_szBorderStyle == "bsRaised")
m_OI.SetBorderStyle (CObjectInspector::bsRaised);
m_OI.SetHotTrack (m_bHotTrack);
m_OI.SetHeaderTitles (m_szPropertyHeader, m_szValueHeader);
m_OI.SetBackColor(m_clBackColor);
m_OI.SetPropertyColTextColor (m_clPTColor);
m_OI.SetValueColTextColor (m_clVTColor);
m_OI.SetGridLineColor (m_clGridLineColor);
m_OI.SetFocusLineColor (m_clFocusLineColor);
m_OI.Set3dFocus (m_b3dFocus);
m_OI.SetMinPropertyColWidth (m_nMinPropertyColWidth);
m_OI.SetMinValueColWidth (m_nMinValueColWidth);
m_OI.SetStyle(m_nStyle == 1);
}
BOOL CObjectInspectorTestDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
if (wParam == IDC_OI)
{
CObjectInspector::NM_OIVIEW *nmHdr = (CObjectInspector::NM_OIVIEW*) lParam;
if (nmHdr->hdr.code == OIVN_ITEMCHANGED)
UpdateControl();
}
return CDialog::OnNotify(wParam, lParam, pResult);
}
void CObjectInspectorTestDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
if (::IsWindow(m_OI.m_hWnd ))
m_OI.MoveWindow (0,0, cx, cy);
}