📄 camerabutton.cpp
字号:
// CameraButton.cpp : implementation file
//
#include "stdafx.h"
#include "../resource.h"
#include "CameraButton.h"
#include "click_btn.h"
#include "cisbitmap.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCameraButton
CCameraButton::CCameraButton()
{
nCurBitmap = 0 ;
nXpos = 75 ;
nYpos = 75 ;
nLen = 75 ;
pParentWnd = NULL ;
}
CCameraButton::~CCameraButton()
{
;
}
BEGIN_MESSAGE_MAP(CCameraButton, CButton)
//{{AFX_MSG_MAP(CCameraButton)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCameraButton message handlers
void CCameraButton::Init(CWnd *pParent)
{
pParentWnd = pParent ;
}
void CCameraButton::push_btn(UINT idb, BOOL down)
{
GetParent()->PostMessage(WM_CAMERA_BUTTON, idb, down);
}
void CCameraButton::OnLButtonUp(UINT nFlags, CPoint point)
{
switch( nCurBitmap )
{
case CAMERA_NORMAL_BUTTON:
return;
case CAMERA_AUTO_BUTTON:
push_btn(CAMERA_AUTO_BUTTON, UP);
break;
case CAMERA_LEFT_BUTTON:
push_btn(CAMERA_LEFT_BUTTON, UP);
break;
case CAMERA_RIGHT_BUTTON:
push_btn(CAMERA_RIGHT_BUTTON, UP);
break;
case CAMERA_UP_BUTTON:
push_btn(CAMERA_UP_BUTTON, UP);
break;
case CAMERA_DOWN_BUTTON:
push_btn(CAMERA_DOWN_BUTTON, UP);
break;
}
nCurBitmap = CAMERA_NORMAL_BUTTON ;
RedrawWindow() ;
CButton::OnLButtonUp(nFlags, point) ;
}
void CCameraButton::OnLButtonDown(UINT nFlags, CPoint point)
{
int dx, dy, dis ;
dx = point.x - nXpos ;
dy = nYpos - point.y ;
dis = dx*dx + dy*dy ;
if (dis < 625/*25*25*/) {
nCurBitmap = CAMERA_AUTO_BUTTON ;
push_btn(CAMERA_AUTO_BUTTON);
}
else if (dis > 1024/*32*32*/ && dis < 3600/*60*60*/) {
if (dx > 0) {
if (dy > 0) {
if (dx > dy) {
nCurBitmap = CAMERA_RIGHT_BUTTON ;
push_btn(CAMERA_RIGHT_BUTTON);
}
else {
nCurBitmap = CAMERA_UP_BUTTON ;
push_btn(CAMERA_UP_BUTTON);
}
}
else {
if (dx > -dy) {
nCurBitmap = CAMERA_RIGHT_BUTTON ;
push_btn(CAMERA_RIGHT_BUTTON);
}
else {
nCurBitmap = CAMERA_DOWN_BUTTON ;
push_btn(CAMERA_DOWN_BUTTON);
}
}
}
else {
if (dy > 0) {
if (-dx > dy) {
nCurBitmap = CAMERA_LEFT_BUTTON ;
push_btn(CAMERA_LEFT_BUTTON);
}
else {
nCurBitmap = CAMERA_UP_BUTTON ;
push_btn(CAMERA_UP_BUTTON);
}
}
else {
if (-dx > -dy) {
nCurBitmap = CAMERA_LEFT_BUTTON ;
push_btn(CAMERA_LEFT_BUTTON);
}
else {
nCurBitmap = CAMERA_DOWN_BUTTON ;
push_btn(CAMERA_DOWN_BUTTON);
}
}
}
}
RedrawWindow() ;
// SetCapture();
CButton::OnLButtonDown(nFlags, point);
}
#include "memdc.h"
void CCameraButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CCISBitmap cis;
switch (nCurBitmap) {
case CAMERA_NORMAL_BUTTON :
cis.LoadBitmap(IDB_CAMERA_NORMAL) ;
break ;
case CAMERA_LEFT_BUTTON :
cis.LoadBitmap(IDB_CAMERA_LEFT) ;
break ;
case CAMERA_RIGHT_BUTTON :
cis.LoadBitmap(IDB_CAMERA_RIGHT) ;
break ;
case CAMERA_UP_BUTTON :
cis.LoadBitmap(IDB_CAMERA_UP) ;
break ;
case CAMERA_DOWN_BUTTON :
cis.LoadBitmap(IDB_CAMERA_DOWN) ;
break ;
case CAMERA_AUTO_BUTTON :
cis.LoadBitmap(IDB_CAMERA_AUTO) ;
break ;
default :
cis.LoadBitmap(IDB_CAMERA_NORMAL) ;
break ;
}
CClientDC cdc(this);
CRect rc;
GetClientRect(rc);
CMemDC mdc(&cdc, rc);
GetWindowRect(rc);
GetParent()->ScreenToClient(rc);
CDC* dc = GetParent()->GetDC();
mdc.BitBlt(0, 0, rc.Width(), rc.Height(), dc, rc.left, rc.top, SRCCOPY);
GetParent()->ReleaseDC(dc);
cis.DrawTransparent(&mdc, 0, 0, RGB(0,0,0));
}
BOOL CCameraButton::OnEraseBkgnd(CDC* pdc)
{
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -