-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVideoFrame.cpp
More file actions
827 lines (762 loc) · 22 KB
/
Copy pathVideoFrame.cpp
File metadata and controls
827 lines (762 loc) · 22 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
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
// VideoFrame.cpp : implementation file
//
#include "stdafx.h"
#include "VideoFrame.h"
// CVideoFrame
IMPLEMENT_DYNAMIC(CVideoFrame, CWnd)
map<HWND, HWND>CVideoFrame::m_PanelMap;
CriticalSectionPtr CVideoFrame::m_csPannelMap = make_shared<CriticalSectionWrap>();
CVideoFrame *CVideoFrame::m_pCurrentFrame = nullptr;
CVideoFrame::CVideoFrame()
{
m_nCols = m_nRows = 1;
m_nNewCols = m_nNewRows = 1;
m_nPannelUsed = 0; // 已用窗格数量
m_pSelectedPen = NULL;
m_pUnSelectedPen = NULL;
m_pRestorePen = NULL;
m_pCurSelectRect = nullptr;
m_pLastSelectRect = nullptr;
m_nCurPanel = -1;
m_nFrameStyle = StyleNormal;
}
CVideoFrame::~CVideoFrame()
{
if (m_pSelectedPen)
delete m_pSelectedPen;
if (m_pUnSelectedPen)
delete m_pUnSelectedPen;
if (m_pRestorePen)
delete m_pRestorePen;
}
BEGIN_MESSAGE_MAP(CVideoFrame, CWnd)
ON_WM_CREATE()
ON_WM_PAINT()
ON_WM_DESTROY()
ON_WM_SIZE()
ON_MESSAGE(WM_TROGGLEFULLSCREEN,OnTroggleFullScreen)
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
ON_WM_CTLCOLOR()
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
// CVideoFrame message handlers
BOOL CVideoFrame::Create(UINT nID, const RECT& rect,int nCount,CWnd* pParentWnd, CCreateContext* pContext)
{
UINT nRows = 0,nCols = 0;
CalcRowCol(nCount,nRows,nCols);
return Create(nID,rect,nRows,nCols,pParentWnd,pContext);
}
BOOL CVideoFrame::Create(UINT nID, const RECT& rect,int nRow,int nCol, CWnd* pParentWnd, CCreateContext* pContext)
{
// can't use for desktop or pop-up windows (use CreateEx instead)
ASSERT(pParentWnd != NULL);
ASSERT(nID != 0);
ASSERT(nRow != 0 && nCol != 0);
m_nNewRows = nRow;
m_nNewCols = nCol;
LPCTSTR szWndClass = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS, ::LoadCursor(NULL, IDC_ARROW), (HBRUSH) ::GetStockObject(BLACK_BRUSH), NULL);
return CreateEx(0, szWndClass, _T("VideoFrame"),
WS_CHILD | WS_VISIBLE,
rect.left, rect.top,
rect.right - rect.left,
rect.bottom - rect.top,
pParentWnd->GetSafeHwnd(),
(HMENU)(UINT_PTR)nID,
(LPVOID)pContext);
}
BOOL CVideoFrame::Create(UINT nID, const RECT& rect,FrameStyle nStyle,CWnd* pParentWnd, CCreateContext* pContext)
{
ASSERT(pParentWnd != NULL);
ASSERT(nID != 0);
//ASSERT(nRow != 0 && nCol != 0);
ASSERT(nStyle != StyleNormal);
if (nStyle == StyleNormal)
return FALSE;
m_nFrameStyle = nStyle;
switch(nStyle)
{
case StyleNormal:
default:
break;
case Style_5P1:
m_nRows = m_nCols = 3;
break;
case Style_7P1:
m_nRows = m_nCols = 4;
break;
case Style_9P1:
m_nRows = m_nCols = 5;
break;
}
LPCTSTR szWndClass = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS, ::LoadCursor(NULL, IDC_ARROW), (HBRUSH) ::GetStockObject(BLACK_BRUSH), NULL);
return CreateEx(0, szWndClass, _T("VideoFrame"),
WS_CHILD | WS_VISIBLE,
rect.left, rect.top,
rect.right - rect.left,
rect.bottom - rect.top,
pParentWnd->GetSafeHwnd(),
(HMENU)(UINT_PTR)nID,
(LPVOID)pContext);
}
BOOL CVideoFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style &= ~WS_BORDER | ~WS_CAPTION | ~WS_SYSMENU | ~WS_THICKFRAME | ~WS_VSCROLL | ~WS_HSCROLL;
cs.style |= WS_CHILD | WS_VISIBLE;
return CWnd::PreCreateWindow(cs);
}
#define BackColor RGB(0,0,0)
#define SelectColor RGB(255,255,0)
int CVideoFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
m_pSelectedPen = new CPen(PS_SOLID, 1, SelectColor);
m_pUnSelectedPen = new CPen(PS_SOLID, _GRID_LINE_WIDTH, BackColor);
m_pRestorePen = new CPen(PS_SOLID, 1, BackColor);
AdjustPanels(m_nNewRows, m_nNewCols);
return 0;
}
// 调整窗格数量
// 如果是新增窗格,则不需要删除原有的窗格
// 如果是缩减窗格,则仅删除多余的窗格
bool CVideoFrame::AdjustPanels(int nRows, int nCols,FrameStyle fs)
{
ASSERT(nRows != 0 && nCols != 0);
if (!nRows || !nCols)
return false;
int nPanelCount = nRows*nCols;
if (fs == StyleNormal)
{
// 行列数相同,不作调整
if (fs == m_nFrameStyle &&
nRows == m_nRows &&
nCols == m_nCols)
return true;
}
m_nFrameStyle = fs;
switch(m_nFrameStyle)
{
case StyleNormal:
default:
break;
case Style_2P1:
nPanelCount = 3;
nRows = 2;
nCols = 2;
break;
case Style_5P1:
nRows = nCols = 3;
nPanelCount = 6;
break;
case Style_7P1:
nRows = nCols = 4;
nPanelCount = 8;
break;
case Style_9P1:
nRows = nCols = 5;
nPanelCount = 10;
break;
case Style_11P1:
nRows = nCols = 6;
nPanelCount = 12;
break;
case Style_13P1:
nRows = nCols = 7;
nPanelCount = 14;
break;
case Style_15P1:
nRows = nCols = 8;
nPanelCount = 16;
break;
}
//缩减窗格
if (nPanelCount < m_vecPanel.size())
{
int nReduceCount = m_vecPanel.size() - nPanelCount;
int nReduced = 0;
// 从后往前删除
for (vector<PanelInfoPtr>::reverse_iterator rit = m_vecPanel.rbegin() ;rit != m_vecPanel.rend() && nReduced < nReduceCount;)
{
::ShowWindow((*rit)->hWnd,SW_HIDE);
//::InvalidateRect((*rit)->hWnd, NULL, TRUE);
m_listRecyclePanel.push_back(*rit);
rit = vector<PanelInfoPtr>::reverse_iterator(m_vecPanel.erase((++rit).base()));
nReduced ++;
}
// 调整窗格尺寸
}
else if (nPanelCount > m_vecPanel.size()) // 新增窗格
{
int nAddCount = nPanelCount - m_vecPanel.size();
// 优先从回收窗口表中取回窗口
int nSize = m_listRecyclePanel.size();
if (nAddCount >= nSize)
{// 回收窗口数大于需要窗口数
for (list<PanelInfoPtr>::reverse_iterator rit = m_listRecyclePanel.rbegin();rit != m_listRecyclePanel.rend();)
{
::ShowWindow((*rit)->hWnd,SW_SHOW);
//::InvalidateRect((*rit)->hWnd, NULL, TRUE);
m_vecPanel.push_back(*rit);
rit = list<PanelInfoPtr>::reverse_iterator(m_listRecyclePanel.erase((++rit).base()));
}
nAddCount -= nSize;
for (int i = 0; i < nAddCount; i++)
{
m_vecPanel.push_back(PanelInfoPtr(new PanelInfo(0, 0)));
}
}
else
{
int nAdded = 0;
for (list<PanelInfoPtr>::reverse_iterator rit = m_listRecyclePanel.rbegin();
rit != m_listRecyclePanel.rend() && nAdded < nAddCount;
nAdded ++)
{
::ShowWindow((*rit)->hWnd,SW_SHOW);
//::InvalidateRect((*rit)->hWnd, NULL, TRUE);
m_vecPanel.push_back(*rit);
rit = list<PanelInfoPtr>::reverse_iterator(m_listRecyclePanel.erase((++rit).base()));
}
}
}
else
return true;
m_nRows = nRows;
m_nCols = nCols;
// 调整窗格的行列编号
int nIndex = 0;
if (m_nFrameStyle == StyleNormal)
{
for (int nRow = 0; nRow < m_nRows; nRow++)
{
for (int nCol = 0; nCol < m_nCols; nCol++)
{
m_vecPanel[nIndex]->nCol = nCol;
m_vecPanel[nIndex]->nRow = nRow;
nIndex ++;
}
}
// 重新计算每一个窗口的大小
ResizePanel();
// 调整每个窗口的位置
nIndex = 0;
for (int nRow = 0; nRow < m_nRows; nRow++)
{
for (int nCol = 0; nCol < m_nCols; nCol++)
{
PanelInfoPtr pPanel = m_vecPanel[nIndex ++];
if (!pPanel->hWnd ||
!IsWindow(pPanel->hWnd))
{
pPanel->hWnd = CreatePanel(nRow, nCol);
::ShowWindow(pPanel->hWnd, SW_SHOW);
}
else
::MoveWindow(pPanel->hWnd,pPanel->rect.left,pPanel->rect.top,RectWidth(pPanel->rect),RectHeight(pPanel->rect),FALSE);
}
}
}
else
{
// 调整窗格的行列编号
m_vecPanel[nIndex]->nCol = 0;
m_vecPanel[nIndex]->nRow = 0;
if (m_nFrameStyle == Style_2P1)
{
m_vecPanel[1]->nCol = 1;
m_vecPanel[1]->nRow = 0;
m_vecPanel[2]->nCol = 1;
m_vecPanel[2]->nRow = 1;
}
else
{
for (int nRow = 0; nRow < m_nRows; nRow++)
{
m_vecPanel[nIndex]->nRow = nRow;
m_vecPanel[nIndex]->nCol = m_nCols - 1;
nIndex ++;
}
for (int nCol = 0; nCol < m_nCols; nCol++)
{
m_vecPanel[nIndex]->nRow = m_nRows - 1;
m_vecPanel[nIndex]->nCol = nCol;
nIndex ++;
}
}
// 重新计算每一个窗口的大小
ResizePanel();
// 先设置最大的窗口,需要重新调整尺寸
PanelInfoPtr pPanel = m_vecPanel[0];
if (!pPanel->hWnd ||
!IsWindow(pPanel->hWnd))
{
pPanel->hWnd = CreatePanel(0, 0);
::ShowWindow(pPanel->hWnd, SW_SHOW);
}
else
::MoveWindow(pPanel->hWnd,pPanel->rect.left,pPanel->rect.top,RectWidth(pPanel->rect),RectHeight(pPanel->rect),FALSE);
nIndex = 1;
// 再调整右侧一列的窗口
int nRows = m_nRows - 1;
int nCols = m_nCols;
if (m_nFrameStyle == Style_2P1)
{
nRows = m_nRows;
nCols = 0;
}
{
for (int nRow = 0; nRow < nRows; nRow++)
{
PanelInfoPtr pPanel = m_vecPanel[nIndex ];
if (!pPanel->hWnd ||
!IsWindow(pPanel->hWnd))
{
pPanel->hWnd = CreatePanel(nIndex);
::ShowWindow(pPanel->hWnd, SW_SHOW);
}
else
::MoveWindow(pPanel->hWnd,pPanel->rect.left,pPanel->rect.top,RectWidth(pPanel->rect),RectHeight(pPanel->rect),FALSE);
nIndex ++;
}
// 调整底层一行窗口
for (int nCol = 0; nCol < nCols; nCol++)
{
PanelInfoPtr pPanel = m_vecPanel[nIndex];
if (!pPanel->hWnd ||
!IsWindow(pPanel->hWnd))
{
pPanel->hWnd = CreatePanel(nIndex );
::ShowWindow(pPanel->hWnd, SW_SHOW);
}
else
::MoveWindow(pPanel->hWnd,pPanel->rect.left,pPanel->rect.top,RectWidth(pPanel->rect),RectHeight(pPanel->rect),FALSE);
nIndex ++;
}
}
}
Invalidate();
return true;
}
bool CVideoFrame::AdjustPanels(int nCount,FrameStyle fs)
{
if (fs != StyleNormal && fs == m_nFrameStyle)
return true;
CalcRowCol(nCount,m_nNewRows,m_nNewCols);
_TraceMsgA("%s Rows = %d\tCols = %d.\n", __FUNCTION__, m_nNewRows, m_nNewCols);
return AdjustPanels(m_nNewRows, m_nNewCols,fs);
}
void CVideoFrame::DrawGrid(CDC *pDc)
{
// CRect rtClient;
// GetClientRect(&rtClient);
// pDc->FillSolidRect(&rtClient,BackColor);
// CPen* pOldPen = (CPen *)pDc->SelectObject(m_pUnSelectedPen);
// for (list<LinePtr>::iterator it = m_listLine.begin();it != m_listLine.end();it ++)
// {
// pDc->MoveTo((*it)->ptStart);
// pDc->LineTo((*it)->ptStop);
// }
/*
GetClientRect(&rtClient);
int nWidth = rtClient.Width();
int nHeight = rtClient.Height();
int nAvgColWidth = nWidth / m_nCols;
int nAvgRowHeight = nHeight / m_nRows;
int nRemainedWidth = nWidth - nAvgColWidth*m_nCols; // 平均分配宽度有盈余
int nRemainedHeight = nHeight - nAvgRowHeight*m_nRows; // 平均分配高度有盈余
int nStartX = rtClient.left;
int nStartY = rtClient.top;
// 画竖线
for (int nCol = 0; nCol < m_nCols; nCol++)
{
if (nCol > 0 && nRemainedWidth > 0)
{
nStartX++;
nRemainedWidth--;
}
if (nCol > 0)
{
pDc->MoveTo(nStartX, nStartY);
pDc->LineTo(nStartX, rtClient.bottom);
}
nStartX += nAvgColWidth;
}
// 画横线
for (int nRow = 0; nRow < m_nRows; nRow++)
{
if (nRow > 0 && nRemainedHeight > 0)
{
nStartY++;
nRemainedHeight--;
}
if (nRow > 0)
{
pDc->MoveTo(rtClient.left, nStartY);
pDc->LineTo(rtClient.right, nStartY);
}
nStartY += nAvgRowHeight;
}
pDc->SelectObject(pOldPen);
*/
//#ifdef _DEBUG
// _TraceMsgA("Index\tLeft\tRight\tTop\t\tBottom.\n");
// for (int nRow = 0; nRow < m_nRows; nRow++)
// {
// for (int nCol = 0; nCol < m_nCols; nCol++)
// {
// int nIndex = nRow*m_nCols + nCol;
// RECT rtWnd = m_vecPanel[nIndex]->rect;
// _TraceMsgA("(%d,%d)\t%d\t\t%d\t\t%d\t\t%d\n",nRow,nCol, pRtWnd->left, pRtWnd->right, pRtWnd->top, pRtWnd->bottom);
// }
// }
//#endif
}
// void CVideoFrame::OnPaint()
// {
// CPaintDC dc(this); // device context for painting
//
// DrawGrid(&dc);
// }
void CVideoFrame::OnDestroy()
{
CWnd::OnDestroy();
}
void CVideoFrame::ResizePanel(int nWidth,int nHeight)
{
CRect rtClient;
m_pLastSelectRect = nullptr;
m_pCurSelectRect = nullptr;
if (!nWidth || !nHeight )
{
GetClientRect(&rtClient);
if (!nWidth)
nWidth = rtClient.Width();
if (!nHeight)
nHeight = rtClient.Height();
}
int nAvgColWidth = (nWidth - _GRID_LINE_WIDTH*(m_nCols + 1))/ m_nCols;
int nAvgRowHeight = (nHeight - _GRID_LINE_WIDTH*(m_nRows + 1)) / m_nRows;
int nRemainedWidth = nWidth - nAvgColWidth*m_nCols ; // 平均分配宽度有盈余
int nRemainedHeight = nHeight - nAvgRowHeight*m_nRows; // 平均分配高度有盈余
vector<RECT>vecRect;
RECT rtSample = {0,0,0,0};
for (int nRow = 0;nRow < m_nRows;nRow ++)
for (int nCol = 0;nCol < m_nCols;nCol ++)
{
vecRect.push_back(rtSample);
}
if (m_nRows == 1 && m_nCols == 1)
{
vecRect[0].left = 1;
vecRect[0].right = nWidth - 1;
vecRect[0].top = 1;
vecRect[0].bottom = nHeight - 1;
}
else
{
// 先计算标准表情况下每个格子的尺寸
int nStartX = _GRID_LINE_WIDTH;
int nIndex = 0;
for (int nCol = 0; nCol < m_nCols; nCol++)
{
if (nCol > 0 && nRemainedWidth > 0)
{
nStartX++;
nRemainedWidth--;
}
// 计算每个窗格的左右边界
for (int nRow = 0; nRow < m_nRows; nRow++)
{
if ( nCol > 0)
{
vecRect[nRow*m_nCols + nCol - 1].right = nStartX - _GRID_LINE_WIDTH;
vecRect[nRow*m_nCols + nCol].left = nStartX + _GRID_LINE_WIDTH;
}
else
vecRect[nRow*m_nCols + nCol].left = nStartX ;
}
nStartX += nAvgColWidth;
}
// 修正最右一列的右坐标
for (int nRow = 0; nRow < m_nRows; nRow++)
vecRect[nRow*m_nCols + m_nCols - 1].right = nWidth - _GRID_LINE_WIDTH ;
int nStartY = _GRID_LINE_WIDTH;
for (int nRow = 0; nRow < m_nRows; nRow++)
{
if (nRow > 0 && nRemainedHeight > 0)
{
nStartY++;
nRemainedHeight--;
}
// 计算每个空格的上下边界
for (int nCol = 0; nCol < m_nCols; nCol++)
{
if (nRow > 0)
{
vecRect[nRow*m_nCols + nCol].top = nStartY + _GRID_LINE_WIDTH;
vecRect[(nRow - 1)*m_nCols + nCol].bottom = nStartY - _GRID_LINE_WIDTH;
}
else
vecRect[nRow*m_nCols + nCol].top = nStartY;
}
nStartY += nAvgRowHeight;
}
// 修正最下一行的底坐标
for (int nCol = 0; nCol < m_nCols; nCol++)
vecRect[(m_nRows - 1)*m_nCols + nCol].bottom = nHeight - _GRID_LINE_WIDTH;
}
if (m_nFrameStyle == StyleNormal)
{
for (int i = 0;i < m_vecPanel.size();i ++)
m_vecPanel[i]->rect = vecRect[i];
// // 使用背景色作为表格线条颜色,因此不再需要另外绘制线条
// // xionggao.lee @ 2017.02.08
// // 计算竖线条坐标
// for (int nCol = 0;nCol < m_nCols - 1;nCol ++)
// {
// LinePtr pLine = LinePtr(new _Line);
// pLine->ptStart.x = vecRect[nCol].right + 2;
// pLine->ptStart.y = vecRect[nCol].top - 2;
//
// pLine->ptStop.x = vecRect[(m_nRows - 1)*m_nCols + nCol].right + 2;
// pLine->ptStop.y = vecRect[(m_nRows - 1)*m_nCols + nCol].bottom + 2;
// m_listLine.push_back(pLine);
// }
// // 计算横线条坐标
// for (int nRow = 0;nRow < m_nRows - 1;nRow ++)
// {
// LinePtr pLine = LinePtr(new _Line);
// pLine->ptStart.x = vecRect[nRow*m_nCols].left - 2;
// pLine->ptStart.y = vecRect[nRow*m_nCols].bottom + 2;
//
// pLine->ptStop.x = vecRect[(nRow + 1)*m_nCols - 1].right + 2;
// pLine->ptStop.y = vecRect[(nRow + 1)*m_nCols - 1].bottom + 2;
// m_listLine.push_back(pLine);
// }
}
else
{
if (m_nFrameStyle == Style_2P1)
{
m_vecPanel[0]->rect.left = vecRect[0].left;
m_vecPanel[0]->rect.top = vecRect[0].top;
m_vecPanel[0]->rect.right = vecRect[0].right;
m_vecPanel[0]->rect.bottom = vecRect[2].bottom;
m_vecPanel[1]->rect = vecRect[1];
m_vecPanel[2]->rect = vecRect[3];
// // 使用背景色作为表格线条颜色,因此不再需要另外绘制线条
// // xionggao.lee @ 2017.02.08
// LinePtr pLine = LinePtr(new _Line);
// pLine->ptStart.x = vecRect[0].right + 2;
// pLine->ptStart.y = vecRect[0].top - 2;
//
// pLine->ptStop.x = vecRect[2].right + 2;
// pLine->ptStop.y = vecRect[2].bottom + 2;
// m_listLine.push_back(pLine);
//
// pLine = LinePtr(new _Line);
// pLine->ptStart.x = vecRect[0].right + 2;
// pLine->ptStart.y = vecRect[0].bottom + 2;
//
// pLine->ptStop.x = vecRect[1].right + 2;
// pLine->ptStop.y = vecRect[1].bottom + 2;
// m_listLine.push_back(pLine);
}
else
{
m_vecPanel[0]->rect.left = vecRect[0].left;
m_vecPanel[0]->rect.top = vecRect[0].top;
int nRightBottom = (m_nRows-1)*m_nCols - 2;
m_vecPanel[0]->rect.right = vecRect[nRightBottom].right;
m_vecPanel[0]->rect.bottom = vecRect[nRightBottom].bottom;
int nIndex = 1;
for (int nRow = 0;nRow < m_nRows - 1;nRow ++)
m_vecPanel[nIndex ++]->rect = vecRect[(nRow + 1)*m_nCols - 1];
for (int nCol = 0;nCol < m_nCols;nCol ++)
m_vecPanel[nIndex ++]->rect = vecRect[(m_nRows-1)*m_nCols + nCol];
// // 使用背景色作为表格线条颜色,因此不再需要另外绘制线条
// // xionggao.lee @ 2017.02.08
// // 计算长竖线条
// LinePtr pLine = LinePtr(new _Line);
// pLine->ptStart.x = vecRect[m_nCols - 2].right + 2;
// pLine->ptStart.y = vecRect[m_nCols - 2].top - 2;
//
// pLine->ptStop.x = vecRect[m_nRows*m_nCols - 2].right + 2;
// pLine->ptStop.y = vecRect[m_nRows*m_nCols - 2].bottom + 2;
// m_listLine.push_back(pLine);
//
// // 计算长横线条
// pLine = LinePtr(new _Line);
// pLine->ptStart.x = vecRect[(m_nRows - 2)*m_nCols].left - 2;
// pLine->ptStart.y = vecRect[(m_nRows - 2)*m_nCols].bottom + 2;
//
// pLine->ptStop.x = vecRect[(m_nRows - 1)*m_nCols - 1].right + 2;
// pLine->ptStop.y = vecRect[(m_nRows - 1)*m_nCols - 1].bottom + 2;
// m_listLine.push_back(pLine);
//
// // 计算短线竖条坐标
// for (int nCol = 0;nCol < m_nCols - 2;nCol ++)
// {
// LinePtr pLine = LinePtr(new _Line);
// pLine->ptStart.x = vecRect[(m_nRows -2)*nCol].right + 2;
// pLine->ptStart.y = vecRect[(m_nRows -2)*nCol].bottom + 2;
//
// pLine->ptStop.x = vecRect[(m_nRows - 1)*m_nCols + nCol].right + 2;
// pLine->ptStop.y = vecRect[(m_nRows - 1)*m_nCols + nCol].bottom + 2;
// m_listLine.push_back(pLine);
// }
//
// // 计算短横线条坐标
// for (int nRow = 0;nRow < m_nRows - 2;nRow ++)
// {
// LinePtr pLine = LinePtr(new _Line);
// pLine->ptStart.x = vecRect[(nRow + 1)*m_nCols - 2].left - 2;
// pLine->ptStart.y = vecRect[(nRow + 1)*m_nCols - 2].bottom + 2;
//
// pLine->ptStop.x = vecRect[(nRow + 1)*m_nCols - 1].right + 2;
// pLine->ptStop.y = vecRect[(nRow + 1)*m_nCols - 1].bottom + 2;
// m_listLine.push_back(pLine);
// }
}
}
//所有矩形内缩一个象素
// for (vector<PanelInfoPtr>::iterator it = m_vecPanel.begin();it != m_vecPanel.end();it ++)
// {
// LPRECT pRect = &(*it)->rect;
// pRect->left += 1;
// pRect->top += 1;
// pRect->right -= 1;
// pRect->bottom -= 1;
// }
//#ifdef _DEBUG
// _TraceMsgA("Index\tLeft\tRight\tTop\t\tBottom.\n");
// for (int nRow = 0; nRow < m_nRows; nRow++)
// {
// for (int nCol = 0; nCol < m_nCols; nCol++)
// {
// int nIndex = nRow*m_nCols + nCol;
// RECT rtWnd = m_vecPanel[nIndex]->rect;
// _TraceMsgA("(%d,%d)\t%d\t\t%d\t\t%d\t\t%d\n",nRow,nCol, pRtWnd->left, pRtWnd->right, pRtWnd->top, pRtWnd->bottom);
// }
// }
//#endif
}
void CVideoFrame::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
ResizePanel(cx, cy);
for (vector<PanelInfoPtr>::iterator it = m_vecPanel.begin(); it != m_vecPanel.end(); it++)
(*it)->UpdateWindow();
RefreshSelectedPanel();
}
LRESULT CVideoFrame::OnTroggleFullScreen(WPARAM W, LPARAM L)
{
HWND hRoot = ::GetAncestor(m_hWnd, GA_ROOT);
if (hRoot)
{
::PostMessage(hRoot, WM_TROGGLEFULLSCREEN, W, L);
}
return 0;
}
void CVideoFrame::RefreshSelectedPanel()
{
if (m_nCurPanel == -1)
return ;
CClientDC dc(this);
RECT rtTemp;
CPen* pOldPen = nullptr;
CBrush *pBrush= CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
CBrush *pOldBrush=dc.SelectObject(pBrush);
if (m_pLastSelectRect)
{
::CopyRect(&rtTemp,m_pLastSelectRect);
rtTemp.left -=1;
rtTemp.top -= 1;
rtTemp.right += 1;
rtTemp.bottom += 1;
pOldPen = (CPen *)dc.SelectObject(m_pRestorePen);
dc.Rectangle(&rtTemp);
}
if (m_nCurPanel < m_vecPanel.size())
m_pCurSelectRect = &m_vecPanel[m_nCurPanel]->rect;
if (m_pCurSelectRect)
{
::CopyRect(&rtTemp,m_pCurSelectRect);
rtTemp.left -=1;
rtTemp.top -= 1;
rtTemp.right += 1;
rtTemp.bottom += 1;
if (!pOldPen)
pOldPen = (CPen*)dc.SelectObject(m_pSelectedPen);
else
dc.SelectObject(m_pSelectedPen);
dc.Rectangle(&rtTemp);
}
dc.SelectObject(pOldBrush);
dc.SelectObject(pOldPen);
}
void CVideoFrame::OnLButtonDown(UINT nFlags, CPoint point)
{
for (int nIndex = 0;nIndex < m_vecPanel.size();nIndex ++)
{
if (::PtInRect(&m_vecPanel[nIndex]->rect,point))
{
m_nCurPanel = nIndex;
if (!m_pCurSelectRect)
{
m_pLastSelectRect = nullptr;
}
else if (m_pCurSelectRect != &m_vecPanel[nIndex]->rect)//从另一窗格切换到当前窗格
{
m_pLastSelectRect = m_pCurSelectRect;
}
m_pCurSelectRect = &m_vecPanel[nIndex]->rect;
RefreshSelectedPanel();
m_pCurrentFrame = this;
}
}
CWnd::OnLButtonDown(nFlags, point);
}
void CVideoFrame::OnRButtonDown(UINT nFlags, CPoint point)
{
for (int nIndex = 0;nIndex < m_vecPanel.size();nIndex ++)
{
if (::PtInRect(&m_vecPanel[nIndex]->rect,point))
{
m_nCurPanel = nIndex;
if (!m_pCurSelectRect)
{
m_pLastSelectRect = nullptr;
}
else if (m_pCurSelectRect != &m_vecPanel[nIndex]->rect)//从另一窗格切换到当前窗格
{
m_pLastSelectRect = m_pCurSelectRect;
}
m_pCurSelectRect = &m_vecPanel[nIndex]->rect;
RefreshSelectedPanel();
m_pCurrentFrame = this;
HWND hParentWnd = GetParent()->GetSafeHwnd();
if (!hParentWnd)
SendMessage(WM_FRAME_RBUTTONDOWN,(WPARAM)MAKEWPARAM(point.x,point.y),(LPARAM)m_nCurPanel);
}
}
CWnd::OnRButtonDown(nFlags, point);
}
HBRUSH CVideoFrame::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CreateSolidBrush(BackColor); //创建背景刷;
pDC->SetBkMode(TRANSPARENT);
return hbr;
}
BOOL CVideoFrame::OnEraseBkgnd(CDC* pDC)
{
CBrush back(BackColor);
CBrush* pold=pDC->SelectObject(&back);
CRect rect;
pDC->GetClipBox (&rect);
pDC->PatBlt (rect.left,rect.top,rect.Width(),rect.Height(),PATCOPY);
pDC->SelectObject(pold);
RefreshSelectedPanel();
return TRUE;
}