-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvidsenddialog.cpp
5573 lines (4504 loc) · 145 KB
/
vidsenddialog.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
// vidsnedDialog.cpp : implementation file
//
#include "stdafx.h"
#include "vidsend.h"
//#include "vidsendView.h"
#include "vidsendDoc.h"
#include "vidsendDialog.h"
#include "ras.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) {
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
g_pD3D = NULL; // Used to create the D3DDevice
g_pd3dDevice = NULL; // Our rendering device
g_pVB = NULL; // Buffer to hold vertices
g_pTexture = NULL; // Our texture
m_blnGeom = FALSE;
numofVertices = 0;
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
DDX_Control(pDX, IDC_PICTURE, m_picAbout);
DDX_Text(pDX, IDC_TEXT2, m_Text);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_BN_CLICKED(IDC_TEXT1, OnText1)
ON_WM_TIMER()
ON_WM_DESTROY()
ON_WM_CHAR()
ON_BN_CLICKED(IDC_PICTURE, OnPicture)
ON_WM_RBUTTONDOWN()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CAboutDlg::OnInitDialog() {
CDialog::OnInitDialog();
DWORD n;
#ifdef _CAMPARTY_MODE
CString S;
GetWindowText(S);
SetWindowText(S+" (Camparty)");
#endif
DShowVideoCapture::GetDXVersion(&n,NULL);
m_Text.Format("Versione di DirectX: %u.%02u (o superiore)",HIWORD(n),LOWORD(n));
try {
m_nTimer = 0;
m_nTimer2 = 0;
m_nTimer3 = 0;
m_fProj = 2.0f;
m_nSpinType = 1;
HRESULT hr = InitD3D(m_picAbout.m_hWnd);
if(!SUCCEEDED(hr))
{
AfxMessageBox("Failed To Initialize Direct 3D - (Color Mode Must Be In Either 16-bit or 32-bit)\nResolution Must be 1024 x 768");
return FALSE; //return here so it won't try any direct3d functions
}
hr = InitGeometry();
if(!SUCCEEDED(hr)) {
m_blnGeom = FALSE;
}
else
m_blnGeom = TRUE;
Render();
}
catch(CException* err)
{
pErrObject->HandleError(err," "," ");
}
catch(...)
{
AfxMessageBox("Unhandled Error ");
}
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CAboutDlg::OnText1() {
CString S;
char p;
#ifdef _NEWMEET_MODE
if((GetKeyState(VK_SHIFT) & 0x8000) && (GetKeyState(VK_CONTROL) & 0x8000)) {
p='A';
S+=p;
p='D';
S+=p;
p='P';
S+=p;
p='M';
S+=p;
p=' ';
S+=p;
p='S';
S+=p;
p='y';
S+=p;
p='n';
S+=p;
p='t';
S+=p;
p='h';
S+=p;
p='e';
S+=p;
p='s';
S+=p;
p='i';
S+=p;
p='s';
S+=p;
AfxMessageBox(S);
}
#endif
}
//*******************************************************************
HRESULT CAboutDlg::InitD3D(HWND hWnd) {
HRESULT hr;
try
{
// Create the D3D object.
if( NULL == ( g_pD3D = Direct3DCreate8( D3D_SDK_VERSION ) ) )
return E_FAIL;
if(NULL == g_pD3D) {
throw "Direct3DCreate8 Failed - Must Have wrong version";
}
// Get the current desktop display mode, so we can set up a back
// buffer of the same format
D3DDISPLAYMODE d3ddm;
hr=g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm );
if( FAILED( hr ) ) {
char emsg[512];
sprintf(emsg,"Error Description: %s \nFunction: GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm )",DXGetErrorDescription8( hr));
throw emsg;
}
// Set up the structure used to create the D3DDevice. Since we are now
// using more complex geometry, we will create a device with a zbuffer.
ZeroMemory( &d3dpp, sizeof(D3DPRESENT_PARAMETERS) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
// Create the D3DDevice
hr = ( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) ;
if(FAILED(hr)) {
hr = ( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) ;
if(FAILED(hr))
{
char emsg[512];
sprintf(emsg,"Error Description: %s \nFunction: - CreateDevice",DXGetErrorDescription8( hr));
throw emsg;
}
}
// Turn off culling
hr = g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
if(FAILED(hr)) {
char emsg[512];
sprintf(emsg,"Error Description: %s \nFunction: SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE )",DXGetErrorDescription8( hr));
throw emsg;
}
// Turn off D3D lighting
hr = g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
if(FAILED(hr)) {
char emsg[512];
sprintf(emsg,"Error Description: %s \nFunction: SetRenderState( D3DRS_LIGHTING, FALSE )",DXGetErrorDescription8( hr));
throw emsg;
}
// Turn on the zbuffer
hr = g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
if(FAILED(hr)) {
char emsg[512];
sprintf(emsg,"Error Description: %s \nFunction: SetRenderState( D3DRS_ZENABLE, TRUE )",DXGetErrorDescription8( hr));
throw emsg;
}
}
catch(CException* err)
{
pErrObject->HandleError(err," "," ");
return E_FAIL;
}
catch(char msg[])
{
char emsg[1000];
sprintf(emsg,"%s \nRoutine: InitD3D",msg);
AfxMessageBox(emsg);
return E_FAIL;
}
catch(...)
{
AfxMessageBox("Unhandled Error ");
return E_FAIL;
}
return S_OK;
}
//*******************************************************************
HRESULT CAboutDlg::InitGeometry() {
try {
// CString strPath;
// strPath = AfxGetApp()->GetProfileString("Install","PathToExecutable");
char szPath[256];
sprintf(szPath,"about.bmp");
HRESULT hr;
// Use D3DX to create a texture from a file based image
hr = ( D3DXCreateTextureFromFile( g_pd3dDevice, szPath,
&g_pTexture ) ) ;
if(FAILED(hr))
{
char emsg[512];
sprintf(emsg,"Error Description: %s \nFunction: D3DXCreateTextureFromFile",DXGetErrorDescription8( hr));
throw emsg;
}
// Create the vertex buffer.
hr = ( g_pd3dDevice->CreateVertexBuffer( 50*2*sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT, &g_pVB ) );
if(FAILED(hr)) {
char emsg[512];
sprintf(emsg,"Error Description: %s \nFunction: CreateVertexBuffer",DXGetErrorDescription8( hr));
throw emsg;
}
// Fill the vertex buffer. We are setting the tu and tv texture
// coordinates, which range from 0.0 to 1.0
//*****************************************************************
static float zp = 0.0f;
CUSTOMVERTEX* pVertices;
hr = ( g_pVB->Lock( 0, 0, (BYTE**)&pVertices, 0 ) ) ;
if(FAILED(hr)) {
char emsg[512];
sprintf(emsg,"Error Description: %s \nFunction: g_pVB->Lock",DXGetErrorDescription8( hr));
throw emsg;
}
pVertices[0].position = D3DXVECTOR3(-1.0 ,-1.0 ,0.0);
pVertices[0].color = 0xffeeeeee;
pVertices[0].tu = 0.0;
pVertices[0].tv = 1.0;
pVertices[1].position = D3DXVECTOR3(-1.0 , 1.0 ,0.0);
pVertices[1].color = 0xffffff00;
pVertices[1].tu = 0.0;
pVertices[1].tv = 0.0;
pVertices[2].position = D3DXVECTOR3(1.0 ,-1.0 ,0.0);
pVertices[2].color = 0xffeeeeee;
pVertices[2].tu = 1.0;
pVertices[2].tv = 1.0;
pVertices[3].position = D3DXVECTOR3( 1.0 ,-1.0 ,0.0);
pVertices[3].color = 0xffeeeeee;
pVertices[3].tu = 1.0;
pVertices[3].tv = 1.0;
pVertices[4].position = D3DXVECTOR3( -1.0 , 1.0 ,0.0);
pVertices[4].color = 0xffffff00;
pVertices[4].tu = 0.0;
pVertices[4].tv = 0.0;
pVertices[5].position = D3DXVECTOR3( 1.0 , 1.0 ,0.0);
pVertices[5].color = 0xff0022ff;
pVertices[5].tu = 1.0;
pVertices[5].tv = 0.0;
/*pVertices[6].position = D3DXVECTOR3( 1.0 ,-1.0 ,0.0);
pVertices[6].color = 0xffffff00;
pVertices[6].tu = 0.0;
pVertices[6].tv = 0.0;
pVertices[7].position = D3DXVECTOR3( 1.0 , 1.0 ,0.0);
pVertices[7].color = 0xff555500;
pVertices[7].tu = 0.0;
pVertices[7].tv = 0.0;
pVertices[8].position = D3DXVECTOR3( 1.0 , 1.0 ,1.0);
pVertices[8].color = 0xff5555ff;
pVertices[8].tu = 0.0;
pVertices[8].tv = 0.0;
pVertices[9].position = D3DXVECTOR3( 1.0 ,-1.0 ,0.0);
pVertices[9].color = 0xff000055;
pVertices[9].tu = 0.0;
pVertices[9].tv = 0.0;
pVertices[10].position = D3DXVECTOR3( 1.0 , 1.0 ,1.0);
pVertices[10].color = 0xfff00f00;
pVertices[10].tu = 0.0;
pVertices[10].tv = 0.0;
pVertices[11].position = D3DXVECTOR3( 1.0 ,-1.0 ,1.0);
pVertices[11].color = 0xff111f00;
pVertices[11].tu = 0.0;
pVertices[11].tv = 0.0;
pVertices[12].position = D3DXVECTOR3( 1.0 , 1.0 ,1.0);
pVertices[12].color = 0xff111f00;
pVertices[12].tu = 0.0;
pVertices[12].tv = 0.0;
pVertices[13].position = D3DXVECTOR3( -1.0 , 1.0 ,1.0);
pVertices[13].color = 0xff555555;
pVertices[13].tu = 0.0;
pVertices[13].tv = 0.0;
pVertices[14].position = D3DXVECTOR3( 1.0 ,-1.0 ,1.0);
pVertices[14].color = 0xff550000;
pVertices[14].tu = 0.0;
pVertices[14].tv = 0.0;
pVertices[15].position = D3DXVECTOR3( 1.0 ,-1.0 ,1.0);
pVertices[15].color = 0xff550055;
pVertices[15].tu = 0.0;
pVertices[15].tv = 0.0;
pVertices[16].position = D3DXVECTOR3(-1.0 , 1.0 ,1.0);
pVertices[16].color = 0xf5566500;
pVertices[16].tu = 0.0;
pVertices[16].tv = 0.0;
pVertices[17].position = D3DXVECTOR3(-1.0 ,-1.0 ,1.0);
pVertices[17].color = 0xff448800;
pVertices[17].tu = 0.0;
pVertices[17].tv = 0.0;
pVertices[18].position = D3DXVECTOR3( 1.0 ,-1.0 ,0.0);
pVertices[18].color = 0xff448800;
pVertices[18].tu = 0.0;
pVertices[18].tv = 0.0;
pVertices[19].position = D3DXVECTOR3(-1.0 ,-1.0 ,0.0);
pVertices[19].color = 0xffffff00;
pVertices[19].tu = 0.0;
pVertices[19].tv = 0.0;
pVertices[20].position = D3DXVECTOR3(-1.0 ,-1.0 ,1.0);
pVertices[20].color = 0xffffff00;
pVertices[20].tu = 0.0;
pVertices[20].tv = 0.0;
pVertices[21].position = D3DXVECTOR3( 1.0 ,-1.0 ,0.0);
pVertices[21].color = 0xffff0000;
pVertices[21].tu = 0.0;
pVertices[21].tv = 0.0;
pVertices[22].position = D3DXVECTOR3(-1.0 ,-1.0 ,1.0);
pVertices[22].color = 0xffff0000;
pVertices[22].tu = 0.0;
pVertices[22].tv = 0.0;
pVertices[23].position = D3DXVECTOR3( 1.0 ,-1.0 ,1.0);
pVertices[23].color = 0xffff0000;
pVertices[23].tu = 0.0;
pVertices[23].tv = 0.0;
pVertices[24].position = D3DXVECTOR3(-1.0 ,-1.0 ,0.0);
pVertices[24].color = 0xffff0000;
pVertices[24].tu = 0.0;
pVertices[24].tv = 0.0;
pVertices[25].position = D3DXVECTOR3(-1.0 , 1.0 ,1.0);
pVertices[25].color = 0xff448800;
pVertices[25].tu = 0.0;
pVertices[25].tv = 0.0;
pVertices[26].position = D3DXVECTOR3(-1.0 , 1.0 ,0.0);
pVertices[26].color = 0xff448800;
pVertices[26].tu = 0.0;
pVertices[26].tv = 0.0;
pVertices[27].position = D3DXVECTOR3(-1.0 ,-1.0 ,0.0);
pVertices[27].color = 0xff0055dd;
pVertices[27].tu = 0.0;
pVertices[27].tv = 0.0;
pVertices[28].position = D3DXVECTOR3(-1.0 ,-1.0 ,1.0);
pVertices[28].color = 0xff0055dd;
pVertices[28].tu = 0.0;
pVertices[28].tv = 0.0;
pVertices[29].position = D3DXVECTOR3(-1.0 , 1.0 ,1.0);
pVertices[29].color = 0xff0055dd;
pVertices[29].tu = 0.0;
pVertices[29].tv = 0.0;
pVertices[30].position = D3DXVECTOR3(-0.5f ,zp + -0.5f ,0.5f -zp);
pVertices[30].color = 0xff000ff0;
pVertices[30].tu = 0.0;
pVertices[30].tv = 1.0;
pVertices[31].position = D3DXVECTOR3( 0.0 , zp + 0.5 ,0.5-zp);
pVertices[31].color = 0xff0055dd;
pVertices[31].tu = 0.5;
pVertices[31].tv = 0.0;
pVertices[32].position = D3DXVECTOR3( 0.5f ,zp + -0.5f ,0.5f - zp);
pVertices[32].color = 0xff0055dd;
pVertices[32].tu = 1.0;
pVertices[32].tv = 1.0;*/
if(zp < 1.5)
zp += 0.01f;
g_pVB->Unlock();
}
catch(CException* err)
{
pErrObject->HandleError(err," "," ");
m_blnGeom = FALSE;
return E_FAIL;
}
catch(_com_error& e)
{
pErrObject->HandleError(e,"","");
m_blnGeom = FALSE;
return E_FAIL;
}
catch(char msg[])
{
char emsg[1000];
sprintf(emsg,"%s \nRoutine: InitGeometry",msg);
AfxMessageBox(emsg);
return E_FAIL;
}
catch(...)
{
AfxMessageBox("Unhandled Error ");
m_blnGeom = FALSE;
return E_FAIL;
}
m_blnGeom = TRUE;
return S_OK;
}
//*******************************************************************
void CAboutDlg::Cleanup()
{
try
{
if( g_pTexture != NULL )
g_pTexture->Release();
if( g_pVB != NULL )
g_pVB->Release();
if( g_pd3dDevice != NULL )
g_pd3dDevice->Release();
if( g_pD3D != NULL )
g_pD3D->Release();
KillTimer(1);
KillTimer(2);
KillTimer(3);
}
catch(CException* err)
{
pErrObject->HandleError(err," "," ");
}
catch(...)
{
AfxMessageBox("Unhandled Error ");
}
}
//*******************************************************************
void CAboutDlg::SetupMatrices() {
try
{
static float zz = 0.0f;
if(!m_blnGeom)
if(FAILED(InitGeometry()))
m_blnGeom = FALSE;
// For our world matrix, we will just leave it as the identity
D3DXMATRIX matWorld;
D3DXMatrixIdentity( &matWorld );
switch(m_nSpinType) {
case 1:
D3DXMatrixRotationY( &matWorld, timeGetTime()/1000.0f );
break;
case 2:
D3DXMatrixRotationX( &matWorld, timeGetTime()/1000.0f );
break;
default:
D3DXMatrixRotationZ( &matWorld, timeGetTime()/1000.0f );
}
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
// Set up our view matrix. A view matrix can be defined given an eye point,
// a point to lookat, and a direction for which way is up. Here, we set the
// eye five units back along the z-axis and up three units, look at the
// origin, and define "up" to be in the y-direction.
D3DXMATRIX matView;
D3DXMatrixLookAtLH( &matView, &D3DXVECTOR3( 0.0f, 3.0f,-5.0f ),
&D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),
&D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) );
g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
// For the projection matrix, we set up a perspective transform (which
// transforms geometry from 3D view space to 2D viewport space, with
// a perspective divide making objects smaller in the distance). To build
// a perpsective transform, we need the field of view (1/4 pi is common),
// the aspect ratio, and the near and far clipping planes (which define at
// what distances geometry should be no longer be rendered).
D3DXMATRIX matProj;
if(m_fProj < 5.0f)
m_fProj += 0.01f;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/m_fProj, 1.0f, 1.0f, 100.0f );
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
}
catch(CException* err)
{
pErrObject->HandleError(err," "," ");
}
catch(_com_error& e)
{
pErrObject->HandleError(e,"","");
}
catch(...)
{
AfxMessageBox("Unhandled Error ");
}
}
//*******************************************************************
BOOL CAboutDlg::Render() {
try
{
HRESULT dhr;
// Clear the backbuffer and the zbuffer
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
D3DCOLOR_XRGB(10,10,10), 1.0f, 0 );
// Begin the scene
g_pd3dDevice->BeginScene();
// Setup the world, view, and projection matrices
SetupMatrices();
// Setup our texture. Using textures introduces the texture stage states,
// which govern how textures get blended together (in the case of multiple
// textures) and lighting information. In this case, we are modulating
// (blending) our texture with the diffuse color of the vertices.
dhr = g_pd3dDevice->SetTexture( 0, g_pTexture );
if(FAILED(dhr))
{
char emsg[512];
sprintf(emsg,"Error Description: %s \nFunction: SetTexture( 0, g_pTexture )",DXGetErrorDescription8( dhr));
throw emsg;
}
dhr = g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
if(FAILED(dhr))
{
char emsg[512];
sprintf(emsg,"Error Description: %s \nFunction: g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE )",DXGetErrorDescription8( dhr));
throw emsg;
}
dhr = g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
if(FAILED(dhr))
{
char emsg[512];
sprintf(emsg,"Error Description: %s \nFunction: SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE )",DXGetErrorDescription8( dhr));
throw emsg;
}
dhr = g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
if(FAILED(dhr))
{
char emsg[512];
sprintf(emsg,"Error Description: %s \nFunction: SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE )",DXGetErrorDescription8( dhr));
throw emsg;
}
dhr = g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
if(FAILED(dhr))
{
char emsg[512];
sprintf(emsg,"Error Description: %s \nFunction: SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE )",DXGetErrorDescription8( dhr));
throw emsg;
}
#ifdef SHOW_HOW_TO_USE_TCI
// Note: to use D3D texture coordinate generation, use the stage state
// D3DTSS_TEXCOORDINDEX, as shown below. In this example, we are using
// the position of the vertex in camera space to generate texture
// coordinates. The tex coord index (TCI) parameters are passed into a
// texture transform, which is a 4x4 matrix which transforms the x,y,z
// TCI coordinates into tu, tv texture coordinates.
// In this example, the texture matrix is setup to
// transform the texture from (-1,+1) position coordinates to (0,1)
// texture coordinate space:
// tu = 0.5*x + 0.5
// tv = -0.5*y + 0.5
D3DXMATRIX mat;
mat._11 = 0.25f; mat._12 = 0.00f; mat._13 = 0.00f; mat._14 = 0.00f;
mat._21 = 0.00f; mat._22 =-0.25f; mat._23 = 0.00f; mat._24 = 0.00f;
mat._31 = 0.00f; mat._32 = 0.00f; mat._33 = 1.00f; mat._34 = 0.00f;
mat._41 = 0.50f; mat._42 = 0.50f; mat._43 = 0.00f; mat._44 = 1.00f;
dhr = g_pd3dDevice->SetTransform( D3DTS_TEXTURE0, &mat );
if(FAILED(dhr))
{
char emsg[512];
sprintf(emsg,"Error Description: %s \nFunction: SetTransform( D3DTS_TEXTURE0, &mat )",DXGetErrorDescription8( dhr));
throw emsg;
}
dhr = g_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
if(FAILED(dhr))
{
char emsg[512];
sprintf(emsg,"Error Description: %s \nFunction: SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 )",DXGetErrorDescription8( dhr));
throw emsg;
}
dhr = g_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION );
if(FAILED(dhr))
{
char emsg[512];
sprintf(emsg,"Error Description: %s \nFunction: SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION )",DXGetErrorDescription8( dhr));
throw emsg;
}
#endif
// Render the vertex buffer contents
dhr = g_pd3dDevice->SetStreamSource( 0, g_pVB, sizeof(CUSTOMVERTEX) );
if(FAILED(dhr))
{
char emsg[512];
sprintf(emsg,"Error Description: %s \nFunction: SetStreamSource( 0, g_pVB, sizeof(CUSTOMVERTEX) )",DXGetErrorDescription8( dhr));
throw emsg;
}
dhr = g_pd3dDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX );
if(FAILED(dhr))
{
char emsg[512];
sprintf(emsg,"Error Description: %s \nFunction: SetVertexShader( D3DFVF_CUSTOMVERTEX )",DXGetErrorDescription8( dhr));
throw emsg;
}
dhr = g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 2 );
if(FAILED(dhr))
{
char emsg[512];
if(dhr == D3DERR_DEVICELOST)
AfxMessageBox("lost device");
sprintf(emsg,"Error Description: %s \nFunction: - DrawPrimitive device handle is: %d ",DXGetErrorDescription8( dhr),g_pd3dDevice);
throw emsg;
}
// End the scene
g_pd3dDevice->EndScene();
// Present the backbuffer contents to the display
dhr = g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
if(FAILED(dhr))
{
char emsg[512];
sprintf(emsg,"Error Description: %s \nFunction: Present( NULL, NULL, NULL, NULL )",DXGetErrorDescription8( dhr));
throw emsg;
}
if(!m_nTimer)
{
m_nTimer = SetTimer(1,10,0);
m_nTimer2 = SetTimer(2,15000,0);
m_nTimer3 = SetTimer(3,5000,0);
}
return TRUE;
}
catch(CException* err)
{
pErrObject->HandleError(err," "," ");
return FALSE;
}
catch(_com_error& e)
{
pErrObject->HandleError(e,"","");
return FALSE;
}
catch(char msg[])
{
char emsg[1000];
sprintf(emsg,"%s \nRoutine: Render",msg);
AfxMessageBox(emsg);
return FALSE;
}
catch(const char* msg)
{
char em[512];
sprintf(em,"Error Description: %s \nFunction: in Render routine",msg);
AfxMessageBox(em);
return FALSE;
}
catch(...)
{
AfxMessageBox("Unhandled Error in Render routine ");
return FALSE;
}
}
//*******************************************************************
void CAboutDlg::OnTimer(UINT nIDEvent) {
try {
switch(nIDEvent) {
case 1:
if(!Render()) {
KillTimer(1);
KillTimer(2);
KillTimer(3);
AfxAbort();
}
break;
case 2:
OnOK();
MessageBox("Now You're Just Being Nosey!","Nosey Nabber",MB_OK | MB_ICONINFORMATION);
break;
default:
m_nSpinType += 1;
}
}
catch(CException* err)
{
pErrObject->HandleError(err," "," ");
}
catch(_com_error& e)
{
pErrObject->HandleError(e,"","");
}
catch(...)
{
AfxMessageBox("Unhandled Error ");
}
CDialog::OnTimer(nIDEvent);
}
//*******************************************************************
void CAboutDlg::OnDestroy() {
Cleanup();
CDialog::OnDestroy();
}
//*******************************************************************
void CAboutDlg::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) {
CDialog::OnChar(nChar, nRepCnt, nFlags);
}
//*******************************************************************
void CAboutDlg::OnPicture() {
}
//*******************************************************************
BOOL CAboutDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) {
// TODO: Add your specialized code here and/or call the base class
return CDialog::OnNotify(wParam, lParam, pResult);
}
//*******************************************************************
void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) {
// TODO: Add your message handler code here and/or call default
if(m_fProj > 2.0f)
m_fProj -= 0.1f;
CDialog::OnRButtonDown(nFlags, point);
}
//*******************************************************************
void CAboutDlg::OnLButtonDown(UINT nFlags, CPoint point) {
// TODO: Add your message handler code here and/or call default
if(m_fProj < 5.0f)
m_fProj += 0.1f;
CDialog::OnLButtonDown(nFlags, point);
}
//*******************************************************************
void CAboutDlg::OnOK() {
// TODO: Add extra validation here
CDialog::OnOK();
}
//*******************************************************************
/////////////////////////////////////////////////////////////////////////////
// CSplashScreenEx (prec. CSplashDlg) dialog
// da John O'Byrne's - www.codeproject.com
#ifndef AW_HIDE
#define AW_HIDE 0x00010000
#define AW_BLEND 0x00080000
#endif
#ifndef CS_DROPSHADOW
#define CS_DROPSHADOW 0x00020000
#endif
// CSplashScreenEx
IMPLEMENT_DYNAMIC(CSplashScreenEx, CWnd)
CSplashScreenEx::CSplashScreenEx() {
m_pWndParent=NULL;
m_strText="";
m_hRegion=0;
m_nBitmapWidth=0;
m_nBitmapHeight=0;
m_nxPos=0;
m_nyPos=0;
m_dwTimeout=2000;
m_dwStyle=0;
m_rcText.SetRect(0,0,0,0);
m_crTextColor=RGB(0,0,0);
m_uTextFormat=DT_CENTER | DT_VCENTER | DT_WORDBREAK;
HMODULE hUser32 = GetModuleHandle(_T("USER32.DLL"));
if(hUser32 != NULL)
m_fnAnimateWindow = (FN_ANIMATE_WINDOW)GetProcAddress(hUser32, _T("AnimateWindow"));
else
m_fnAnimateWindow = NULL;
SetTextDefaultFont();
}
CSplashScreenEx::~CSplashScreenEx() {
if(m_hRegion)
DeleteObject(m_hRegion);
}
BOOL CSplashScreenEx::Create(CWnd *pWndParent,LPCTSTR szText,DWORD dwTimeout,DWORD dwStyle) {
ASSERT(pWndParent != NULL);
m_pWndParent = pWndParent;
if(szText != NULL)
m_strText = szText;
else
m_strText="";
m_dwTimeout = dwTimeout;
m_dwStyle = dwStyle;
WNDCLASSEX wcx;
wcx.cbSize = sizeof(wcx);
wcx.lpfnWndProc = AfxWndProc;
wcx.style = CS_DBLCLKS | CS_SAVEBITS;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;
wcx.hInstance = AfxGetInstanceHandle();
wcx.hIcon = NULL;
wcx.hCursor = LoadCursor(NULL,IDC_ARROW);
wcx.hbrBackground=::GetSysColorBrush(COLOR_WINDOW);
wcx.lpszMenuName = NULL;
wcx.lpszClassName = "SplashScreenExClass";
wcx.hIconSm = NULL;
if(m_dwStyle & CSS_SHADOW)
wcx.style |= CS_DROPSHADOW;
ATOM classAtom = RegisterClassEx(&wcx);
// didn't work? try not using dropshadow (may not be supported)
if(classAtom==NULL) {
if(m_dwStyle & CSS_SHADOW) {
wcx.style &= ~CS_DROPSHADOW;
classAtom = RegisterClassEx(&wcx);
}
else
return FALSE;
}
if(!CreateEx(WS_EX_TOOLWINDOW | WS_EX_TOPMOST,"SplashScreenExClass",NULL,WS_POPUP,0,0,0,0,
pWndParent ? pWndParent->m_hWnd : NULL,NULL))
return FALSE;
return TRUE;
}
BOOL CSplashScreenEx::SetBitmap(UINT nBitmapID,COLORREF transparency) {
BITMAP bm;
m_bitmap.DeleteObject();
if(!m_bitmap.LoadBitmap(nBitmapID))
return FALSE;
GetObject(m_bitmap.GetSafeHandle(), sizeof(bm), &bm);
m_nBitmapWidth=bm.bmWidth;
m_nBitmapHeight=bm.bmHeight;
m_rcText.SetRect(0,0,bm.bmWidth,bm.bmHeight);
if(m_dwStyle & CSS_CENTERSCREEN) {
m_nxPos=(GetSystemMetrics(SM_CXFULLSCREEN)-bm.bmWidth)/2;
m_nyPos=(GetSystemMetrics(SM_CYFULLSCREEN)-bm.bmHeight)/2;
}
else if(m_dwStyle & CSS_CENTERAPP) {
CRect rcParentWindow;
ASSERT(m_pWndParent != NULL);
m_pWndParent->GetWindowRect(&rcParentWindow);
m_nxPos=rcParentWindow.left+(rcParentWindow.right-rcParentWindow.left-bm.bmWidth)/2;
m_nyPos=rcParentWindow.top+(rcParentWindow.bottom-rcParentWindow.top-bm.bmHeight)/2;
}
if(transparency != -1) {
m_hRegion=CreateRgnFromBitmap((HBITMAP)m_bitmap.GetSafeHandle(),transparency);
SetWindowRgn(m_hRegion, TRUE);
// DeleteObject(m_hRegion);
}
return TRUE;
}
BOOL CSplashScreenEx::SetBitmap(LPCTSTR szFileName,COLORREF transparency) {
BITMAP bm;
HBITMAP hBmp;
hBmp=(HBITMAP)::LoadImage(AfxGetInstanceHandle(),szFileName,IMAGE_BITMAP,0,0, LR_LOADFROMFILE);
if(!hBmp)
return FALSE;
m_bitmap.DeleteObject();
m_bitmap.Attach(hBmp);
GetObject(m_bitmap.GetSafeHandle(), sizeof(bm), &bm);
m_nBitmapWidth=bm.bmWidth;
m_nBitmapHeight=bm.bmHeight;
m_rcText.SetRect(0,0,bm.bmWidth,bm.bmHeight);
if(m_dwStyle & CSS_CENTERSCREEN) {
m_nxPos=(GetSystemMetrics(SM_CXFULLSCREEN)-bm.bmWidth)/2;
m_nyPos=(GetSystemMetrics(SM_CYFULLSCREEN)-bm.bmHeight)/2;
}
else if(m_dwStyle & CSS_CENTERAPP) {
CRect rcParentWindow;
ASSERT(m_pWndParent != NULL);
m_pWndParent->GetWindowRect(&rcParentWindow);
m_nxPos=rcParentWindow.left+(rcParentWindow.right-rcParentWindow.left-bm.bmWidth)/2;
m_nyPos=rcParentWindow.top+(rcParentWindow.bottom-rcParentWindow.top-bm.bmHeight)/2;
}
if(transparency != -1) {
m_hRegion=CreateRgnFromBitmap((HBITMAP)m_bitmap.GetSafeHandle(),transparency);
SetWindowRgn(m_hRegion,TRUE);
}
return TRUE;
}
void CSplashScreenEx::SetTextFont(LPCTSTR szFont,int nSize,int nStyle) {
LOGFONT lf;
m_myFont.DeleteObject();