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;