-
Notifications
You must be signed in to change notification settings - Fork 3
/
listing35.html
executable file
·1162 lines (949 loc) · 40 KB
/
listing35.html
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<!-- BEGIN META TAG INFO -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="home" href="http://developer.apple.com/">
<link rel="find" href="http://developer.apple.com/search/">
<link rel="stylesheet" type="text/css" href="../../documentation/css/adcstyle.css" title="fonts">
<script language="JavaScript" src="../../documentation/js/adc.js" type="text/javascript"></script>
<!-- END META TAG INFO -->
<!-- BEGIN TITLE -->
<title>MakeEffectMovie - /Start Code/Common Files/WinFramework.c</title>
<!-- END TITLE -->
<script language="JavaScript">
function JumpToNewPage() {
window.location=document.scpopupmenu.gotop.value;
return true;
}
</script>
</head>
<!-- BEGIN BODY OPEN -->
<body>
<!--END BODY OPEN -->
<!-- START CENTER OPEN -->
<center>
<!-- END CENTER OPEN -->
<!-- BEGIN LOGO AND SEARCH -->
<!--#include virtual="/includes/adcnavbar"-->
<!-- END LOGO AND SEARCH -->
<!-- START BREADCRUMB -->
<div id="breadcrumb">
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td scope="row"><img width="340" height="10" src="images/1dot.gif" alt=""></td>
<td><img width="340" height="10" src="images/1dot.gif" alt=""></td>
</tr>
<tr valign="middle">
<td align="left" colspan="2">
<a href="http://developer.apple.com/">ADC Home</a> > <a href="../../referencelibrary/index.html">Reference Library</a> > <a href="../../samplecode/index.html">Sample Code</a> > <a href="../../samplecode/QuickTime/index.html">QuickTime</a> > <a href="../../samplecode/QuickTime/idxMovieCreation-date.html">Movie Creation</a> > <A HREF="javascript:location.replace('index.html');">MakeEffectMovie</A> >
</td>
</tr>
<tr>
<td colspan="2" scope="row"><img width="680" height="35" src="images/1dot.gif" alt=""></td>
</tr>
</table>
</div>
<!-- END BREADCRUMB -->
<!-- START MAIN CONTENT -->
<!-- START TITLE GRAPHIC AND INTRO-->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td><h1><div id="pagehead">MakeEffectMovie</div></h1></td>
</tr>
</table>
<!-- END TITLE GRAPHIC AND INTRO -->
<!-- START WIDE COLUMN -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td id="scdetails">
<h2>/Start Code/Common Files/WinFramework.c</h2>
<form name="scpopupmenu" onSubmit="return false;" method=post>
<p><strong>View Source Code:</strong>
<select name="gotop" onChange="JumpToNewPage();" style="width:340px"><option selected value="ingnore">Select File</option>
<option value="listing1.html">/Application Files/ComApplication.c</option>
<option value="listing2.html">/Application Files/ComApplication.h</option>
<option value="listing3.html">/Application Files/ComResource.h</option>
<option value="listing4.html">/Clippings/AddEffectsDescription.txt</option>
<option value="listing5.html">/Clippings/AddInputMap.txt</option>
<option value="listing6.html">/Clippings/AddMovieResource.txt</option>
<option value="listing7.html">/Clippings/AddSourceName.txt</option>
<option value="listing8.html">/Clippings/CreateEffectDescription.txt</option>
<option value="listing9.html">/Clippings/CreateEffectsTrack.txt</option>
<option value="listing10.html">/Clippings/CreateInputMap.txt</option>
<option value="listing11.html">/Clippings/GetWhatKindOfEffect.txt</option>
<option value="listing12.html">/Clippings/SelectAnEffect.txt</option>
<option value="listing13.html">/Common Files/ComFramework.c</option>
<option value="listing14.html">/Common Files/ComFramework.h</option>
<option value="listing15.html">/Common Files/MacFramework.c</option>
<option value="listing16.html">/Common Files/MacFramework.h</option>
<option value="listing17.html">/Common Files/MacPrefix.h</option>
<option value="listing18.html">/Common Files/QTUtilities.c</option>
<option value="listing19.html">/Common Files/QTUtilities.h</option>
<option value="listing20.html">/Common Files/WinFramework.c</option>
<option value="listing21.html">/Common Files/WinFramework.h</option>
<option value="listing22.html">/Common Files/WinPrefix.h</option>
<option value="listing23.html">/Completed Lab/MakeEffectMovie.c</option>
<option value="listing24.html">/Completed Lab/MakeEffectMovie.h</option>
<option value="listing25.html">/Start Code/Application Files/ComApplication.c</option>
<option value="listing26.html">/Start Code/Application Files/ComApplication.h</option>
<option value="listing27.html">/Start Code/Application Files/ComResource.h</option>
<option value="listing28.html">/Start Code/Common Files/ComFramework.c</option>
<option value="listing29.html">/Start Code/Common Files/ComFramework.h</option>
<option value="listing30.html">/Start Code/Common Files/MacFramework.c</option>
<option value="listing31.html">/Start Code/Common Files/MacFramework.h</option>
<option value="listing32.html">/Start Code/Common Files/MacPrefix.h</option>
<option value="listing33.html">/Start Code/Common Files/QTUtilities.c</option>
<option value="listing34.html">/Start Code/Common Files/QTUtilities.h</option>
<option value="listing35.html">/Start Code/Common Files/WinFramework.c</option>
<option value="listing36.html">/Start Code/Common Files/WinFramework.h</option>
<option value="listing37.html">/Start Code/Common Files/WinPrefix.h</option>
<option value="listing38.html">/Start Code/MakeEffectMovie.c</option>
<option value="listing39.html">/Start Code/MakeEffectMovie.h</option></select>
</p>
</form>
<p><strong><a href="MakeEffectMovie.zip">Download Sample</a></strong> (“MakeEffectMovie.zip”, 2.34M)<BR>
<strong><a href="MakeEffectMovie.dmg">Download Sample</a></strong> (“MakeEffectMovie.dmg”, 2.76M)</p>
<!--
<p><strong><a href="#">Download Sample</a></strong> (“filename.sit”, 500K)</p>
-->
</td>
</tr>
<tr>
<td scope="row"><img width="680" height="10" src="images/1dot.gif" alt=""><br>
<img height="1" width="680" src="images/1dot_919699.gif" alt=""><br>
<img width="680" height="20" src="images/1dot.gif" alt=""></td>
</tr>
<tr>
<td scope="row">
<!--googleon: index -->
<pre class="sourcecodebox">//////////
//
// File: WinFramework.c
//
// Contains: Code for the QuickTime sample code framework that is specific to Windows.
// This code handles windows, menus, events, and other low-level things. Put your
// application-specific code into the file ComApplication.c.
//
// Written by: Tim Monroe
// Based on the QTShell code written by Tim Monroe, which in turn was based on the MDIPlayer
// code written by Brian S. Friedkin (Aug 5, 1996). This current version is now very far removed from
// MDIPlayer.
//
// Copyright: © 1999 by Apple Computer, Inc., all rights reserved.
//
// Change History (most recent first):
//
// <7> 04/03/00 rtm reworked QTFrame_CalcWindowMinMaxInfo; disabled movie window maximize button
// in WM_CREATE message processing (implementing this is left as an exercise...)
// <6> 01/14/00 rtm reworked window-drawing code (WM_PAINT message) to support graphics files
// <5> 01/05/00 rtm minor tweaks to QuickTime initialization in WinMain
// <4> 12/26/99 rtm added WM_LBUTTONDOWN processing to QTFrame_MovieWndProc; minor reorganization
// of QTFrame_MovieWndProc so that myMacEvent and myIsHandled are in scope for
// that message
// <3> 12/16/99 rtm made minor change to QTFrame_MovieWndProc so that QTApp_HandleEvent is called
// even if the window has no movie controller
// <2> 11/29/99 rtm modified "Save changes" dialog box to use Macintosh wordings prompted by move
// to Navigation Services
// <1> 11/05/99 rtm first file; based on earlier sample code
//
//////////
//////////
//
// header files
//
//////////
#include "WinFramework.h"
//////////
//
// global variables
//
//////////
BOOL gShuttingDown = false; // are we shutting down?
BOOL gWeAreSizingWindow = false; // are we resizing a window?
BOOL gWeAreCreatingWindow = false; // are we creating a window?
HANDLE ghInst; // the instance of this application
HWND ghWnd; // the MDI frame window; this window has the menu bar
HWND ghWndMDIClient; // the MDI client window
char gChildName[] = "QTShellChild";
char gMovieType[] = "QuickTime Movie";
short gAppResFile = kInvalidFileRefNum; // file reference number for this application's resource file
FSSpec gAppFSSpec; // file specification for the application itself
char gAppName[20]; // the name of this application
LPSTR gCmdLine; // the command line passed to WinMain
extern Rect gMCResizeBounds; // maximum size for any movie window
//////////
//
// WinMain
// The main function for this application.
//
// Set up the application's execution environment; make sure QuickTime (etc.) is installed,
// then start handling events. If we terminate before reaching the message loop, we should
// return 0.
//
//////////
int CALLBACK WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR theCmdLine, int nCmdShow)
{
HANDLE myAccel;
HWND myWindowFrame;
MSG myMsg;
WNDCLASSEX myWC;
char myFileName[MAX_PATH];
DWORD myLength;
OSErr myErr = noErr;
ghInst = hInstance;
gCmdLine = theCmdLine;
if (hPrevInstance == NULL) {
LoadString(hInstance, IDS_APPNAME, gAppName, sizeof(gAppName));
// register the frame window class
myWC.cbSize = sizeof(WNDCLASSEX);
myWC.style = CS_HREDRAW | CS_VREDRAW;
myWC.lpfnWndProc = (WNDPROC)QTFrame_FrameWndProc;
myWC.cbClsExtra = 0;
myWC.cbWndExtra = 0;
myWC.hInstance = hInstance;
myWC.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPICON));
myWC.hCursor = LoadCursor(NULL, IDC_ARROW);
myWC.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
myWC.lpszMenuName = gAppName;
myWC.lpszClassName = gAppName;
myWC.hIconSm = LoadImage(hInstance, MAKEINTRESOURCE(IDI_APPICON), IMAGE_ICON, 16, 16, 0);
if (!RegisterClassEx(&myWC)) {
if (!RegisterClass((LPWNDCLASS)&myWC.style))
return(0);
}
// register the movie child window class
myWC.cbSize = sizeof(WNDCLASSEX);
myWC.style = 0;
myWC.lpfnWndProc = (WNDPROC)QTFrame_MovieWndProc;
myWC.cbClsExtra = 0;
myWC.cbWndExtra = 0;
myWC.hInstance = hInstance;
myWC.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CHILDICON));
// to avoid having QuickTime VR "fight" with the system over the cursor,
// we set the client area cursor to NULL; this means that for QuickTime
// movies, we'll need to change the cursor to an arrow manually; see the
// handling of the WM_MOUSEMOVE message in QTFrame_MovieWndProc
myWC.hCursor = NULL;
myWC.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
myWC.lpszMenuName = NULL;
myWC.lpszClassName = gChildName;
myWC.hIconSm = LoadImage(hInstance, MAKEINTRESOURCE(IDI_CHILDICON), IMAGE_ICON, 16, 16, 0);
if (!RegisterClassEx(&myWC)) {
if (!RegisterClass((LPWNDCLASS)&myWC.style))
return(0);
}
}
// load accelerators
myAccel = LoadAccelerators(hInstance, gAppName);
// initialize QuickTime Media Layer and QuickTime; alert the user and return 0 if unsuccessful
myErr = InitializeQTML(0L);
if (myErr != noErr) {
MessageBox(NULL, "QuickTime is not installed on this computer. Exiting.", gAppName, MB_OK | MB_APPLMODAL);
return(0);
}
myErr = EnterMovies();
if (myErr != noErr) {
MessageBox(NULL, "Could not initialize QuickTime. Exiting.", gAppName, MB_OK | MB_APPLMODAL);
return(0);
}
// get the application's resource file, if it exists
myLength = GetModuleFileName(NULL, myFileName, MAX_PATH); // NULL means: the current process
if (myLength != 0) {
NativePathNameToFSSpec(myFileName, &gAppFSSpec, kFullNativePath);
gAppResFile = FSpOpenResFile(&gAppFSSpec, fsRdWrPerm);
if (gAppResFile != kInvalidFileRefNum)
UseResFile(gAppResFile);
}
// do any application-specific initialization that must occur before the frame window is created
QTApp_Init(kInitAppPhase_BeforeCreateFrameWindow);
// create the main frame window
myWindowFrame = CreateWindow(gAppName, gAppName, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ghWnd = myWindowFrame;
// make sure we got a frame window
if (myWindowFrame == NULL)
return(0);
// show the window
ShowWindow(myWindowFrame, nCmdShow);
UpdateWindow(myWindowFrame);
// do any application-specific initialization that must occur after the frame window is created
QTApp_Init(kInitAppPhase_AfterCreateFrameWindow);
// get and process events until the user quits
while (GetMessage(&myMsg, NULL, 0, 0)) {
if (!TranslateMDISysAccel(ghWndMDIClient, &myMsg)) {
if (!TranslateAccelerator(myWindowFrame, myAccel, &myMsg)) {
TranslateMessage(&myMsg);
DispatchMessage(&myMsg);
}
}
}
// close the application's resource file, if it was previously opened
if (gAppResFile != kInvalidFileRefNum)
CloseResFile(gAppResFile);
// terminate the QuickTime Media Layer
ExitMovies();
TerminateQTML();
return(myMsg.wParam); // returns the value from PostQuitMessage
}
//////////
//
// QTFrame_FrameWndProc
// The window procedure for the MDI frame window.
//
//////////
LRESULT CALLBACK QTFrame_FrameWndProc (HWND theWnd, UINT theMessage, UINT wParam, LONG lParam)
{
HWND myChild;
switch (theMessage) {
case WM_CREATE: {
CLIENTCREATESTRUCT myClientStruct = {0};
myClientStruct.hWindowMenu = GetSubMenu(GetMenu(theWnd), WINDOWMENU);
myClientStruct.idFirstChild = IDM_WINDOWCHILD;
// create the MDI client filling the client area
ghWndMDIClient = CreateWindow("mdiclient",
NULL,
WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
0, 0, 0, 0,
theWnd,
(HMENU)0xCAC,
ghInst,
(LPVOID)&myClientStruct);
// set initial menu state
QTFrame_AdjustMenus(NULL, GetMenu(theWnd));
if (ghWndMDIClient != NULL)
ShowWindow(ghWndMDIClient, SW_SHOW);
return(0);
}
case WM_ACTIVATE:
// the MDI frame window is being activated or deactivated;
// activate or deactivate any active child window by sending this message to DefMDIChildProc
myChild = (HWND)SendMessage(ghWndMDIClient, WM_MDIGETACTIVE, 0, 0L);
if (IsWindow(myChild))
SendMessage(myChild, WM_ACTIVATE, wParam, lParam);
break;
case WM_COMMAND: {
switch (LOWORD(wParam)) {
case IDM_FILENEW:
case IDM_FILEOPEN:
case IDM_FILECLOSE:
case IDM_EXIT:
QTFrame_HandleFileMenuItem(NULL, LOWORD(wParam));
return(0);
case IDM_FILESAVE:
case IDM_FILESAVEAS:
// save the active child window
myChild = (HWND)SendMessage(ghWndMDIClient, WM_MDIGETACTIVE, 0, 0L);
if (IsWindow(myChild))
SendMessage(myChild, WM_COMMAND, wParam, lParam);
return(0);
case IDM_WINDOWTILE:
SendMessage(ghWndMDIClient, WM_MDITILE, 0, 0L);
return(0);
case IDM_WINDOWCASCADE:
SendMessage(ghWndMDIClient, WM_MDICASCADE, 0, 0L);
return(0);
case IDM_WINDOWICONS:
SendMessage(ghWndMDIClient, WM_MDIICONARRANGE, 0, 0L);
return(0);
case IDM_WINDOWCLOSEALL: {
WindowReference myWindow, myNextWindow;
// walk the window list and destroy any open windows
myWindow = QTFrame_GetFrontMovieWindow();
while (myWindow != NULL) {
myNextWindow = QTFrame_GetNextMovieWindow(myWindow);
SendMessage(myWindow, WM_CLOSE, 0L, 0L);
myWindow = myNextWindow;
}
return(0);
}
case IDM_ABOUT:
QTFrame_ShowAboutBox();
return(0);
default:
// pass this message to the active child window...
myChild = (HWND)SendMessage(ghWndMDIClient, WM_MDIGETACTIVE, 0, 0L);
if (IsWindow(myChild))
SendMessage(myChild, WM_COMMAND, wParam, lParam);
// ...then do any application-specific menu handling, if no movie windows are open...
if (myChild == NULL)
QTApp_HandleMenu((UInt16)LOWORD(wParam));
// ...and then pass it to DefFrameProc
break;
}
break;
}
case WM_OPENDROPPEDFILES:
// open any movie files that were dropped onto the application icon
QTFrame_OpenCommandLineMovies(gCmdLine);
return(0);
case WM_INITMENU:
if (GetMenu(theWnd) == (HMENU)wParam)
return(QTFrame_AdjustMenus((HWND)SendMessage(ghWndMDIClient, WM_MDIGETACTIVE, 0, 0L), (HMENU)wParam));
return(1);
case WM_CLOSE:
// if we're not already in the process of shutting down,
// simulate the selection of the Quit menu command
if (!gShuttingDown) {
SendMessage(ghWnd, WM_COMMAND, IDM_EXIT, 0L);
return(0);
}
break;
case WM_DESTROY:
// do any application-specific shutdown
QTApp_Stop(kStopAppPhase_AfterDestroyWindows);
PostQuitMessage(0);
break;
}
return(DefFrameProc(theWnd, ghWndMDIClient, theMessage, wParam, lParam));
}
//////////
//
// QTFrame_MovieWndProc
// The window procedure for a movie window.
//
//////////
LRESULT CALLBACK QTFrame_MovieWndProc (HWND theWnd, UINT theMessage, UINT wParam, LONG lParam)
{
WPARAM myWidth, myHeight;
MovieController myMC = NULL;
Movie myMovie = NULL;
WindowObject myWindowObject = NULL;
MSG myMsg = {0};
EventRecord myMacEvent;
Boolean myIsHandled = false;
// get the window object, movie, and movie controller for this window
myWindowObject = QTFrame_GetWindowObjectFromWindow(theWnd);
if (myWindowObject != NULL) {
myMC = (**myWindowObject).fController;
myMovie = (**myWindowObject).fMovie;
}
// give the movie controller this message first
if (!gShuttingDown) {
LONG myPoints = GetMessagePos();
myMsg.hwnd = theWnd;
myMsg.message = theMessage;
myMsg.wParam = wParam;
myMsg.lParam = lParam;
myMsg.time = GetMessageTime();
myMsg.pt.x = LOWORD(myPoints);
myMsg.pt.y = HIWORD(myPoints);
// translate a Windows event to a Mac event
WinEventToMacEvent(&myMsg, &myMacEvent);
// let the application-specific code have a chance to intercept the event
myIsHandled = QTApp_HandleEvent(&myMacEvent);
// pass the Mac event to the movie controller, but only if the movie window isn't minimized
if (!myIsHandled)
if (myMC != NULL)
if (!IsIconic(theWnd))
myIsHandled = MCIsPlayerEvent(myMC, (EventRecord *)&myMacEvent);
}
switch (theMessage) {
case WM_CREATE: {
LONG myStyles;
// create a new window object associated with the new window
QTFrame_CreateWindowObject(theWnd);
// disable the maximize button
myStyles = GetWindowLong(theWnd, GWL_STYLE);
myStyles &= ~WS_MAXIMIZEBOX;
SetWindowLong(theWnd, GWL_STYLE, myStyles);
}
break;
case WM_WINDOWPOSCHANGING:
// don't show the window until we have created a movie and
// can therefore properly size the window to contain the movie
if (gWeAreCreatingWindow) {
WINDOWPOS *lpWindowPos = (WINDOWPOS*)lParam;
lpWindowPos->flags &= ~SWP_SHOWWINDOW;
}
break;
case WM_WINDOWPOSCHANGED:
// if a movie window has become minimized, stop the movie
if (IsIconic(theWnd))
StopMovie(myMovie);
break;
case WM_SIZE:
// resize the movie and controller to fit the window
myWidth = LOWORD(lParam);
myHeight = HIWORD(lParam);
// we do NOT want to resize the movie controller if the window is minimized,
// if there is no movie controller, or if we are in the middle of resizing the window
if (!gWeAreSizingWindow && (myMC != NULL) && (wParam != SIZE_MINIMIZED)) {
Rect myRect;
myRect.top = 0;
myRect.left = 0;
myRect.right = myWidth;
myRect.bottom = myHeight;
MCSetControllerBoundsRect(myMC, &myRect);
}
break;
case WM_MOUSEMOVE:
// for QuickTime movies (but NOT for QuickTime VR movies), set the cursor to the arrow cursor
if (myWindowObject != NULL)
if (!(**myWindowObject).fIsQTVRMovie)
SetCursor(LoadCursor(NULL, IDC_ARROW));
break;
case WM_PUMPMOVIE:
// we receive this message only to task the movie
break;
case WM_LBUTTONDOWN:
// do any application-specific mouse-button handling, but only if the message hasn't already been handled
if (!myIsHandled)
QTApp_HandleContentClick(theWnd, &myMacEvent);
break;
case WM_CHAR:
// do any application-specific key press handling
QTApp_HandleKeyPress((char)wParam);
break;
case WM_PAINT: {
// do any application-specific drawing in the window
PAINTSTRUCT myPaintStruct;
BeginPaint(theWnd, &myPaintStruct);
// if the window contains an image, draw it using GraphicsImportDraw
if (myWindowObject != NULL)
if ((**myWindowObject).fGraphicsImporter != NULL)
GraphicsImportDraw((**myWindowObject).fGraphicsImporter);
QTApp_Draw(theWnd, NULL);
EndPaint(theWnd, &myPaintStruct);
}
break;
case WM_MDIACTIVATE:
// activate or deactivate the movie controller in the specified window
QTFrame_ActivateController(theWnd, (HWND)theWnd == (HWND)lParam);
break;
case WM_COMMAND: {
switch (LOWORD(wParam)) {
case IDM_FILESAVE:
case IDM_FILESAVEAS:
QTFrame_HandleFileMenuItem(theWnd, LOWORD(wParam));
break;
case IDM_EDITUNDO:
case IDM_EDITCUT:
case IDM_EDITCOPY:
case IDM_EDITPASTE:
case IDM_EDITCLEAR:
case IDM_EDITSELECTALL:
case IDM_EDITSELECTNONE:
QTFrame_HandleEditMenuItem(theWnd, LOWORD(wParam));
break;
default:
// do any application-specific menu handling
QTApp_HandleMenu((UInt16)LOWORD(wParam));
break;
}
break;
} // case WM_COMMAND
case WM_GETMINMAXINFO:
QTFrame_CalcWindowMinMaxInfo(theWnd, (LPMINMAXINFO)lParam);
return(0);
case WM_CLOSE:
// prepare to close the window, making sure that any changed data is saved or explicitly discarded;
// we can still cancel the window closing here
if (myWindowObject != NULL) {
// if the window's data is "dirty", give the user a chance to save it
if ((**myWindowObject).fIsDirty) {
int myItem;
char myText[256];
UINT myAction;
// get the title of the window
GetWindowText(theWnd, myText, sizeof(myText));
// specify the action
myAction = gShuttingDown ? IDS_SAVEONQUIT : IDS_SAVEONCLOSE;
// display the "Save changes" dialog box
myItem = QTFrame_ShowCautionAlert(theWnd, myAction, MB_ICONEXCLAMATION, MB_YESNOCANCEL, gAppName, myText);
switch (myItem) {
case kSaveChanges:
// save the data in the window
QTFrame_UpdateMovieFile(theWnd);
break;
case kCancelClose:
// do not close the window and do not quit the application
gShuttingDown = false;
return(0);
case kDontSaveChanges:
// discard any unsaved changes (that is, don't do anything)
break;
default:
// unexpected item selected; just return
return(0);
}
}
} // if (myWindowObject != NULL)
// if we got to this point, it's okay to close and destroy the window
SendMessage(ghWndMDIClient, WM_MDIDESTROY, (WPARAM)theWnd, 0L);
break;
case WM_DESTROY:
// when we get this message,
// the window has been removed from the screen and its associated data must be destroyed
if (myWindowObject != NULL)
QTFrame_CloseWindowObject(myWindowObject);
SetWindowLong(theWnd, GWL_USERDATA, 0);
// destroy the port association
DestroyPortAssociation((CGrafPtr)GetHWNDPort(theWnd));
break;
}
return(DefMDIChildProc(theWnd, theMessage, wParam, lParam));
}
//////////
//
// QTFrame_QuitFramework
// Do any framework-specific shut-down.
//
//////////
void QTFrame_QuitFramework (void)
{
// set our global flag to indicate we're shutting down
gShuttingDown = true;
// do application-specific processing that must occur before movie windows are closed
QTApp_Stop(kStopAppPhase_BeforeDestroyWindows);
// close all open movie windows; note that the user can cancel the shutting down
QTFrame_CloseMovieWindows();
// close the frame window, if we're still shutting down
if (gShuttingDown)
SendMessage(ghWnd, WM_CLOSE, 0, 0L);
}
//////////
//
// QTFrame_OpenCommandLineMovies
// Parse the command line when the application first starts up and
// open as movie documents any files specified on the command line.
//
// Based on the routine ParseCmdLinePriv in GraphicImporter.c.
//
//////////
void QTFrame_OpenCommandLineMovies (LPSTR theCmdLine)
{
#pragma unused(theCmdLine)
LPSTR myCmdLine;
FSSpec myFSSpec;
SHFILEINFO myFileInfo;
// get the command line for the current process
myCmdLine = GetCommandLine();
// parse the command line
if (*myCmdLine) {
LPSTR myTempLine;
// the string preceding any white space is the name of the module (that is, the application)
myTempLine = strchr(myCmdLine, ' ');
if (myTempLine) {
myCmdLine = myTempLine; // skip the name of the application
while (*myCmdLine == ' ')
myCmdLine++; // skip spaces to end of string or to first command
while (*myCmdLine != '\0') {
char myFileName[MAX_PATH];
char myTempName[MAX_PATH];
char myBuffName[MAX_PATH];
int myIndex;
// read thru the remaining string to find file names
for (myIndex = 0; *myCmdLine != '\0'; myIndex++, myCmdLine++) {
// if we encounter a space character, it might be a filename delimiter or a space in the filename;
// we'll try to open the filename we have so far to see whether it's a valid filename; if not, the
// space must be part of the filename we're constructing
if (*myCmdLine == ' ') {
HANDLE myFindFile;
WIN32_FIND_DATA myFile;
myTempName[myIndex] = '\0';
strcpy(myBuffName, myTempName);
myFindFile = FindFirstFile(myBuffName, &myFile);
if (myFindFile != INVALID_HANDLE_VALUE) {
// we found a file having the specified name; close our file search and
// break out of our character-gobbling loop (since we've got a valid filename)
FindClose(myFindFile);
break;
}
}
// if we made it here, *myCmdLine is part of the filename (possibly a space)
myFileName[myIndex] = myTempName[myIndex] = *myCmdLine;
}
if (*myCmdLine != '\0')
myCmdLine++;
// add a terminating NULL character
myFileName[myIndex] = '\0';
// make sure the filename picks out a QuickTime movie
SHGetFileInfo(myFileName, (DWORD)0, &myFileInfo, sizeof(myFileInfo), SHGFI_TYPENAME);
if (strcmp(myFileInfo.szTypeName, gMovieType) != 0)
continue;
// make an FSSpec record
NativePathNameToFSSpec(myFileName, &myFSSpec, 0L);
// open the file in a movie window
QTFrame_OpenMovieInWindow(NULL, &myFSSpec);
}
} else
myCmdLine += strlen(myCmdLine); // point to NULL
}
}
//////////
//
// QTFrame_CreateMovieWindow
// Create a new window to display the movie in.
//
//////////
WindowReference QTFrame_CreateMovieWindow (void)
{
WindowReference myWindow = NULL;
gWeAreCreatingWindow = true;
// create a new window to display the movie in
myWindow = CreateWindowEx(WS_EX_MDICHILD,
gChildName,
"",
0,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
ghWndMDIClient,
NULL,
ghInst,
0);
// CreateWindowEx sends a WM_CREATE message to the window being created;
// we'll call QTFrame_CreateWindowObject when processing that message
gWeAreCreatingWindow = false;
return(myWindow);
}
//////////
//
// QTFrame_DestroyMovieWindow
// Close the specified movie window.
//
//////////
void QTFrame_DestroyMovieWindow (WindowReference theWindow)
{
#pragma unused(theWindow)
HWND myChild = NULL;
// close the active child window
myChild = (HWND)SendMessage(ghWndMDIClient, WM_MDIGETACTIVE, 0, 0L);
if (IsWindow(myChild))
SendMessage(myChild, WM_CLOSE, 0L, 0L);
}
//////////
//
// QTFrame_GetDisplayName
// Given a full pathname, return the part that trails the rightmost path separator,
// in long file name format (not in 8.3 format).
//
//////////
void QTFrame_GetDisplayName (char *thePathName, char *theDispName)
{
SHFILEINFO myFileInfo;
DWORD myResult;
myResult = SHGetFileInfo(thePathName, (DWORD)0, &myFileInfo, sizeof(myFileInfo), SHGFI_DISPLAYNAME);
if (myResult != 0) {
// SHGetFileInfo successful
strcpy(theDispName, myFileInfo.szDisplayName);
} else {
// SHGetFileInfo not successful, so find the basename ourselves
short myLength = 0;
short myIndex;
// get the length of the pathname
myLength = strlen(thePathName);
// find the position of the rightmost path separator in thePathName
if (strchr(thePathName, kWinFilePathSeparator) != NULL) {
myIndex = myLength - 1;
while (thePathName[myIndex] != kWinFilePathSeparator)
myIndex--;
// calculate the length of the basename
myLength = myLength - myIndex - 1;
} else {
// there is no rightmost path separator in thePathName;
// set myIndex so that myIndex + 1 == 0, for the call to BlockMove below
myIndex = -1;
}
// copy into theDispName the substring of thePathName from myIndex + 1 to the end
BlockMove(&thePathName[myIndex + 1], theDispName, myLength);
theDispName[myLength] = '\0';
}
}
//////////
//
// QTFrame_ShowAboutBox
// Display and manage the About dialog box.
//
//////////
void QTFrame_ShowAboutBox (void)
{
DialogBox(ghInst, MAKEINTRESOURCE(IDD_ABOUT), ghWnd, (DLGPROC)QTFrame_DialogProcedure);
}
//////////
//
// QTFrame_ShowCautionAlert
// Display and manage a caution alert.
//
// Based on ShowUserMessage by Stephen Chernicoff, in his WiniEdit application
// (as described in the book "From Mac to Windows" on CodeWarrior reference CD).
//
//////////
int QTFrame_ShowCautionAlert (HWND theWnd, UINT theID, UINT theIconStyle, UINT theButtonStyle, LPSTR theTitle, LPSTR theArgument)
{
char myTemplate[kAlertMessageMaxLength];
char myText[kAlertMessageMaxLength];
UINT myStyle;
int myItem;
// beep, to get the user's attention (just like CautionAlert on MacOS)
QTFrame_Beep();
// load the message text template from a resource
LoadString(ghInst, theID, myTemplate, sizeof(myTemplate));
// insert argument into the message text template, to get the message text
wsprintf(myText, myTemplate, theArgument);
// set the dialog box style
myStyle = theIconStyle | theButtonStyle | MB_APPLMODAL | MB_SETFOREGROUND;
// display the dialog box
myItem = MessageBox(theWnd, myText, theTitle, myStyle);
return(myItem);
}
//////////
//
// QTFrame_DialogProcedure
// Dialog callback procedure.
//
//////////
static UINT APIENTRY QTFrame_DialogProcedure (HWND theDialog, UINT theMessage, WPARAM wParam, LPARAM lParam)
{
BOOL isHandled = false;
switch (theMessage) {
case WM_INITDIALOG: {
Point myPoint;
long myWidth;
long myHeight;
RECT myRect;