MFC push Button control button press and Bounce Event implementation example

Source: Internet
Author: User
Tags microsoft c

The MFC button control buttons themselves have a click, double-click, and other message response events, but individual "press" and "bounce" require our customization, and the following is an example of a button custom event.

1-Right-click Add Class in the project directory;



2-Add C + + Class;



3-Add a class based on the CButton, named Cptzbutton, the name according to their own needs to take whatever is good;



4-Add the following code in PTZButton.h:

#if!defined (ptz_button_control_h_)//Prevent duplicate inclusion
#define PTZ_BUTTON_CONTROL_H_ 

#if _msc_ver > 1000// Microsoft C Compiler version control is greater than 1000, for example vc6.0
#pragma once
#endif//_msc_ver >

cptzbutton:public cbutton< c5/>{
//Constructor public
:
	Cptzbutton ();
	Virtual ~cptzbutton ();
Protected:
	afx_msg void OnLButtonDown (UINT nflags, CPoint point);//press and bounce events
	afx_msg void OnLButtonUp (UINT nflags, CPoint point);
	Declare_message_map ()
};

#endif
5-Add the following code in PTZButton.cpp:

#include "stdafx.h"
#include "PTZButton.h"//Add the necessary header file to the third-party plug-in header file

#ifdef _DEBUG
#define NEW Debug_new
# undef this_file
static char this_file[] = __file__;
#endif

Cptzbutton::cptzbutton ()
{

}

Cptzbutton::~cptzbutton ()
{

}

begin_message _map (Cptzbutton, CButton)
	
	On_wm_lbuttondown () on_wm_lbuttonup () End_message_map ()/********
function Name:    	onlbuttondown
function Description:	left mouse button press the response function
input parameters:   
output parameter:   			
return value:		
*************************************************/
void Cptzbutton::o Nlbuttondown (UINT nflags, CPoint point) 
{
	//Add your code
	
	cbutton::onlbuttondown (nflags, point);
}

/*************************************************
function Name:    	onlbuttonup
function Description:	left mouse button bounce response function
Input parameter:   
output parameter:   			
return value:		
*************************************************/
void Cptzbutton::o Nlbuttonup (UINT nflags, CPoint point) 
{
        //Add your code 
	cbutton::onlbuttonup (nflags, point);
}
6-Associate the added button below;

In the dialog box, add the button control, right-click on the control to add a variable, and in the dialog header file, press

The change of the button variable definition CButton to cptzbutton-> completion;

Cptzbutton m_ptzupmc;//Add variable to CButton M_PTZUPMC, modify to Cptzbutton M_PTZUPMC
7-Other buttons that need to be added to press the Bounce event repeat the 6th step by adding each;


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.