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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
//CMainFrame.h增加下面3行
CDlgRightToolBar* m_pRightToolDlg;// 增加的浮动工具栏
void MoveRightToolDlgMin(); // 设置缩进工具栏
void MoveRightToolDlgMax(); // 最大化显示工具栏
// int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)中增加下面3行
m_pRightToolDlg = new CDlgRightToolBar;
m_pRightToolDlg->Create(IDD_DLG_RIGHTTOOLBAR, this);
m_pRightToolDlg->ShowWindow(SW_HIDE);

//
void CMainFrame::MoveRightToolDlgMin()
{

// 设置右侧工具栏最小化
const int nBorderSize = 0;
CRect mainRc;
GetClientRect(mainRc);
CRect rc;
m_wndMenuBar.GetWindowRect(rc);
int nMenuHeight = rc.bottom - rc.top;
CPoint pos;
pos.x = mainRc.right - CDlgRightToolBar::emRCTDlgWidthMin/*最小宽度*/;
pos.y = nBorderSize + nMenuHeight;
int cy = mainRc.bottom-mainRc.top-nMenuHeight;
ClientToScreen(&pos);
m_pRightToolDlg->SetWindowPos(this, pos.x, pos.y,
CDlgRightToolBar::emRCTDlgWidthMin, cy - 2 * nBorderSize-nMenuHeight,
SWP_NOACTIVATE | SWP_NOZORDER);
}
void CMainFrame::MoveRightToolDlgMax()
{

// 设置右侧工具栏最大化
const int nBorderSize = 0;
CRect mainRc;
GetClientRect(mainRc);
CRect rc;
m_wndMenuBar.GetWindowRect(rc);
int nMenuHeight = rc.bottom - rc.top;
CPoint pos;
pos.x = mainRc.right - CDlgRightToolBar::emRCTDlgWidthMax/*最大宽度*/;
pos.y = nBorderSize + nMenuHeight;
int cy = mainRc.bottom-mainRc.top-nMenuHeight;
ClientToScreen(&pos);
m_pRightToolDlg->SetWindowPos(this, pos.x, pos.y,
CDlgRightToolBar::emRCTDlgWidthMax, cy - 2 * nBorderSize-nMenuHeight,
SWP_NOACTIVATE | SWP_NOZORDER);
}
#pragma once
#include "afxcmn.h"


// CDlgRightToolBar 对话框

class CDlgRightToolBar : public CDialogEx
{
DECLARE_DYNAMIC(CDlgRightToolBar)

public:
CDlgRightToolBar(CWnd* pParent = NULL); // 标准构造函数
virtual ~CDlgRightToolBar();

// 对话框数据
enum { IDD = IDD_DLG_RIGHTTOOLBAR };

protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
CBrush m_bgBrush;
bool m_show;
bool m_bMouseTracking;
COLORREF m_transparentColor;
void InitChannelList();
void RefreshChannelList();
enum EumChannelList{emChannelSelect, emChannelName, emChannelNumber, emChannelMax};

DECLARE_MESSAGE_MAP()
public:
enum {emRCTDlgWidthMax = 240, emRCTDlgWidthMin = 20};
void TransparentWindowsDefault();
void TransparentWindows();
void ShowMinimize();
void ShowMaximize();
public:
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnCaptureChanged(CWnd *pWnd);
afx_msg LRESULT OnNcHitTest(CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
CListCtrl m_ctrlListChannel;
afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
afx_msg void OnMouseLeave();
afx_msg void OnTimer(UINT_PTR nIDEvent);
};
// DlgRightToolBar.cpp : 实现文件
//

#include "stdafx.h"
#include "DemoA.h"
#include "DlgRightToolBar.h"
#include "afxdialogex.h"
#include "DrawManager.h"
#include "ObjectRectBase.h"
#include "TransparentPNG.h"

// CDlgRightToolBar 对话框
enum { emRCTDlgTimerUpdate = 1, emRCTDlgTimerMoveRight};
IMPLEMENT_DYNAMIC(CDlgRightToolBar, CDialogEx)

CDlgRightToolBar::CDlgRightToolBar(CWnd* pParent /*=NULL*/)
: CDialogEx(CDlgRightToolBar::IDD, pParent)
, m_show(true)
, m_bMouseTracking(false)
, m_transparentColor(RGB(1,1,1))
{

}

CDlgRightToolBar::~CDlgRightToolBar()
{
}

void CDlgRightToolBar::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_RTB_CHANNEL, m_ctrlListChannel);
}


BEGIN_MESSAGE_MAP(CDlgRightToolBar, CDialogEx)
ON_WM_PAINT()
ON_WM_CTLCOLOR()
ON_WM_SIZE()
ON_WM_CAPTURECHANGED()
ON_WM_NCHITTEST()
ON_WM_MOUSEMOVE()
ON_WM_ACTIVATE()
ON_WM_MOUSELEAVE()
ON_WM_TIMER()
END_MESSAGE_MAP()


// CDlgRightToolBar 消息处理程序


BOOL CDlgRightToolBar::OnInitDialog()
{
CDialogEx::OnInitDialog();

// TODO: 在此添加额外的初始化
ModifyStyleEx(0, WS_EX_LAYERED /*| WS_EX_COMPOSITED*/);
SetLayeredWindowAttributes(m_transparentColor, 200, /*LWA_ALPHA |*/ LWA_COLORKEY);
// SetLayeredWindowAttributes(RGB(240, 240, 240), 200, LWA_ALPHA | LWA_COLORKEY);
m_bgBrush.CreateSolidBrush(m_transparentColor);
// CImage image;
// image.Load(_T("resource\\floatingBg.bmp"));
// HBITMAP hbmp = NULL;
// CBitmap bmp;
// hbmp = image.Detach();
// m_bgBrush.CreatePatternBrush(bmp.FromHandle(hbmp));
InitChannelList();
RefreshChannelList();
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
void CDlgRightToolBar::InitChannelList()
{
DWORD dwStyle = m_ctrlListChannel.GetExtendedStyle();
dwStyle |= LVS_EX_FULLROWSELECT;//选中某行使整行高亮(只适用与report风格的listctrl)
dwStyle |= LVS_EX_GRIDLINES;//网格线(只适用与report风格的listctrl)
dwStyle |= LVS_EX_CHECKBOXES;//item前生成checkbox控件
dwStyle |= LVS_EX_TRACKSELECT;
// dwStyle |= LVS_NOCOLUMNHEADER;
m_ctrlListChannel.SetExtendedStyle(dwStyle); //设置扩展风格

m_ctrlListChannel.SetTextBkColor(CLR_NONE);

CString columnHead[emChannelMax] = {
_T("选择")
, _T("节目名称")
, _T("编号")
};
int width[emChannelMax] = {40, 80, 36};

for (int i = emChannelSelect; i < emChannelMax; ++i)
{
m_ctrlListChannel.InsertColumn(i, columnHead[i], LVCFMT_LEFT, width[i]);
}
}
void CDlgRightToolBar::RefreshChannelList()
{
int channelCount = CDrawManager::GetInstance()->GetChannelCount();

const std::list

& channellist = CDrawManager::GetInstance()->GetList();
m_ctrlListChannel.DeleteAllItems();
for (auto it = channellist.rbegin(); it != channellist.rend(); ++it)
{
CString num;
num.Format(_T("%d"), (*it)->GetChannel());
m_ctrlListChannel.InsertItem(0, "");
m_ctrlListChannel.SetItemText(0, emChannelName, (*it)->GetName());
m_ctrlListChannel.SetItemText(0, emChannelNumber, num);
}
}
void CDlgRightToolBar::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: 在此处添加消息处理程序代码
// 不为绘图消息调用 CDialogEx::OnPaint()
//
CRect rc;
GetClientRect(rc);
rc.right = rc.left + emRCTDlgWidthMax;
CImage image;
image.Load(_T("resource\\floating.png"));
CTransparentPNG trans;
trans(&image);
CRect imageRc(0, 0, image.GetWidth(), image.GetHeight());
image.Draw(dc.m_hDC, rc, imageRc);
}


HBRUSH CDlgRightToolBar::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);

// TODO: 在此更改 DC 的任何特性
// TODO: 如果默认的不是所需画笔,则返回另一个画笔
return m_bgBrush;
return hbr;
}


void CDlgRightToolBar::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
//InvalidateRect(NULL);
if (0 != cx && 0 != cy)
{
if (m_ctrlListChannel.m_hWnd)
{
m_ctrlListChannel.MoveWindow(50, 80, 170, cy-110, SWP_NOACTIVATE);
}

}
// TODO: 在此处添加消息处理程序代码
}


void CDlgRightToolBar::OnCaptureChanged(CWnd *pWnd)
{
// TODO: 在此处添加消息处理程序代码

CDialogEx::OnCaptureChanged(pWnd);
}


LRESULT CDlgRightToolBar::OnNcHitTest(CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值

return CDialogEx::OnNcHitTest(point);
}


void CDlgRightToolBar::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值

TRACKMOUSEEVENT tme;
tme.cbSize=sizeof(TRACKMOUSEEVENT); //监控鼠标离开
tme.dwFlags=TME_LEAVE;
tme.hwndTrack=this->m_hWnd;

if(::_TrackMouseEvent(&tme))
{
if (!m_bMouseTracking)
{
SetLayeredWindowAttributes(m_transparentColor, 200, /*LWA_ALPHA |*/ LWA_COLORKEY);
KillTimer(emRCTDlgTimerMoveRight);
CRect crc;
GetClientRect(crc);
crc.left = crc.right-emRCTDlgWidthMax;
ClientToScreen(crc);
MoveWindow(crc);
}
m_bMouseTracking=true; //其他鼠标进入时的操作
}

CDialogEx::OnMouseMove(nFlags, point);
}


void CDlgRightToolBar::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CDialogEx::OnActivate(nState, pWndOther, bMinimized);

return;
switch(nState)
{
case WA_ACTIVE :
{
CRect crc;
GetClientRect(crc);
CRect wrc;
GetParent()->GetWindowRect(wrc);
SetWindowPos(NULL/*FromHandle(m_hWnd)*/, wrc.right-emRCTDlgWidthMax, wrc.top, emRCTDlgWidthMax, wrc.bottom-wrc.top+50, SWP_NOACTIVATE);
}
break;
case WA_INACTIVE:
{
CRect crc;
GetClientRect(crc);
CRect wrc;
GetWindowRect(wrc);
SetWindowPos(NULL/*FromHandle(m_hWnd)*/, wrc.right-50, wrc.top, 50, 100, SWP_NOACTIVATE);
}
break;
case WA_CLICKACTIVE:
{
CRect crc;
GetClientRect(crc);
CRect wrc;
GetParent()->GetWindowRect(wrc);
SetWindowPos(NULL/*FromHandle(m_hWnd)*/, wrc.right-emRCTDlgWidthMax, wrc.top, emRCTDlgWidthMax, wrc.bottom-wrc.top+50, SWP_NOACTIVATE);
}
break;
}
TRACE("CDlgRightToolBar::OnActivate state %d min %d\n", nState, bMinimized);
// TODO: 在此处添加消息处理程序代码
}


void CDlgRightToolBar::OnMouseLeave()
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
m_bMouseTracking=false;
CPoint point;
GetCursorPos(&point);
CRect winRc;
m_ctrlListChannel.GetWindowRect(winRc);
if (!winRc.PtInRect(point))
{
SetTimer(emRCTDlgTimerMoveRight, 200, NULL);
}
//ShowWindow(SW_HIDE);
TRACE("CDlgRightToolBar::OnMouseLeave posx=%d, posy=%d \n\
left=%d right=%d top=%d bottom=%d\n"
, point.x, point.y, winRc.left, winRc.top, winRc.right, winRc.bottom);

CDialogEx::OnMouseLeave();
}


void CDlgRightToolBar::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
switch (nIDEvent)
{
case emRCTDlgTimerMoveRight:
{
CRect crc;
GetClientRect(crc);
if (crc.right > emRCTDlgWidthMin)
{
int tran = crc.right*100/240+100;
SetLayeredWindowAttributes(m_transparentColor, tran, LWA_ALPHA | LWA_COLORKEY);
crc.left+=10;
ClientToScreen(crc);
// MoveWindow(crc);
SetWindowPos(NULL, crc.left, crc.top, crc.right-crc.left, crc.bottom-crc.top, SWP_NOACTIVATE);
}
else
{
SetLayeredWindowAttributes(m_transparentColor, 100, LWA_ALPHA | LWA_COLORKEY);
KillTimer(emRCTDlgTimerMoveRight);
}
}
break;
default:
break;
}
CDialogEx::OnTimer(nIDEvent);
}
void CDlgRightToolBar::TransparentWindowsDefault()
{
SetLayeredWindowAttributes(m_transparentColor, 100, /*LWA_ALPHA |*/ LWA_COLORKEY);
}
void CDlgRightToolBar::TransparentWindows()
{
SetLayeredWindowAttributes(m_transparentColor, 100, LWA_ALPHA | LWA_COLORKEY);
}

void CDlgRightToolBar::ShowMinimize()
{
SetLayeredWindowAttributes(m_transparentColor, 100, LWA_ALPHA | LWA_COLORKEY);

CRect crc;
GetClientRect(crc);
crc.left = crc.right-emRCTDlgWidthMin;
ClientToScreen(crc);
SetWindowPos(NULL, crc.left, crc.top, crc.right-crc.left, crc.bottom-crc.top, SWP_NOACTIVATE);
}
void CDlgRightToolBar::ShowMaximize()
{
SetLayeredWindowAttributes(m_transparentColor, 100, /*LWA_ALPHA | */LWA_COLORKEY);

CRect crc;
GetClientRect(crc);
crc.left = crc.right -emRCTDlgWidthMax;
ClientToScreen(crc);
SetWindowPos(NULL, crc.left, crc.top, crc.right-crc.left, crc.bottom-crc.top, SWP_NOACTIVATE);
}