📄 batteryctl.cpp
字号:
// BatteryCtl.cpp : Implementation of the CBatteryCtrl ActiveX Control class.
#include "stdafx.h"
#include "Battery.h"
#include "BatteryCtl.h"
#include "BatteryPpg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CBatteryCtrl, COleControl)
/////////////////////////////////////////////////////////////////////////////
// Message map
BEGIN_MESSAGE_MAP(CBatteryCtrl, COleControl)
//{{AFX_MSG_MAP(CBatteryCtrl)
// NOTE - ClassWizard will add and remove message map entries
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG_MAP
ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Dispatch map
BEGIN_DISPATCH_MAP(CBatteryCtrl, COleControl)
//{{AFX_DISPATCH_MAP(CBatteryCtrl)
DISP_PROPERTY_NOTIFY(CBatteryCtrl, "BackPicture", m_strBackPicture, OnBackPictureChanged, VT_BSTR)
DISP_PROPERTY_NOTIFY(CBatteryCtrl, "Rows", m_nRows, OnRowsChanged, VT_I2)
DISP_PROPERTY_NOTIFY(CBatteryCtrl, "Cols", m_nCols, OnColsChanged, VT_I2)
DISP_PROPERTY_NOTIFY(CBatteryCtrl, "RowAscending", m_bRowAscending, OnRowAscendingChanged, VT_BOOL)
DISP_PROPERTY_NOTIFY(CBatteryCtrl, "ColAscending", m_bColAscending, OnColAscendingChanged, VT_BOOL)
DISP_PROPERTY_NOTIFY(CBatteryCtrl, "ShowCoordinate", m_bShowCoordinate, OnShowCoordinateChanged, VT_BOOL)
DISP_PROPERTY_NOTIFY(CBatteryCtrl, "CoordinateStyle", m_nCoordinateStyle, OnCoordinateStyleChanged, VT_I2)
DISP_PROPERTY_NOTIFY(CBatteryCtrl, "SpacePercent", m_nSpacePercent, OnSpacePercentChanged, VT_I2)
DISP_STOCKFUNC_REFRESH()
//}}AFX_DISPATCH_MAP
DISP_FUNCTION_ID(CBatteryCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()
/////////////////////////////////////////////////////////////////////////////
// Event map
BEGIN_EVENT_MAP(CBatteryCtrl, COleControl)
//{{AFX_EVENT_MAP(CBatteryCtrl)
// NOTE - ClassWizard will add and remove event map entries
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_EVENT_MAP
END_EVENT_MAP()
/////////////////////////////////////////////////////////////////////////////
// Property pages
// TODO: Add more property pages as needed. Remember to increase the count!
BEGIN_PROPPAGEIDS(CBatteryCtrl, 1)
PROPPAGEID(CBatteryPropPage::guid)
END_PROPPAGEIDS(CBatteryCtrl)
/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid
IMPLEMENT_OLECREATE_EX(CBatteryCtrl, "BATTERY.BatteryCtrl.1",
0x11726fbd, 0xa85a, 0x4703, 0x97, 0x1f, 0xca, 0xd6, 0x5d, 0xfc, 0x95, 0x61)
/////////////////////////////////////////////////////////////////////////////
// Type library ID and version
IMPLEMENT_OLETYPELIB(CBatteryCtrl, _tlid, _wVerMajor, _wVerMinor)
/////////////////////////////////////////////////////////////////////////////
// Interface IDs
const IID BASED_CODE IID_DBattery =
{ 0x15f77938, 0x1e61, 0x4419, { 0xbc, 0x8, 0x6d, 0x1c, 0xf8, 0x5b, 0x21, 0x54 } };
const IID BASED_CODE IID_DBatteryEvents =
{ 0xd373074b, 0x8678, 0x4af0, { 0xb0, 0x3d, 0xe3, 0x3f, 0x61, 0x21, 0xfa, 0x76 } };
/////////////////////////////////////////////////////////////////////////////
// Control type information
static const DWORD BASED_CODE _dwBatteryOleMisc =
OLEMISC_ACTIVATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST |
OLEMISC_INSIDEOUT |
OLEMISC_CANTLINKINSIDE |
OLEMISC_RECOMPOSEONRESIZE;
IMPLEMENT_OLECTLTYPE(CBatteryCtrl, IDS_BATTERY, _dwBatteryOleMisc)
/////////////////////////////////////////////////////////////////////////////
// CBatteryCtrl::CBatteryCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CBatteryCtrl
BOOL CBatteryCtrl::CBatteryCtrlFactory::UpdateRegistry(BOOL bRegister)
{
// TODO: Verify that your control follows apartment-model threading rules.
// Refer to MFC TechNote 64 for more information.
// If your control does not conform to the apartment-model rules, then
// you must modify the code below, changing the 6th parameter from
// afxRegApartmentThreading to 0.
if (bRegister)
return AfxOleRegisterControlClass(
AfxGetInstanceHandle(),
m_clsid,
m_lpszProgID,
IDS_BATTERY,
IDB_BATTERY,
afxRegApartmentThreading,
_dwBatteryOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}
/////////////////////////////////////////////////////////////////////////////
// CBatteryCtrl::CBatteryCtrl - Constructor
const int MAX_ROW_COUNT=3;
const int MAX_COL_COUNT=4;
const int MAX_COORDINATE_STYLE=4;
const int MAX_SPACE_PERCENT=50;
CBatteryCtrl::CBatteryCtrl()
:m_nRows(MAX_ROW_COUNT),m_nCols(MAX_COL_COUNT),m_bRowAscending(TRUE),
m_bColAscending(FALSE),m_bShowCoordinate(TRUE),
m_nCoordinateStyle(MAX_COORDINATE_STYLE),m_nSpacePercent(MAX_SPACE_PERCENT),
m_strBackPicture("")
{
InitializeIIDs(&IID_DBattery, &IID_DBatteryEvents);
LoadPicture();
}
/////////////////////////////////////////////////////////////////////////////
// CBatteryCtrl::~CBatteryCtrl - Destructor
CBatteryCtrl::~CBatteryCtrl()
{
// TODO: Cleanup your control's instance data here.
}
/////////////////////////////////////////////////////////////////////////////
// CBatteryCtrl::OnDraw - Drawing function
void CBatteryCtrl::OnDraw(
CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
CBrush bkBrush(TranslateColor(GetBackColor()));
pdc->FillRect(rcBounds,&bkBrush);
if(m_pict)
{
CRect rcImage(CPoint(0,0),m_pict.GetImageSize());
CRect rc;
rc.IntersectRect(&rcImage,&rcBounds);
m_pict.Render(pdc, rc);
}
CRect rc;
GetBatteryZone(rcBounds,rc);
}
/////////////////////////////////////////////////////////////////////////////
// CBatteryCtrl::DoPropExchange - Persistence support
void CBatteryCtrl::DoPropExchange(CPropExchange* pPX)
{
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX);
// TODO: Call PX_ functions for each persistent custom property.
}
/////////////////////////////////////////////////////////////////////////////
// CBatteryCtrl::OnResetState - Reset control to default state
void CBatteryCtrl::OnResetState()
{
COleControl::OnResetState(); // Resets defaults found in DoPropExchange
}
/////////////////////////////////////////////////////////////////////////////
// CBatteryCtrl::AboutBox - Display an "About" box to the user
void CBatteryCtrl::AboutBox()
{
CDialog dlgAbout(IDD_ABOUTBOX_BATTERY);
dlgAbout.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CBatteryCtrl message handlers
void CBatteryCtrl::OnBackPictureChanged()
{
LoadPicture();
SetModifiedFlag();
}
void CBatteryCtrl::LoadPicture()
{
m_pict.Free();
if(IDR_BACKPICTURE>0 && !m_pict.Load(m_strBackPicture))
{
m_pict.Load(IDR_BACKPICTURE);
}
}
void CBatteryCtrl::OnRowsChanged()
{
if(m_nRows<=0 || m_nRows>MAX_ROW_COUNT)
{
m_nRows=MAX_ROW_COUNT;
}
SetModifiedFlag();
}
void CBatteryCtrl::OnColsChanged()
{
if(m_nCols<=0 || m_nCols>MAX_COL_COUNT)
{
m_nCols=MAX_COL_COUNT;
}
SetModifiedFlag();
}
void CBatteryCtrl::OnRowAscendingChanged()
{
SetModifiedFlag();
}
void CBatteryCtrl::OnColAscendingChanged()
{
SetModifiedFlag();
}
void CBatteryCtrl::OnShowCoordinateChanged()
{
SetModifiedFlag();
}
void CBatteryCtrl::OnCoordinateStyleChanged()
{
if(m_nCoordinateStyle<=0 || m_nCoordinateStyle>MAX_COORDINATE_STYLE)
{
m_nCoordinateStyle=MAX_COORDINATE_STYLE;
}
SetModifiedFlag();
}
void CBatteryCtrl::OnSpacePercentChanged()
{
if(m_nSpacePercent<=0 || m_nSpacePercent>MAX_SPACE_PERCENT)
{
m_nSpacePercent=MAX_SPACE_PERCENT;
}
SetModifiedFlag();
}
CSize CBatteryCtrl::GetRowCol(USHORT nBarreryNo)
{
CSize sz(0,0);
if(nBarreryNo>m_nRows*m_nCols||nBarreryNo==0) return sz;
int nRowIndex=(nBarreryNo-1)/m_nCols;
int nColIndex=nBarreryNo-nRowIndex*m_nCols-1;
if(!m_bColAscending)
{
nRowIndex=m_nRows-1-nRowIndex;
}
if(!m_bRowAscending)
{
nColIndex=m_nCols-1-nColIndex;
}
sz.cx=nColIndex;
sz.cy=nRowIndex;
return sz;
}
void CBatteryCtrl::GetBatteryZone(const CRect& rcBounds,CRect& rcBattery)
{
CSize sz((rcBounds.Width()/(m_nCols+1)),rcBounds.Height()/(m_nRows+1));
rcBattery.left=rcBounds.left
+((m_nCoordinateStyle==1||m_nCoordinateStyle==4)?sz.cx:0);
rcBattery.top=rcBounds.top
+((m_nCoordinateStyle==1||m_nCoordinateStyle==2)?sz.cy:0);
rcBattery.right=rcBattery.left+rcBounds.Width()-sz.cx;
rcBattery.bottom=rcBattery.top+rcBounds.Height()-sz.cy;
}
/*
CRect CBatteryCtrl::GetBarreryPeriphery(const CRect& rcBounds,USHORT nBarreryNo)
{
CRect rc(0,0,0,0);
if(nBarreryNo>m_nRows*m_nCols||nBarreryNo==0) return rc;
}
CRect CBatteryCtrl::GetBarreryInlier(const CRect& rcPeriphery,USHORT nBarreryNo)
{
CRect rc(0,0,0,0);
return rc;
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -