/
BSWndContainer.cpp
641 lines (553 loc) · 15.5 KB
/
BSWndContainer.cpp
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
// BSWndContainer.cpp : implementation file
//
#include "stdafx.h"
#include "BSWndContainer.h"
#include "BarcodeRecord.h"
//////////////////////////////////////////////////////////////
#include "BarcodeRecordDlg.h"
extern CBarcodeRecordDlg *pCMainDlg;
#include "DLGSettings.h"
extern CDLGSettings DlgSettings;
/*
#pragma warning(disable:4706)
#define COMPILE_MULTIMON_STUBS
#include <multimon.h>
#pragma warning(default:4706)
*/
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBSWndContainer
CBSWndContainer::CBSWndContainer()
{
// init active page pointer
m_pActivePage = NULL;
// init window state
m_bFullScreen = FALSE; // 全屏标记
m_bMultiScreen = TRUE; // 多屏标记
m_bAutoAdjustPos= FALSE; // 自动调节标记
for(int i=0;i<MAX_PLAYWIN;i++)
{
m_nStartPlay[i] = FALSE;
m_nStartRecord[i] = FALSE;
}
SetDrawActivePage(TRUE); // 启动边框
m_nShowPortion=100; // 显示比例
}
CBSWndContainer::~CBSWndContainer()
{
// remove all pages
while(!m_PageList.IsEmpty())
m_PageList.RemoveHead();
}
BEGIN_MESSAGE_MAP(CBSWndContainer, CWnd)
//{{AFX_MSG_MAP(CBSWndContainer)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBSWndContainer member functions
///////////////////////////////////////////////////
// call this function to create container object.
// it is override from cwnd class
BOOL CBSWndContainer::Create( LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext )
{
dwStyle|=WS_EX_TOOLWINDOW;
return CWnd::Create(lpszClassName,lpszWindowName,dwStyle,rect,pParentWnd,nID,pContext );
}
///////////////////////////////////////////////////
// call this function to add a page wnd to
// container. if success retrun TRUE,else return
// FALSE.
BOOL CBSWndContainer::AddPage(CWnd *pWnd, BOOL bRepaint)
{
// check parameter
if( !pWnd || !IsWindow(pWnd->m_hWnd) ) return FALSE;
// check list
POSITION pos=m_PageList.Find(pWnd);
if(pos!=NULL)
{
TRACE("This Window has been added to container, the operation will terminate.\n");
return TRUE;
}
// added page
m_PageList.AddTail(pWnd);
if( m_bDrawActive ) DrawActivePage(FALSE);
// reset active page
SetActivePage(pWnd, bRepaint);
return TRUE;
}
///////////////////////////////////////////////////
// call this function to remove a page wnd from
// container.
CWnd *CBSWndContainer::DelPage(CWnd *pWnd)
{
// check list
POSITION pos=m_PageList.Find(pWnd);
if(pos==NULL)
{
TRACE("This Window is not a member of container, the operation will terminate.\n");
return NULL;
}
if(pWnd==m_pActivePage)
if(m_pActivePage==GetPrevPage(pWnd))//m_PageList.IsEmpty()?NULL:m_PageList.GetHead();
m_pActivePage=NULL;
else m_pActivePage=GetPrevPage(pWnd);
m_PageList.RemoveAt(pos);
if (pWnd)
{
pWnd->ShowWindow(SW_HIDE);
}
// Invalidate();
return pWnd;
}
///////////////////////////////////////////////////
// call this function to remove active page from
// container.
CWnd *CBSWndContainer::DelPage()
{
return DelPage(m_pActivePage);
}
///////////////////////////////////////////////////
// call this function to set a page to be active
// page.
void CBSWndContainer::SetActivePage(CWnd *pWnd, BOOL bRepaint)
{
// check parameter
if( !pWnd || !IsWindow(pWnd->m_hWnd) ) return;
// if pWnd is the Active Page, return
if( m_pActivePage==pWnd ) return;
// check list
POSITION pos=m_PageList.Find(pWnd);
if(pos==NULL)
{
TRACE("__This Window is not a member of container, the operation will terminate.\n");
return;
}
if(bRepaint) UpdateWnd();
if( m_bDrawActive ) DrawActivePage(FALSE);
m_pActivePage=pWnd;
if( m_bDrawActive ) DrawActivePage(TRUE);
}
///////////////////////////////////////////////////
// call this function to get the active page's
// pointer. if no active page,return NULL;
CWnd *CBSWndContainer::GetActivePage()
{
return m_pActivePage;
}
CWnd *CBSWndContainer::GetTailPage()
{
return m_PageList.GetTail();
}
///////////////////////////////////////////////////
// call this function to get the next page by
// the page that user defined. if the defined
// page is not find in container, return NULL.
CWnd *CBSWndContainer::GetNextPage(CWnd *pWnd)
{
// check parameter
if( !pWnd || !IsWindow(pWnd->m_hWnd) ) return NULL;
// check list
POSITION pos=m_PageList.Find(pWnd);
if(pos==NULL)
{
TRACE("This Window is not a member of container, the operation will terminate.\n");
return NULL;
}
//
m_PageList.GetNext(pos);
if(pos==NULL)
return m_PageList.GetHead();
else
return m_PageList.GetNext(pos);
}
///////////////////////////////////////////////////
// call this function to get the prev page by
// the page that user defined. if the defined
// page is not find in container,return NULL.
CWnd *CBSWndContainer::GetPrevPage(CWnd *pWnd)
{
// check parameter
if( !pWnd || !IsWindow(pWnd->m_hWnd) ) return NULL;
// check list
POSITION pos=m_PageList.Find(pWnd);
if(pos==NULL)
{
TRACE("This Window is not a member of container, the operation will terminate.\n");
return NULL;
}
//
m_PageList.GetPrev(pos);
if(pos==NULL)
return m_PageList.GetTail();
else
return m_PageList.GetPrev(pos);
}
CWnd *CBSWndContainer::GetPage(int nIndex)
{
CWnd *pRet = NULL;
POSITION pos = m_PageList.FindIndex(nIndex);
if(pos == NULL) return pRet;
return m_PageList.GetAt(pos);
}
int CBSWndContainer::GetCount() const
{
return m_PageList.GetCount();
}
///////////////////////////////////////////////////
// call this function to page wnds,when
// the window is resized.
void CBSWndContainer::UpdateWnd()
{
if(!IsWindowVisible()||IsIconic()) return;
/////////////////////
//计算显示总区域
//得到窗口的设备坐标
CRect rtContainer;
GetClientRect(&rtContainer);
GetShowRect(&rtContainer);
rtContainer.DeflateRect(1,1);
//调整Container位置
if(m_bAutoAdjustPos)
AdjustRect(&rtContainer);
/////////////////////
//
if(m_bMultiScreen)
{ //多屏状态
CRect rt;
int nCount=m_PageList.GetCount();
int i=0;
for(POSITION pos=m_PageList.GetHeadPosition();pos!=NULL;)
{
CWnd *p=m_PageList.GetNext(pos);
rt=rtContainer;
CalcPageRect(&rt,i,nCount);
rt.DeflateRect(WINDOW_SPACE,WINDOW_SPACE,WINDOW_SPACE,WINDOW_SPACE); //窗口之间的间隔
p->MoveWindow(&rt);
p->ShowWindow(SW_SHOW);
i++;
}
if( m_bDrawActive && m_PageList.GetCount()>1 ) DrawActivePage(TRUE);
}
else
{ //单屏状态
for(POSITION pos=m_PageList.GetHeadPosition();pos!=NULL;)
{
CWnd *p=m_PageList.GetNext(pos);
if(p==m_pActivePage)
p->MoveWindow(&rtContainer);
else
{
if(m_bFullScreen)
p->MoveWindow(0,0,1,1);
else
p->MoveWindow(rtContainer.right+1,rtContainer.bottom+1,1,1);
}
}
}
}
int GetCurrentScreenMonitorRect(HWND hWnd,RECT& ScreenRect)
{
/*
int nRet = 0;
HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
MONITORINFO mInfo;
mInfo.cbSize = sizeof(MONITORINFO);
if(GetMonitorInfo(hMonitor,&mInfo) == TRUE)
{
ScreenRect = mInfo.rcMonitor;
}
else
{
//取主窗口的信息
HMONITOR hMonitor2 = MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY);
MONITORINFO mInfo2;
mInfo2.cbSize = sizeof(MONITORINFO);
if(GetMonitorInfo(hMonitor2,&mInfo2) == TRUE)
{
ScreenRect = mInfo.rcMonitor;
}
else
{
ScreenRect.bottom = 0;
ScreenRect.left = 0;
ScreenRect.right = 0;
ScreenRect.top = 0;
nRet = -1;
}
}
return nRet;
*/
return 1;
}
///////////////////////////////////////////////////
// full screen
void CBSWndContainer::SetFullScreen(BOOL bFlag)
{
if(bFlag==m_bFullScreen) return;
if( bFlag )
{//全屏
// //得到显示器分辨率
// int cx=GetSystemMetrics(SM_CXSCREEN);
// int cy=GetSystemMetrics(SM_CYSCREEN);
//
// //保存位置信息
// GetWindowPlacement(&_temppl);
// //修改风格
// ModifyStyle(WS_CHILD,WS_POPUP);
// //修改父窗口
// _tempparent=SetParent(NULL);
// _tempparent->ShowWindow(SW_HIDE);
//移动窗口
/* MoveWindow(0,0,cx,cy);*/
ModifyStyle(WS_CHILD,WS_POPUP);
//修改父窗口
// _tempparent=SetParent(NULL);
// _tempparent->ShowWindow(SW_HIDE);
GetWindowPlacement(&m_OldWndPlacement);
CRect WindowRect;
GetWindowRect(&WindowRect);
CRect ClientRect;
RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery, &ClientRect);
ClientToScreen(&ClientRect);
// 获取屏幕的分辨率
CRect screenRect;
GetCurrentScreenMonitorRect(m_hWnd, screenRect);
int nFullWidth = screenRect.Width(); //GetSystemMetrics(SM_CXSCREEN);
int nFullHeight = screenRect.Height(); //GetSystemMetrics(SM_CYSCREEN);
//将除控制条外的客户区全屏显示到从(0,0)到(nFullWidth, nFullHeight)区域, 将(0,0)和(nFullWidth, nFullHeight)两个点外扩充原窗口和除控制条之外的 客户区位置间的差值, 就得到全屏显示的窗口位置
m_FullScreenRect.left= WindowRect.left - ClientRect.left + screenRect.left;
m_FullScreenRect.top = WindowRect.top - ClientRect.top + screenRect.top;
m_FullScreenRect.right = m_FullScreenRect.left + WindowRect.right - ClientRect.right + nFullWidth;//::GetSystemMetrics(SM_CXSCREEN);
m_FullScreenRect.bottom = m_FullScreenRect.top + WindowRect.bottom - ClientRect.bottom + nFullHeight;//::GetSystemMetrics(SM_CYSCREEN);
m_bFullScreen=TRUE; // 设置全屏显示标志为 TRUE
// 进入全屏显示状态
WINDOWPLACEMENT wndpl;
wndpl.length=sizeof(WINDOWPLACEMENT);
wndpl.flags=0;
wndpl.showCmd=SW_SHOWNORMAL;
wndpl.rcNormalPosition= m_FullScreenRect;
_tempparent=SetParent(NULL);
_tempparent->ShowWindow(SW_HIDE);
SetWindowPlacement(&wndpl);
// SetWindowPos(&wndTopMost,0,0,cx,cy,NULL);
}
else
{//还原
//还原父窗口
// _tempparent->ShowWindow(SW_SHOW);
// SetParent(_tempparent);
// //还原风格
// ModifyStyle(WS_POPUP,WS_CHILD);
// //还原位置
// SetWindowPlacement(&_temppl);
_tempparent->ShowWindow(SW_SHOW);
SetParent(_tempparent);
//还原风格
ModifyStyle(WS_POPUP,WS_CHILD);
SetWindowPlacement(&m_OldWndPlacement);
}
m_bFullScreen=bFlag;
Invalidate();
}
BOOL CBSWndContainer::GetFullScreen()
{
return m_bFullScreen;
}
///////////////////////////////////////////////////
// multiscreen
void CBSWndContainer::SetMultiScreen(BOOL bFlag)
{
if(m_bMultiScreen==bFlag) return;
m_bMultiScreen=bFlag;
Invalidate();
}
BOOL CBSWndContainer::GetMultiScreen()
{
return m_bMultiScreen;
}
//////////////////////////////////////////////////
// autoadjustpos
void CBSWndContainer::SetAutoAdjustPos(BOOL bFlag)
{
if(m_bAutoAdjustPos==bFlag) return;
m_bAutoAdjustPos=bFlag;
Invalidate();
}
BOOL CBSWndContainer::GetAutoAdjustPos()
{
return m_bAutoAdjustPos;
}
/////////////////////////////////////////////////
//开启预览
void CBSWndContainer::SetCurWndPlayState(BOOL bFlag)
{
if(GetCurWndPlayState() == bFlag)
return;
if(bFlag == TRUE)
// pCMainDlg->DlgPlaywin.StartPlay();
;
else
pCMainDlg->DlgPlaywin.StopPlay();
}
BOOL CBSWndContainer::GetCurWndPlayState()
{
return pCMainDlg->DlgPlaywin.GetCurWndPlayState();
}
/////////////////////////////////////////////////
//开启录像
void CBSWndContainer::SetCurWndRecordState(BOOL bFlag)
{
if(GetCurWndPlayState() == bFlag)
return;
if(bFlag == TRUE)
pCMainDlg->DlgPlaywin.StartRecord();
else
pCMainDlg->DlgPlaywin.StopRecord();
}
BOOL CBSWndContainer::GetCurWndRecordState()
{
return pCMainDlg->DlgPlaywin.GetCurWndRecordState();
}
//////////////////////////////////////////////////
//抓拍图像
void CBSWndContainer::Capture()
{
pCMainDlg->DlgPlaywin.CapturePic();
}
//////////////////////////////////////////////////
// draw active page
void CBSWndContainer::SetDrawActivePage(BOOL bFlag,COLORREF clrTopLeft,COLORREF clrBottomRight)
{
if(m_bDrawActive==bFlag) return;
if(bFlag)
{
m_clrTopLeft=clrTopLeft;
m_clrBottomRight=clrBottomRight;
}
m_bDrawActive=bFlag;
DrawActivePage(bFlag);
}
BOOL CBSWndContainer::GetDrawActivePage()
{
return m_bDrawActive;
}
//////////////////////////////////////////////////
// 显示百分比
// 40 <= nPortion <=100
void CBSWndContainer::SetShowPortion(int nPortion)
{
if(m_nShowPortion==nPortion) return;
if(m_nShowPortion<40) m_nShowPortion=40;
if(m_nShowPortion>100) m_nShowPortion=100;
m_nShowPortion=nPortion;
Invalidate();
}
int CBSWndContainer::GetShowPortion()
{
return m_nShowPortion;
}
///////////////////////////////////////////////////
// clean the no useful page in the container,
// return the page count.
int CBSWndContainer::UpdateList()
{
POSITION posPrev;
for(POSITION pos=m_PageList.GetHeadPosition();pos!=NULL;)
{
posPrev=pos;
CWnd *p=m_PageList.GetNext(pos);
if(!IsWindow(p->m_hWnd))
m_PageList.RemoveAt(posPrev);
}
return m_PageList.GetCount();
}
///////////////////////////////////////////////////
// get a rect by the index of a child
void CBSWndContainer::CalcPageRect(LPRECT lpRect,int nIndex,int nPageCount)
{
if((nPageCount<=0)||(nIndex>=nPageCount))
{
lpRect->left=lpRect->right=lpRect->top=lpRect->bottom=0;
return;
}
//get row count
int nRow=0;
while((nRow)*(nRow)<nPageCount) nRow++;
//get singledlg width and height
int nWidth=(lpRect->right-lpRect->left)/nRow;
int nHeight=(lpRect->bottom-lpRect->top)/nRow;
//get top-left point
CPoint pt;
pt.x=lpRect->left+nWidth*(nIndex%nRow);
pt.y=lpRect->top+nHeight*(nIndex/nRow);
//set rect return back
lpRect->left=pt.x;
lpRect->top=pt.y;
lpRect->right=lpRect->left+nWidth;
lpRect->bottom=lpRect->top+nHeight;
}
///////////////////////////////////////////////////
// adjust a rect by defined proportion
void CBSWndContainer::AdjustRect(LPRECT lpRect)
{
int nWidth=lpRect->right-lpRect->left;
int nHeight=lpRect->bottom-lpRect->top;
CPoint pt((lpRect->left+lpRect->right)/2,(lpRect->top+lpRect->bottom)/2);
int nTemp=nWidth*8/11;
if(nTemp>nHeight)
{
nWidth=nHeight*11/8;
}
else if(nTemp<nHeight)
{
nHeight=nTemp;
}
lpRect->left=pt.x-nWidth/2;
lpRect->right=pt.x+nWidth/2;
lpRect->top=pt.y-nHeight/2;
lpRect->bottom=pt.y+nHeight/2;
}
///////////////////////////////////////////////////
// 按比例得到显示区域
void CBSWndContainer::GetShowRect(LPRECT lpRect)
{
if(m_nShowPortion<40) m_nShowPortion=40;
if(m_nShowPortion>100) m_nShowPortion=100;
int nWidth = lpRect->right-lpRect->left;
int nHeight = lpRect->bottom-lpRect->top;
int nNewWidth = (int)(nWidth*m_nShowPortion/100);
int nNewHeight = (int)(nHeight*m_nShowPortion/100);
int ndx = ( nWidth-nNewWidth )/2;
int ndy = ( nHeight-nNewHeight )/2;
lpRect->left = lpRect->left + ndx;
lpRect->top = lpRect->top + ndy;
lpRect->right = lpRect->left + nNewWidth;
lpRect->bottom = lpRect->top + nNewHeight;
}
///////////////////////////////////////////////////
// draw the frame of active page
void CBSWndContainer::DrawActivePage(BOOL bFlag)
{
if( !m_bMultiScreen ||
!m_pActivePage ||
m_PageList.GetCount()<2
) return;
CRect rt;
m_pActivePage->GetWindowRect(&rt);
ScreenToClient(&rt);
rt.InflateRect(1,1);
if(bFlag)
{
CDC *pDC=GetDC();
if(!pDC) return;
// pDC->Draw3dRect(&rt,m_clrTopLeft, m_clrBottomRight);
pDC->Draw3dRect(&rt,RGB(255,0,0), RGB(255,0,0));
ReleaseDC(pDC);
}
else
InvalidateRect(&rt);
}