-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwinctrl.cpp
2081 lines (1578 loc) · 64.8 KB
/
winctrl.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
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
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//------------------------------------------------------------------------------
// File: WinCtrl.cpp
//
// Desc: DirectShow base classes - implements video control interface class.
//
// Copyright (c) 1992-2001 Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
#include <streams.h>
#include <intsafe.h>
#include <checkbmi.h>
// The control interface methods require us to be connected
#define CheckConnected(pin,code) \
{ \
if (pin == NULL) { \
ASSERT(!TEXT("Pin not set")); \
} else if (pin->IsConnected() == FALSE) { \
return (code); \
} \
}
// This checks to see whether the window has a drain. An application can in
// most environments set the owner/parent of windows so that they appear in
// a compound document context (for example). In this case, the application
// would probably like to be told of any keyboard/mouse messages. Therefore
// we pass these messages on untranslated, returning TRUE if we're successful
BOOL WINAPI PossiblyEatMessage(HWND hwndDrain, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (hwndDrain != NULL && !InSendMessage())
{
switch (uMsg)
{
case WM_CHAR:
case WM_DEADCHAR:
case WM_KEYDOWN:
case WM_KEYUP:
case WM_LBUTTONDBLCLK:
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_MBUTTONDBLCLK:
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
case WM_MOUSEACTIVATE:
case WM_MOUSEMOVE:
// If we pass this on we don't get any mouse clicks
//case WM_NCHITTEST:
case WM_NCLBUTTONDBLCLK:
case WM_NCLBUTTONDOWN:
case WM_NCLBUTTONUP:
case WM_NCMBUTTONDBLCLK:
case WM_NCMBUTTONDOWN:
case WM_NCMBUTTONUP:
case WM_NCMOUSEMOVE:
case WM_NCRBUTTONDBLCLK:
case WM_NCRBUTTONDOWN:
case WM_NCRBUTTONUP:
case WM_RBUTTONDBLCLK:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
case WM_SYSCHAR:
case WM_SYSDEADCHAR:
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
DbgLog((LOG_TRACE, 2, TEXT("Forwarding %x to drain")));
PostMessage(hwndDrain, uMsg, wParam, lParam);
return TRUE;
}
}
return FALSE;
}
// This class implements the IVideoWindow control functions (dual interface)
// we support a large number of properties and methods designed to allow the
// client (whether it be an automation controller or a C/C++ application) to
// set and get a number of window related properties such as it's position.
// We also support some methods that duplicate the properties but provide a
// more direct and efficient mechanism as many values may be changed in one
CBaseControlWindow::CBaseControlWindow(
__inout CBaseFilter *pFilter, // Owning filter
__in CCritSec *pInterfaceLock, // Locking object
__in_opt LPCTSTR pName, // Object description
__inout_opt LPUNKNOWN pUnk, // Normal COM ownership
__inout HRESULT *phr) : // OLE return code
CBaseVideoWindow(pName,pUnk),
m_pInterfaceLock(pInterfaceLock),
m_hwndOwner(NULL),
m_hwndDrain(NULL),
m_bAutoShow(TRUE),
m_pFilter(pFilter),
m_bCursorHidden(FALSE),
m_pPin(NULL)
{
ASSERT(m_pFilter);
ASSERT(m_pInterfaceLock);
ASSERT(phr);
m_BorderColour = VIDEO_COLOUR;
}
// Set the title caption on the base window, we don't do any field checking
// as we really don't care what title they intend to have. We can always get
// it back again later with GetWindowText. The only other complication is to
// do the necessary string conversions between ANSI and OLE Unicode strings
STDMETHODIMP CBaseControlWindow::put_Caption(__in BSTR strCaption)
{
CheckPointer((PVOID)strCaption,E_POINTER);
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
#ifdef UNICODE
SetWindowText(m_hwnd, strCaption);
#else
CHAR Caption[CAPTION];
WideCharToMultiByte(CP_ACP,0,strCaption,-1,Caption,CAPTION,NULL,NULL);
SetWindowText(m_hwnd, Caption);
#endif
return NOERROR;
}
// Get the current base window title caption, once again we do no real field
// checking. We allocate a string for the window title to be filled in with
// which ensures the interface doesn't fiddle around with getting memory. A
// BSTR is a normal C string with the length at position (-1), we use the
// WriteBSTR helper function to create the caption to try and avoid OLE32
STDMETHODIMP CBaseControlWindow::get_Caption(__out BSTR *pstrCaption)
{
CheckPointer(pstrCaption,E_POINTER);
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
WCHAR WideCaption[CAPTION];
#ifdef UNICODE
GetWindowText(m_hwnd,WideCaption,CAPTION);
#else
// Convert the ASCII caption to a UNICODE string
TCHAR Caption[CAPTION];
GetWindowText(m_hwnd,Caption,CAPTION);
MultiByteToWideChar(CP_ACP,0,Caption,-1,WideCaption,CAPTION);
#endif
return WriteBSTR(pstrCaption,WideCaption);
}
// Set the window style using GWL_EXSTYLE
STDMETHODIMP CBaseControlWindow::put_WindowStyleEx(long WindowStyleEx)
{
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
// Should we be taking off WS_EX_TOPMOST
if (GetWindowLong(m_hwnd,GWL_EXSTYLE) & WS_EX_TOPMOST) {
if ((WindowStyleEx & WS_EX_TOPMOST) == 0) {
SendMessage(m_hwnd,m_ShowStageTop,(WPARAM) FALSE,(LPARAM) 0);
}
}
// Likewise should we be adding WS_EX_TOPMOST
if (WindowStyleEx & WS_EX_TOPMOST) {
SendMessage(m_hwnd,m_ShowStageTop,(WPARAM) TRUE,(LPARAM) 0);
WindowStyleEx &= (~WS_EX_TOPMOST);
if (WindowStyleEx == 0) return NOERROR;
}
return DoSetWindowStyle(WindowStyleEx,GWL_EXSTYLE);
}
// Gets the current GWL_EXSTYLE base window style
STDMETHODIMP CBaseControlWindow::get_WindowStyleEx(__out long *pWindowStyleEx)
{
CheckPointer(pWindowStyleEx,E_POINTER);
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
return DoGetWindowStyle(pWindowStyleEx,GWL_EXSTYLE);
}
// Set the window style using GWL_STYLE
STDMETHODIMP CBaseControlWindow::put_WindowStyle(long WindowStyle)
{
// These styles cannot be changed dynamically
if ((WindowStyle & WS_DISABLED) ||
(WindowStyle & WS_ICONIC) ||
(WindowStyle & WS_MAXIMIZE) ||
(WindowStyle & WS_MINIMIZE) ||
(WindowStyle & WS_HSCROLL) ||
(WindowStyle & WS_VSCROLL)) {
return E_INVALIDARG;
}
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
return DoSetWindowStyle(WindowStyle,GWL_STYLE);
}
// Get the current GWL_STYLE base window style
STDMETHODIMP CBaseControlWindow::get_WindowStyle(__out long *pWindowStyle)
{
CheckPointer(pWindowStyle,E_POINTER);
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
return DoGetWindowStyle(pWindowStyle,GWL_STYLE);
}
// Change the base window style or the extended styles depending on whether
// WindowLong is GWL_STYLE or GWL_EXSTYLE. We must call SetWindowPos to have
// the window displayed in it's new style after the change which is a little
// tricky if the window is not currently visible as we realise it offscreen.
// In most cases the client will call get_WindowStyle before they call this
// and then AND and OR in extra bit settings according to the requirements
HRESULT CBaseControlWindow::DoSetWindowStyle(long Style,long WindowLong)
{
RECT WindowRect;
// Get the window's visibility before setting the style
BOOL bVisible = IsWindowVisible(m_hwnd);
EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
// Set the new style flags for the window
SetWindowLong(m_hwnd,WindowLong,Style);
UINT WindowFlags = SWP_SHOWWINDOW | SWP_FRAMECHANGED | SWP_NOACTIVATE;
WindowFlags |= SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE;
// Show the window again in the current position
if (bVisible == TRUE) {
SetWindowPos(m_hwnd, // Base window handle
HWND_TOP, // Just a place holder
0,0,0,0, // Leave size and position
WindowFlags); // Just draw it again
return NOERROR;
}
// Move the window offscreen so the user doesn't see the changes
MoveWindow((HWND) m_hwnd, // Base window handle
GetSystemMetrics(SM_CXSCREEN), // Current desktop width
GetSystemMetrics(SM_CYSCREEN), // Likewise it's height
WIDTH(&WindowRect), // Use the same width
HEIGHT(&WindowRect), // Keep height same to
TRUE); // May as well repaint
// Now show the previously hidden window
SetWindowPos(m_hwnd, // Base window handle
HWND_TOP, // Just a place holder
0,0,0,0, // Leave size and position
WindowFlags); // Just draw it again
ShowWindow(m_hwnd,SW_HIDE);
if (GetParent(m_hwnd)) {
MapWindowPoints(HWND_DESKTOP, GetParent(m_hwnd), (LPPOINT)&WindowRect, 2);
}
MoveWindow((HWND) m_hwnd, // Base window handle
WindowRect.left, // Existing x coordinate
WindowRect.top, // Existing y coordinate
WIDTH(&WindowRect), // Use the same width
HEIGHT(&WindowRect), // Keep height same to
TRUE); // May as well repaint
return NOERROR;
}
// Get the current base window style (either GWL_STYLE or GWL_EXSTYLE)
HRESULT CBaseControlWindow::DoGetWindowStyle(__out long *pStyle,long WindowLong)
{
*pStyle = GetWindowLong(m_hwnd,WindowLong);
return NOERROR;
}
// Change the visibility of the base window, this takes the same parameters
// as the ShowWindow Win32 API does, so the client can have the window hidden
// or shown, minimised to an icon, or maximised to play in full screen mode
// We pass the request on to the base window to actually make the change
STDMETHODIMP CBaseControlWindow::put_WindowState(long WindowState)
{
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
DoShowWindow(WindowState);
return NOERROR;
}
// Get the current window state, this function returns a subset of the SW bit
// settings available in ShowWindow, if the window is visible then SW_SHOW is
// set, if it is hidden then the SW_HIDDEN is set, if it is either minimised
// or maximised then the SW_MINIMIZE or SW_MAXIMIZE is set respectively. The
// other SW bit settings are really set commands not readable output values
STDMETHODIMP CBaseControlWindow::get_WindowState(__out long *pWindowState)
{
CheckPointer(pWindowState,E_POINTER);
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
ASSERT(pWindowState);
*pWindowState = FALSE;
// Is the window visible, a window is termed visible if it is somewhere on
// the current desktop even if it is completely obscured by other windows
// so the flag is a style for each window set with the WS_VISIBLE bit
if (IsWindowVisible(m_hwnd) == TRUE) {
// Is the base window iconic
if (IsIconic(m_hwnd) == TRUE) {
*pWindowState |= SW_MINIMIZE;
}
// Has the window been maximised
else if (IsZoomed(m_hwnd) == TRUE) {
*pWindowState |= SW_MAXIMIZE;
}
// Window is normal
else {
*pWindowState |= SW_SHOW;
}
} else {
*pWindowState |= SW_HIDE;
}
return NOERROR;
}
// This makes sure that any palette we realise in the base window (through a
// media type or through the overlay interface) is done in the background and
// is therefore mapped to existing device entries rather than taking it over
// as it will do when we this window gets the keyboard focus. An application
// uses this to make sure it doesn't have it's palette removed by the window
STDMETHODIMP CBaseControlWindow::put_BackgroundPalette(long BackgroundPalette)
{
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
CAutoLock cWindowLock(&m_WindowLock);
// Check this is a valid automation boolean type
if (BackgroundPalette != OATRUE) {
if (BackgroundPalette != OAFALSE) {
return E_INVALIDARG;
}
}
// Make sure the window realises any palette it has again
m_bBackground = (BackgroundPalette == OATRUE ? TRUE : FALSE);
PostMessage(m_hwnd,m_RealizePalette,0,0);
PaintWindow(FALSE);
return NOERROR;
}
// This returns the current background realisation setting
STDMETHODIMP
CBaseControlWindow::get_BackgroundPalette(__out long *pBackgroundPalette)
{
CheckPointer(pBackgroundPalette,E_POINTER);
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
CAutoLock cWindowLock(&m_WindowLock);
// Get the current background palette setting
*pBackgroundPalette = (m_bBackground == TRUE ? OATRUE : OAFALSE);
return NOERROR;
}
// Change the visibility of the base window
STDMETHODIMP CBaseControlWindow::put_Visible(long Visible)
{
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
// Check this is a valid automation boolean type
if (Visible != OATRUE) {
if (Visible != OAFALSE) {
return E_INVALIDARG;
}
}
// Convert the boolean visibility into SW_SHOW and SW_HIDE
INT Mode = (Visible == OATRUE ? SW_SHOWNORMAL : SW_HIDE);
DoShowWindow(Mode);
return NOERROR;
}
// Return OATRUE if the window is currently visible otherwise OAFALSE
STDMETHODIMP CBaseControlWindow::get_Visible(__out long *pVisible)
{
CheckPointer(pVisible,E_POINTER);
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
// See if the base window has a WS_VISIBLE style - this will return TRUE
// even if the window is completely obscured by other desktop windows, we
// return FALSE if the window is not showing because of earlier calls
BOOL Mode = IsWindowVisible(m_hwnd);
*pVisible = (Mode == TRUE ? OATRUE : OAFALSE);
return NOERROR;
}
// Change the left position of the base window. This keeps the window width
// and height properties the same so it effectively shunts the window left or
// right accordingly - there is the Width property to change that dimension
STDMETHODIMP CBaseControlWindow::put_Left(long Left)
{
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
BOOL bSuccess;
RECT WindowRect;
// Get the current window position in a RECT
EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
if (GetParent(m_hwnd)) {
MapWindowPoints(HWND_DESKTOP, GetParent(m_hwnd), (LPPOINT)&WindowRect, 2);
}
// Adjust the coordinates ready for SetWindowPos, the window rectangle we
// get back from GetWindowRect is in left,top,right and bottom while the
// coordinates SetWindowPos wants are left,top,width and height values
WindowRect.bottom = WindowRect.bottom - WindowRect.top;
WindowRect.right = WindowRect.right - WindowRect.left;
UINT WindowFlags = SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE;
bSuccess = SetWindowPos(m_hwnd, // Window handle
HWND_TOP, // Put it at the top
Left, // New left position
WindowRect.top, // Leave top alone
WindowRect.right, // The WIDTH (not right)
WindowRect.bottom, // The HEIGHT (not bottom)
WindowFlags); // Show window options
if (bSuccess == FALSE) {
return E_INVALIDARG;
}
return NOERROR;
}
// Return the current base window left position
STDMETHODIMP CBaseControlWindow::get_Left(__out long *pLeft)
{
CheckPointer(pLeft,E_POINTER);
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
RECT WindowRect;
EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
*pLeft = WindowRect.left;
return NOERROR;
}
// Change the current width of the base window. This property complements the
// left position property so we must keep the left edge constant and expand or
// contract to the right, the alternative would be to change the left edge so
// keeping the right edge constant but this is maybe a little more intuitive
STDMETHODIMP CBaseControlWindow::put_Width(long Width)
{
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
BOOL bSuccess;
RECT WindowRect;
// Adjust the coordinates ready for SetWindowPos, the window rectangle we
// get back from GetWindowRect is in left,top,right and bottom while the
// coordinates SetWindowPos wants are left,top,width and height values
EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
if (GetParent(m_hwnd)) {
MapWindowPoints(HWND_DESKTOP, GetParent(m_hwnd), (LPPOINT)&WindowRect, 2);
}
WindowRect.bottom = WindowRect.bottom - WindowRect.top;
UINT WindowFlags = SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE;
// This seems to have a bug in that calling SetWindowPos on a window with
// just the width changing causes it to ignore the width that you pass in
// and sets it to a mimimum value of 110 pixels wide (Windows NT 3.51)
bSuccess = SetWindowPos(m_hwnd, // Window handle
HWND_TOP, // Put it at the top
WindowRect.left, // Leave left alone
WindowRect.top, // Leave top alone
Width, // New WIDTH dimension
WindowRect.bottom, // The HEIGHT (not bottom)
WindowFlags); // Show window options
if (bSuccess == FALSE) {
return E_INVALIDARG;
}
return NOERROR;
}
// Return the current base window width
STDMETHODIMP CBaseControlWindow::get_Width(__out long *pWidth)
{
CheckPointer(pWidth,E_POINTER);
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
RECT WindowRect;
EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
*pWidth = WindowRect.right - WindowRect.left;
return NOERROR;
}
// This allows the client program to change the top position for the window in
// the same way that changing the left position does not affect the width of
// the image so changing the top position does not affect the window height
STDMETHODIMP CBaseControlWindow::put_Top(long Top)
{
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
BOOL bSuccess;
RECT WindowRect;
// Get the current window position in a RECT
EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
if (GetParent(m_hwnd)) {
MapWindowPoints(HWND_DESKTOP, GetParent(m_hwnd), (LPPOINT)&WindowRect, 2);
}
// Adjust the coordinates ready for SetWindowPos, the window rectangle we
// get back from GetWindowRect is in left,top,right and bottom while the
// coordinates SetWindowPos wants are left,top,width and height values
WindowRect.bottom = WindowRect.bottom - WindowRect.top;
WindowRect.right = WindowRect.right - WindowRect.left;
UINT WindowFlags = SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE;
bSuccess = SetWindowPos(m_hwnd, // Window handle
HWND_TOP, // Put it at the top
WindowRect.left, // Leave left alone
Top, // New top position
WindowRect.right, // The WIDTH (not right)
WindowRect.bottom, // The HEIGHT (not bottom)
WindowFlags); // Show window flags
if (bSuccess == FALSE) {
return E_INVALIDARG;
}
return NOERROR;
}
// Return the current base window top position
STDMETHODIMP CBaseControlWindow::get_Top(long *pTop)
{
CheckPointer(pTop,E_POINTER);
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
RECT WindowRect;
EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
*pTop = WindowRect.top;
return NOERROR;
}
// Change the height of the window, this complements the top property so when
// we change this we must keep the top position for the base window, as said
// before we could keep the bottom and grow upwards although this is perhaps
// a little more intuitive since we already have a top position property
STDMETHODIMP CBaseControlWindow::put_Height(long Height)
{
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
BOOL bSuccess;
RECT WindowRect;
// Adjust the coordinates ready for SetWindowPos, the window rectangle we
// get back from GetWindowRect is in left,top,right and bottom while the
// coordinates SetWindowPos wants are left,top,width and height values
EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
if (GetParent(m_hwnd)) {
MapWindowPoints(HWND_DESKTOP, GetParent(m_hwnd), (LPPOINT)&WindowRect, 2);
}
WindowRect.right = WindowRect.right - WindowRect.left;
UINT WindowFlags = SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE;
bSuccess = SetWindowPos(m_hwnd, // Window handle
HWND_TOP, // Put it at the top
WindowRect.left, // Leave left alone
WindowRect.top, // Leave top alone
WindowRect.right, // The WIDTH (not right)
Height, // New height dimension
WindowFlags); // Show window flags
if (bSuccess == FALSE) {
return E_INVALIDARG;
}
return NOERROR;
}
// Return the current base window height
STDMETHODIMP CBaseControlWindow::get_Height(__out long *pHeight)
{
CheckPointer(pHeight,E_POINTER);
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
RECT WindowRect;
EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
*pHeight = WindowRect.bottom - WindowRect.top;
return NOERROR;
}
// This can be called to change the owning window. Setting the owner is done
// through this function, however to make the window a true child window the
// style must also be set to WS_CHILD. After resetting the owner to NULL an
// application should also set the style to WS_OVERLAPPED | WS_CLIPCHILDREN.
// We cannot lock the object here because the SetParent causes an interthread
// SendMessage to the owner window. If they are in GetState we will sit here
// incomplete with the critical section locked therefore blocking out source
// filter threads from accessing us. Because the source thread can't enter us
// it can't get buffers or call EndOfStream so the GetState will not complete
STDMETHODIMP CBaseControlWindow::put_Owner(OAHWND Owner)
{
// Check we are connected otherwise reject the call
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
m_hwndOwner = (HWND) Owner;
HWND hwndParent = m_hwndOwner;
// Add or remove WS_CHILD as appropriate
LONG Style = GetWindowLong(m_hwnd,GWL_STYLE);
if (Owner == NULL) {
Style &= (~WS_CHILD);
} else {
Style |= (WS_CHILD);
}
SetWindowLong(m_hwnd,GWL_STYLE,Style);
// Don't call this with the filter locked
SetParent(m_hwnd,hwndParent);
PaintWindow(TRUE);
NOTE1("Changed parent %lx",hwndParent);
return NOERROR;
}
// This complements the put_Owner to get the current owning window property
// we always return NOERROR although the returned window handle may be NULL
// to indicate no owning window (the desktop window doesn't qualify as one)
// If an application sets the owner we call SetParent, however that returns
// NULL until the WS_CHILD bit is set on, so we store the owner internally
STDMETHODIMP CBaseControlWindow::get_Owner(__out OAHWND *Owner)
{
CheckPointer(Owner,E_POINTER);
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
*Owner = (OAHWND) m_hwndOwner;
return NOERROR;
}
// And renderer supporting IVideoWindow may have an HWND set who will get any
// keyboard and mouse messages we receive posted on to them. This is separate
// from setting an owning window. By separating the two, applications may get
// messages sent on even when they have set no owner (perhaps it's maximised)
STDMETHODIMP CBaseControlWindow::put_MessageDrain(OAHWND Drain)
{
// Check we are connected otherwise reject the call
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
m_hwndDrain = (HWND) Drain;
return NOERROR;
}
// Return the current message drain
STDMETHODIMP CBaseControlWindow::get_MessageDrain(__out OAHWND *Drain)
{
CheckPointer(Drain,E_POINTER);
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
*Drain = (OAHWND) m_hwndDrain;
return NOERROR;
}
// This is called by the filter graph to inform us of a message we should know
// is being sent to our owning window. We have this because as a child window
// we do not get certain messages that are only sent to top level windows. We
// must see the palette changed/changing/query messages so that we know if we
// have the foreground palette or not. We pass the message on to our window
// using SendMessage - this will cause an interthread send message to occur
STDMETHODIMP
CBaseControlWindow::NotifyOwnerMessage(OAHWND hwnd, // Window handle
long uMsg, // Message ID
LONG_PTR wParam, // Parameters
LONG_PTR lParam) // for message
{
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
// Only interested in these Windows messages
switch (uMsg) {
case WM_SYSCOLORCHANGE:
case WM_PALETTECHANGED:
case WM_PALETTEISCHANGING:
case WM_QUERYNEWPALETTE:
case WM_DEVMODECHANGE:
case WM_DISPLAYCHANGE:
case WM_ACTIVATEAPP:
// If we do not have an owner then ignore
if (m_hwndOwner == NULL) {
return NOERROR;
}
SendMessage(m_hwnd,uMsg,(WPARAM)wParam,(LPARAM)lParam);
break;
// do NOT fwd WM_MOVE. the parameters are the location of the parent
// window, NOT what the renderer should be looking at. But we need
// to make sure the overlay is moved with the parent window, so we
// do this.
case WM_MOVE:
PostMessage(m_hwnd,WM_PAINT,0,0);
break;
}
return NOERROR;
}
// Allow an application to have us set the base window in the foreground. We
// have this because it is difficult for one thread to do do this to a window
// owned by another thread. We ask the base window class to do the real work
STDMETHODIMP CBaseControlWindow::SetWindowForeground(long Focus)
{
// Check this is a valid automation boolean type
if (Focus != OATRUE) {
if (Focus != OAFALSE) {
return E_INVALIDARG;
}
}
// We shouldn't lock as this sends a message
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
BOOL bFocus = (Focus == OATRUE ? TRUE : FALSE);
DoSetWindowForeground(bFocus);
return NOERROR;
}
// This allows a client to set the complete window size and position in one
// atomic operation. The same affect can be had by changing each dimension
// in turn through their individual properties although some flashing will
// occur as each of them gets updated (they are better set at design time)
STDMETHODIMP
CBaseControlWindow::SetWindowPosition(long Left,long Top,long Width,long Height)
{
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
BOOL bSuccess;
// Set the new size and position
UINT WindowFlags = SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE;
ASSERT(IsWindow(m_hwnd));
bSuccess = SetWindowPos(m_hwnd, // Window handle
HWND_TOP, // Put it at the top
Left, // Left position
Top, // Top position
Width, // Window width
Height, // Window height
WindowFlags); // Show window flags
ASSERT(bSuccess);
#ifdef DEBUG
DbgLog((LOG_TRACE, 1, TEXT("SWP failed error %d"), GetLastError()));
#endif
if (bSuccess == FALSE) {
return E_INVALIDARG;
}
return NOERROR;
}
// This complements the SetWindowPosition to return the current window place
// in device coordinates. As before the same information can be retrived by
// calling the property get functions individually but this is atomic and is
// therefore more suitable to a live environment rather than design time
STDMETHODIMP
CBaseControlWindow::GetWindowPosition(__out long *pLeft,__out long *pTop,__out long *pWidth,__out long *pHeight)
{
// Should check the pointers are not NULL
CheckPointer(pLeft,E_POINTER);
CheckPointer(pTop,E_POINTER);
CheckPointer(pWidth,E_POINTER);
CheckPointer(pHeight,E_POINTER);
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
RECT WindowRect;
// Get the current window coordinates
EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
// Convert the RECT into left,top,width and height values
*pLeft = WindowRect.left;
*pTop = WindowRect.top;
*pWidth = WindowRect.right - WindowRect.left;
*pHeight = WindowRect.bottom - WindowRect.top;
return NOERROR;
}
// When a window is maximised or iconic calling GetWindowPosition will return
// the current window position (likewise for the properties). However if the
// restored size (ie the size we'll return to when normally shown) is needed
// then this should be used. When in a normal position (neither iconic nor
// maximised) then this returns the same coordinates as GetWindowPosition
STDMETHODIMP
CBaseControlWindow::GetRestorePosition(__out long *pLeft,__out long *pTop,__out long *pWidth,__out long *pHeight)
{
// Should check the pointers are not NULL
CheckPointer(pLeft,E_POINTER);
CheckPointer(pTop,E_POINTER);
CheckPointer(pWidth,E_POINTER);
CheckPointer(pHeight,E_POINTER);
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
// Use GetWindowPlacement to find the restore position
WINDOWPLACEMENT Place;
Place.length = sizeof(WINDOWPLACEMENT);
EXECUTE_ASSERT(GetWindowPlacement(m_hwnd,&Place));
RECT WorkArea;
// We must take into account any task bar present
if (SystemParametersInfo(SPI_GETWORKAREA,0,&WorkArea,FALSE) == TRUE) {
if (GetParent(m_hwnd) == NULL) {
Place.rcNormalPosition.top += WorkArea.top;
Place.rcNormalPosition.bottom += WorkArea.top;
Place.rcNormalPosition.left += WorkArea.left;
Place.rcNormalPosition.right += WorkArea.left;
}
}
// Convert the RECT into left,top,width and height values
*pLeft = Place.rcNormalPosition.left;
*pTop = Place.rcNormalPosition.top;
*pWidth = Place.rcNormalPosition.right - Place.rcNormalPosition.left;
*pHeight = Place.rcNormalPosition.bottom - Place.rcNormalPosition.top;
return NOERROR;
}
// Return the current border colour, if we are playing something to a subset
// of the base window display there is an outside area exposed. The default
// action is to paint this colour in the Windows background colour (defined
// as value COLOR_WINDOW) We reset to this default when we're disconnected
STDMETHODIMP CBaseControlWindow::get_BorderColor(__out long *Color)
{
CheckPointer(Color,E_POINTER);
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
*Color = (long) m_BorderColour;
return NOERROR;
}
// This can be called to set the current border colour
STDMETHODIMP CBaseControlWindow::put_BorderColor(long Color)
{
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
// Have the window repainted with the new border colour
m_BorderColour = (COLORREF) Color;
PaintWindow(TRUE);
return NOERROR;
}
// Delegate fullscreen handling to plug in distributor
STDMETHODIMP CBaseControlWindow::get_FullScreenMode(__out long *FullScreenMode)
{
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
CheckPointer(FullScreenMode,E_POINTER);
return E_NOTIMPL;
}
// Delegate fullscreen handling to plug in distributor
STDMETHODIMP CBaseControlWindow::put_FullScreenMode(long FullScreenMode)
{
return E_NOTIMPL;
}
// This sets the auto show property, this property causes the base window to
// be displayed whenever we change state. This allows an application to have
// to do nothing to have the window appear but still allow them to change the
// default behaviour if for example they want to keep it hidden for longer
STDMETHODIMP CBaseControlWindow::put_AutoShow(long AutoShow)
{
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
// Check this is a valid automation boolean type
if (AutoShow != OATRUE) {
if (AutoShow != OAFALSE) {
return E_INVALIDARG;
}
}
m_bAutoShow = (AutoShow == OATRUE ? TRUE : FALSE);
return NOERROR;
}
// This can be called to get the current auto show flag. The flag is updated
// when we connect and disconnect and through this interface all of which are
// controlled and serialised by means of the main renderer critical section
STDMETHODIMP CBaseControlWindow::get_AutoShow(__out long *AutoShow)
{
CheckPointer(AutoShow,E_POINTER);
CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
*AutoShow = (m_bAutoShow == TRUE ? OATRUE : OAFALSE);
return NOERROR;
}