?? aneasyvaluectl.cpp
字號(hào):
// AnEasyValueCtl.cpp : Implementation of the CAnEasyValueCtrl ActiveX Control class.
#include "stdafx.h"
#include "AnEasyValue.h"
#include "AnEasyValueCtl.h"
#include "AnEasyValuePpg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CAnEasyValueCtrl, COleControl)
/////////////////////////////////////////////////////////////////////////////
// Message map
BEGIN_MESSAGE_MAP(CAnEasyValueCtrl, COleControl)
//{{AFX_MSG_MAP(CAnEasyValueCtrl)
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Dispatch map
BEGIN_DISPATCH_MAP(CAnEasyValueCtrl, COleControl)
//{{AFX_DISPATCH_MAP(CAnEasyValueCtrl)
DISP_PROPERTY_NOTIFY(CAnEasyValueCtrl, "TextAlign", m_textAlign, OnTextAlignChanged, VT_I4)
DISP_FUNCTION(CAnEasyValueCtrl, "ABeep", ABeep, VT_EMPTY, VTS_NONE)
DISP_STOCKFUNC_DOCLICK()
DISP_STOCKPROP_BACKCOLOR()
DISP_STOCKPROP_FORECOLOR()
//}}AFX_DISPATCH_MAP
DISP_FUNCTION_ID(CAnEasyValueCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()
/////////////////////////////////////////////////////////////////////////////
// Event map
BEGIN_EVENT_MAP(CAnEasyValueCtrl, COleControl)
//{{AFX_EVENT_MAP(CAnEasyValueCtrl)
EVENT_CUSTOM("ValueMax", FireValueMax, VTS_NONE)
EVENT_STOCK_CLICK()
//}}AFX_EVENT_MAP
END_EVENT_MAP()
/////////////////////////////////////////////////////////////////////////////
// Property pages
// TODO: Add more property pages as needed. Remember to increase the count!
BEGIN_PROPPAGEIDS(CAnEasyValueCtrl, 2)
PROPPAGEID(CAnEasyValuePropPage::guid)
PROPPAGEID(CLSID_CColorPropPage)
END_PROPPAGEIDS(CAnEasyValueCtrl)
/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid
IMPLEMENT_OLECREATE_EX(CAnEasyValueCtrl, "ANEASYVALUE.AnEasyValueCtrl.1",
0xc3ddeec, 0x18aa, 0x45be, 0x9b, 0x2d, 0xa5, 0xed, 0xfd, 0x9e, 0x88, 0x9f)
/////////////////////////////////////////////////////////////////////////////
// Type library ID and version
IMPLEMENT_OLETYPELIB(CAnEasyValueCtrl, _tlid, _wVerMajor, _wVerMinor)
/////////////////////////////////////////////////////////////////////////////
// Interface IDs
const IID BASED_CODE IID_DAnEasyValue =
{ 0xd7929955, 0xbf2a, 0x4c48, { 0x92, 0xc8, 0x42, 0xed, 0xf3, 0xe2, 0x1, 0xfa } };
const IID BASED_CODE IID_DAnEasyValueEvents =
{ 0xaca26236, 0xab86, 0x463d, { 0x9b, 0x85, 0x58, 0xe8, 0x1a, 0x8d, 0x41, 0xbb } };
/////////////////////////////////////////////////////////////////////////////
// Control type information
static const DWORD BASED_CODE _dwAnEasyValueOleMisc =
OLEMISC_ACTIVATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST |
OLEMISC_INSIDEOUT |
OLEMISC_CANTLINKINSIDE |
OLEMISC_RECOMPOSEONRESIZE;
IMPLEMENT_OLECTLTYPE(CAnEasyValueCtrl, IDS_ANEASYVALUE, _dwAnEasyValueOleMisc)
/////////////////////////////////////////////////////////////////////////////
// CAnEasyValueCtrl::CAnEasyValueCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CAnEasyValueCtrl
BOOL CAnEasyValueCtrl::CAnEasyValueCtrlFactory::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_ANEASYVALUE,
IDB_ANEASYVALUE,
afxRegApartmentThreading,
_dwAnEasyValueOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}
/////////////////////////////////////////////////////////////////////////////
// CAnEasyValueCtrl::CAnEasyValueCtrl - Constructor
CAnEasyValueCtrl::CAnEasyValueCtrl()
{
InitializeIIDs(&IID_DAnEasyValue, &IID_DAnEasyValueEvents);
// TODO: Initialize your control's instance data here.
m_MaxValue = 20000;
m_MinValue = 0;
m_CurPosition = 0;
m_CurValue = 0;
m_textAlign = 1;
}
/////////////////////////////////////////////////////////////////////////////
// CAnEasyValueCtrl::~CAnEasyValueCtrl - Destructor
CAnEasyValueCtrl::~CAnEasyValueCtrl()
{
// TODO: Cleanup your control's instance data here.
}
/////////////////////////////////////////////////////////////////////////////
// CAnEasyValueCtrl::OnDraw - Drawing function
void CAnEasyValueCtrl::OnDraw(
CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
// TODO: Replace the following code with your own drawing code.
pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
//pdc->Ellipse(rcBounds);
//設(shè)置字體顏色
pdc->SetTextColor(TranslateColor(GetForeColor()));
//設(shè)置背景顏色
pdc->SetBkMode(TRANSPARENT);
CBrush BKBrush(TranslateColor(GetBackColor()));
pdc->FillRect(rcBounds,&BKBrush);
//根據(jù)控件大小調(diào)整工具條大小
CRect rect = rcBounds;
rect.top = rcBounds.top +5;
rect.bottom = rcBounds.bottom -5;
rect.left = rcBounds.left + 5;
rect.right = rcBounds.right -5 ;
//顯示工具條
pdc->Rectangle(&rect);
//顯示數(shù)據(jù)條,顯示四個(gè)邊界
rect.top+=1;
rect.bottom -=1;
rect.left+=1;
//根據(jù)當(dāng)前水平位置設(shè)置右邊界
if (m_CurPosition>rcBounds.right-6) {
m_CurValue = m_MaxValue;
rect.right-=1;
}
else if (m_CurPosition<rcBounds.left+6) {
m_CurValue = m_MinValue;
rect.right = rect.left;
}
else
{
m_CurValue = (long)((double)(m_CurPosition-rect.left)/(rect.right-rect.left)*(m_MaxValue-m_MinValue)+m_MinValue);
rect.right = m_CurPosition;
}
//顯示數(shù)據(jù)條
pdc->FillSolidRect(rect,TranslateColor(GetForeColor()));
CString Value;
Value.Format("%d",m_CurValue);
//顯示數(shù)值
if (m_textAlign==0) {
pdc->SetTextAlign(TA_LEFT);
pdc->TextOut(rcBounds.left+5,rcBounds.top+5,Value);
}
else if (m_textAlign==1) {
pdc->SetTextAlign(TA_CENTER);
pdc->TextOut((rcBounds.left+rcBounds.right)/2,rcBounds.top+5,Value);
}
else{
pdc->SetTextAlign(TA_RIGHT);
pdc->TextOut(rcBounds.right-5,rcBounds.top+5,Value);
}
if (m_CurValue==m_MaxValue) {
FireValueMax();
DoClick();
ABeep();
}
}
/////////////////////////////////////////////////////////////////////////////
// CAnEasyValueCtrl::DoPropExchange - Persistence support
void CAnEasyValueCtrl::DoPropExchange(CPropExchange* pPX)
{
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX);
// TODO: Call PX_ functions for each persistent custom property.
}
/////////////////////////////////////////////////////////////////////////////
// CAnEasyValueCtrl::OnResetState - Reset control to default state
void CAnEasyValueCtrl::OnResetState()
{
COleControl::OnResetState(); // Resets defaults found in DoPropExchange
// TODO: Reset any other control state here.
}
/////////////////////////////////////////////////////////////////////////////
// CAnEasyValueCtrl::AboutBox - Display an "About" box to the user
void CAnEasyValueCtrl::AboutBox()
{
CDialog dlgAbout(IDD_ABOUTBOX_ANEASYVALUE);
dlgAbout.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CAnEasyValueCtrl message handlers
void CAnEasyValueCtrl::OnTextAlignChanged()
{
// TODO: Add notification handler code
InvalidateControl();
SetModifiedFlag();
}
void CAnEasyValueCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//改變當(dāng)前位置
m_CurPosition = point.x;
//重畫控件,自動(dòng)調(diào)用OnDraw()
Invalidate();
COleControl::OnMouseMove(nFlags, point);
}
void CAnEasyValueCtrl::ABeep()
{
// TODO: Add your dispatch handler code here
MessageBeep((WORD)-1);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -