-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCommandButton.cpp
More file actions
121 lines (107 loc) · 2.5 KB
/
CommandButton.cpp
File metadata and controls
121 lines (107 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "stdafx.h"
#include "Axis3.h"
#include "Axis3Dlg.h"
#include "CommandButton.h"
IMPLEMENT_DYNAMIC(CComButton, CButton)
CComButton::CComButton()
{
m_pOldDragCapture = NULL;
m_bDragging = false;
}
CComButton::~CComButton()
{
}
BEGIN_MESSAGE_MAP(CComButton, CButton)
ON_CONTROL_REFLECT(BN_CLICKED, &CComButton::OnBnClicked)
ON_WM_LBUTTONUP()
ON_WM_RBUTTONDOWN()
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()
void CComButton::OnBnClicked()
{
SendToUO(csCommand);
}
void CComButton::OnRButtonDown(UINT /*nFlags*/, CPoint point)
{
ClientToScreen(&point);
HMENU hMenu = ::CreatePopupMenu();
if (NULL != hMenu)
{
::AppendMenu(hMenu, MF_STRING, 2, CMsg(_T("Edit Button")));
::AppendMenu(hMenu, MF_STRING, 1, CMsg(_T("Remove Button")));
int sel = ::TrackPopupMenuEx(hMenu,
TPM_CENTERALIGN | TPM_RETURNCMD,
point.x,
point.y,
m_hWnd,
NULL);
switch (sel)
{
case 1:
{
CCommandPage * pComPage = (CCommandPage *)GetParent();
pComPage->RemoveButton(GetDlgCtrlID());
break;
}
case 2:
{
CCommandPage * pComPage = (CCommandPage *)GetParent();
pComPage->EditButton(GetDlgCtrlID());
break;
}
}
::DestroyMenu(hMenu);
}
}
void CComButton::OnMouseMove(UINT nFlags, CPoint point)
{
if(nFlags & MK_LBUTTON)
{
if(m_pOldDragCapture == NULL)
{
m_pOldDragCapture = SetCapture();
GetCursorPos(&m_ptStartDrag);
CRect rect;
GetWindowRect(&rect);
m_ptStartPos = rect.TopLeft();
}
m_bDragging = true;
CRect rect;
::GetWindowRect(m_hWnd,&rect);
CPoint ptMouse;
GetCursorPos(&ptMouse);
CSize sizeDiff = ptMouse - m_ptStartDrag;
CSize sizeMove = m_ptStartPos-rect.TopLeft();
rect.OffsetRect(sizeMove);
rect.OffsetRect(sizeDiff.cx, sizeDiff.cy);
GetParent()->ScreenToClient(&rect);
MoveWindow(rect);
}
CButton::OnMouseMove(nFlags, point);
}
void CComButton::OnLButtonUp(UINT nFlags, CPoint point)
{
if(m_pOldDragCapture != NULL)
{
ReleaseCapture();
m_pOldDragCapture = NULL;
}
if(m_bDragging)
{
m_bDragging = false;
GetParent()->Invalidate();
CRect rect;
GetWindowRect(&rect);
CPoint m_ptEndPos = rect.TopLeft();
INT_PTR iNewX, iNewY;
iNewX = (m_ptEndPos.x - m_ptStartPos.x);
(iNewX >= 0) ? (iNewX+=41) : (iNewX-=41);
iNewX = (iNewX/81)*5;
iNewY = (m_ptEndPos.y - m_ptStartPos.y);
(iNewY >= 0) ? (iNewY+=14) : (iNewY-=14);
iNewY = iNewY/28;
CCommandPage * pComPage = (CCommandPage *)GetParent();
pComPage->Reposition(GetDlgCtrlID(),iNewX+iNewY);
}
CButton::OnLButtonUp(nFlags, point);
}