📄 bitbutton.cpp
字号:
// BitButton.cpp : implementation file
//
#include "stdafx.h"
#include "iic.h"
#include "BitButton.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBitButton
CBitButton::CBitButton()
{
m_bit = 0;
m_checked = 0;
}
CBitButton::~CBitButton()
{
}
BEGIN_MESSAGE_MAP(CBitButton, CButton)
//{{AFX_MSG_MAP(CBitButton)
ON_WM_RBUTTONDOWN()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONDBLCLK()
ON_WM_LBUTTONUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBitButton message handlers
void CBitButton::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CButton::OnLButtonDown(nFlags, point);
if(GetCheck()==0)
SetCheck(1);
else
SetCheck(0);
m_checked = GetCheck();
}
bool CBitButton::GetBit(BYTE &val, int nbits)
{
BYTE i = 1<<nbits;
if(m_bit)
val = val|i;
else
val = val&(~i);
return m_bit;
}
bool CBitButton::GetBit()
{
return m_bit;
}
//DEL void CBitButton::OnMButtonDown(UINT nFlags, CPoint point)
//DEL {
//DEL // TODO: Add your message handler code here and/or call default
//DEL CButton::OnLButtonDown(nFlags, point);
//DEL }
void CBitButton::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CString str;
this->GetWindowText(str);
char c = str.GetAt(str.GetLength()-1);
if(c == '0'){
c = '1';
m_bit = 1;
}
else{
c = '0';
m_bit = 0;
}
str.SetAt((str.GetLength()-1),c);
this->SetWindowText(str);
CWnd::OnLButtonDown(nFlags, point);
}
void CBitButton::SetBit(bool b)
{
CString str;
this->GetWindowText(str);
char c;
if(b){
c = '1';
m_bit = 1;
}
else{
c = '0';
m_bit = 0;
}
str.SetAt((str.GetLength()-1),c);
this->SetWindowText(str);
}
void CBitButton::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
return;
CButton::OnLButtonDblClk(nFlags, point);
}
void CBitButton::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CWnd::OnLButtonUp(nFlags, point);
SetCheck(m_checked);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -