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

📄 buttonctl.cpp

📁 INTERNET网络高级编程的包括邮件加密、MAPI、ISAPI、ACTIVEX、FTP等等。
💻 CPP
字号:
// ButtonCtl.cpp : Implementation of the CButtonCtrl ActiveX Control class.

#include "stdafx.h"
#include "Button.h"
#include "ButtonCtl.h"
#include "ButtonPpg.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


IMPLEMENT_DYNCREATE(CButtonCtrl, COleControl)


/////////////////////////////////////////////////////////////////////////////
// Message map

BEGIN_MESSAGE_MAP(CButtonCtrl, COleControl)
	//{{AFX_MSG_MAP(CButtonCtrl)
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONDOWN()
	//}}AFX_MSG_MAP
	ON_MESSAGE(OCM_COMMAND, OnOcmCommand)
	ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// Dispatch map

BEGIN_DISPATCH_MAP(CButtonCtrl, COleControl)
	//{{AFX_DISPATCH_MAP(CButtonCtrl)
	// NOTE - ClassWizard will add and remove dispatch map entries
	//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_DISPATCH_MAP
	DISP_FUNCTION_ID(CButtonCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()


/////////////////////////////////////////////////////////////////////////////
// Event map

BEGIN_EVENT_MAP(CButtonCtrl, COleControl)
	//{{AFX_EVENT_MAP(CButtonCtrl)
	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(CButtonCtrl, 1)
	PROPPAGEID(CButtonPropPage::guid)
END_PROPPAGEIDS(CButtonCtrl)


/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid

IMPLEMENT_OLECREATE_EX(CButtonCtrl, "BUTTON.ButtonCtrl.1",
	0xbc9c5a86, 0xc896, 0x11d4, 0xaf, 0x14, 0, 0xe0, 0x4c, 0xdd, 0x45, 0x65)


/////////////////////////////////////////////////////////////////////////////
// Type library ID and version

IMPLEMENT_OLETYPELIB(CButtonCtrl, _tlid, _wVerMajor, _wVerMinor)


/////////////////////////////////////////////////////////////////////////////
// Interface IDs

const IID BASED_CODE IID_DButton =
		{ 0xbc9c5a84, 0xc896, 0x11d4, { 0xaf, 0x14, 0, 0xe0, 0x4c, 0xdd, 0x45, 0x65 } };
const IID BASED_CODE IID_DButtonEvents =
		{ 0xbc9c5a85, 0xc896, 0x11d4, { 0xaf, 0x14, 0, 0xe0, 0x4c, 0xdd, 0x45, 0x65 } };


/////////////////////////////////////////////////////////////////////////////
// Control type information

static const DWORD BASED_CODE _dwButtonOleMisc =
	OLEMISC_ACTIVATEWHENVISIBLE |
	OLEMISC_SETCLIENTSITEFIRST |
	OLEMISC_INSIDEOUT |
	OLEMISC_CANTLINKINSIDE |
	OLEMISC_RECOMPOSEONRESIZE;

IMPLEMENT_OLECTLTYPE(CButtonCtrl, IDS_BUTTON, _dwButtonOleMisc)


/////////////////////////////////////////////////////////////////////////////
// CButtonCtrl::CButtonCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CButtonCtrl

BOOL CButtonCtrl::CButtonCtrlFactory::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_BUTTON,
			IDB_BUTTON,
			afxRegApartmentThreading,
			_dwButtonOleMisc,
			_tlid,
			_wVerMajor,
			_wVerMinor);
	else
		return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}


/////////////////////////////////////////////////////////////////////////////
// CButtonCtrl::CButtonCtrl - Constructor

CButtonCtrl::CButtonCtrl()
{
	InitializeIIDs(&IID_DButton, &IID_DButtonEvents);

	// TODO: Initialize your control's instance data here.

	//设置Button的文本
	SetText("这是闪耀的Button");

	//初始化时为没有进行闪耀
	bDraw=FALSE;

	//产生随机种子
	srand((unsigned int)time(NULL));

	m_bMouseCaptured=FALSE;
	
}


/////////////////////////////////////////////////////////////////////////////
// CButtonCtrl::~CButtonCtrl - Destructor

CButtonCtrl::~CButtonCtrl()
{
	// TODO: Cleanup your control's instance data here.
	bDraw=FALSE;
}


/////////////////////////////////////////////////////////////////////////////
// CButtonCtrl::OnDraw - Drawing function

void CButtonCtrl::OnDraw(
			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	DoSuperclassPaint(pdc, rcBounds);

	//自己加入的代码
	//CRect rc;		
	//GetClientRect(&rc);//首先得到Button的区域
    //int Width=rc.Width();//和高度及宽度
	//int Height=rc.Height();
	int Width=rcBounds.Width();//和高度及宽度
	int Height=rcBounds.Height();

   while(bDraw)
	{
		
		for(long count=5000;count>0;count--)
		{
							
			int cx=MapRand(Width);
			int cy=MapRand(Height);//找到MyButton
								   //内区域的随机的一点
            
			BYTE nRed=MapRand(255);
			BYTE nGreen=MapRand(255);
			BYTE nBlue=MapRand(255);//产生随机的一个颜色
			
			pdc->SetPixel(cx,cy,RGB(nRed,nGreen,nBlue));

		}

		SendMessage(WM_MOUSEMOVE,NULL,::GetMessagePos());
	
	}
	
}


/////////////////////////////////////////////////////////////////////////////
// CButtonCtrl::DoPropExchange - Persistence support

void CButtonCtrl::DoPropExchange(CPropExchange* pPX)
{
	ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
	COleControl::DoPropExchange(pPX);

	// TODO: Call PX_ functions for each persistent custom property.

}


/////////////////////////////////////////////////////////////////////////////
// CButtonCtrl::OnResetState - Reset control to default state

void CButtonCtrl::OnResetState()
{
	COleControl::OnResetState();  // Resets defaults found in DoPropExchange

	// TODO: Reset any other control state here.
}


/////////////////////////////////////////////////////////////////////////////
// CButtonCtrl::AboutBox - Display an "About" box to the user

void CButtonCtrl::AboutBox()
{
	CDialog dlgAbout(IDD_ABOUTBOX_BUTTON);
	dlgAbout.DoModal();
}


/////////////////////////////////////////////////////////////////////////////
// CButtonCtrl::PreCreateWindow - Modify parameters for CreateWindowEx

BOOL CButtonCtrl::PreCreateWindow(CREATESTRUCT& cs)
{
	cs.lpszClass = _T("BUTTON");
	return COleControl::PreCreateWindow(cs);
}


/////////////////////////////////////////////////////////////////////////////
// CButtonCtrl::IsSubclassedControl - This is a subclassed control

BOOL CButtonCtrl::IsSubclassedControl()
{
	return TRUE;
}


/////////////////////////////////////////////////////////////////////////////
// CButtonCtrl::OnOcmCommand - Handle command messages

LRESULT CButtonCtrl::OnOcmCommand(WPARAM wParam, LPARAM lParam)
{
#ifdef _WIN32
	WORD wNotifyCode = HIWORD(wParam);
#else
	WORD wNotifyCode = HIWORD(lParam);
#endif

	// TODO: Switch on wNotifyCode here.

	return 0;
}


/////////////////////////////////////////////////////////////////////////////
// CButtonCtrl message handlers

void CButtonCtrl::OnMouseMove(UINT nFlags, CPoint point) 
{
	COleControl::OnMouseMove(nFlags, point);
	// TODO: Add your message handler code here and/or call default

	CRect rc;
	this->GetClientRect(&rc); 

	if (!m_bMouseCaptured || GetCapture()!=this)
	{
		SetCapture();                             //问题2:关边界什么事情????
		m_bMouseCaptured=TRUE;	
	}

	if(rc.PtInRect(point))
	{
		bDraw=TRUE;
		InvalidateControl();
		UpdateWindow();
	}		
	else
	{
		bDraw=FALSE;
		ReleaseCapture();     
		m_bMouseCaptured=FALSE;
		InvalidateControl();
		UpdateWindow();
	}
		
   }
	
//自己编写的随机数生成函数
BYTE CButtonCtrl::MapRand(UINT nMax)
{
	
	int nRand=rand();

	float fMap=(float) nMax/RAND_MAX;
	float fRetVal=(float) nRand*fMap + 0.5F;

	return (UINT)fRetVal;
	
}

void CButtonCtrl::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	COleControl::OnLButtonDown(nFlags, point);
}

⌨️ 快捷键说明

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