-
Notifications
You must be signed in to change notification settings - Fork 0
/
si_Basecode.cpp
2019 lines (1750 loc) · 73.9 KB
/
si_Basecode.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
// si_Basecode.cpp - space invaders opengl
/***********************************************
* Jeff Molofee's Revised OpenGL Basecode *
* Huge Thanks To Maxwell Sayles & Peter Puck *
* http://nehe.gamedev.net *
* 2001 *
***********************************************/
// This file handles : - the program entry (WinMain() function)
// - the main loop
// - the Windows messages
// - the dialog boxes (startup, about, streaming URL)
#include <windows.h> // Header File For The Windows Library
#include <Wininet.h> // Header File For Internet Library
#include <gl/gl.h> // Header File For The OpenGL32 Library
#include <gl/glu.h> // Header File For The OpenGL Utility Library
#include "si_Basecode.h" // Header File For The NeHeGL Basecode
#include "si_Main.h" // Header File For Main Global Variables
#include "commctrl.h" // Header File For Windows XP Common Controls
#include "si_Functions.h" // Header File For The Game Functions
#include "resource.h" // Header File For the resources ids
#define WM_TOGGLEFULLSCREEN (WM_USER+1) // Application Define Message For Toggling Fullscreen
// ALPHA LAYERED WINDOW (WINDOW TRANSPARENCY)
typedef BOOL (WINAPI *SLWA_FUNC)(HWND hwnd,COLORREF crKey,BYTE bAlpha,DWORD dwFlags);
//bool first_pass = true;
//DWORD start, actual;
//BYTE alpha=0;
// DIALOG BOXES HANDLES
HWND g_hwndDlg; // Startup DialogBox Handle
HWND g_hwndDlgAbout; // About DialogBox Handle
// MISC.
bool equalizer_moving = false; // Equalizer en train d'être déplacé ?
bool dialogbox_internet_over = false; // Bouton Internet (mouse over)
extern bool game_spectrum; // Spectrum activated ?
HCURSOR cur_hand, cur_hand_closed; // Handles Of Cursors
bool custom_streaming_dialogbox = false; // for playing song when enter 'about' but not 'custom stream'
COLORREF textcolor2;
bool AntialiasingMode_over = false;
// TOOLTIPS
HWND g_hwndTT; // The window which handles tooltips
TOOLINFO ti; // The toolinfo structure (for tooltips properties)
WNDPROC OrigControlProc, OrigAntiAliasingModeProc; // To return the unprocessed messages in the procedure of the subclassed controls
// GAME PARAMETERS (STEP, LOADING)
extern int game_step; // Etape du jeu (chargement etc.)
extern bool Fps2_firstpass; // FPS Méthode n°2
bool game_loading = false; // To make the Loading Thread called only once
bool game_loading_finished = true;
// THREADS
unsigned long h_thread2; // Handle Of The Loading Thread
bool my_mod_about_on = false; // Music For About-DialogBox
bool my_mod_about_working = false; // Music For About-DialogBox
// PROGRAM
static BOOL g_isProgramLooping; // Window Creation Loop, For FullScreen/Windowed Toggle // Between Fullscreen / Windowed Mode
static BOOL g_createFullScreen; // If true, Then Create Fullscreen
GL_Window window; // Window Structure
// TERMINATE APPLICATION
void TerminateApplication(GL_Window* window) // Terminate The Application
{
PostMessage(window->hWnd, WM_QUIT, 0, 0); // Send A WM_QUIT Message
g_isProgramLooping = FALSE; // Stop Looping Of The Program
}
// SWITCH FULLSCREEN / FENETRE
void ToggleFullscreen(GL_Window* window) // Toggle Fullscreen/Windowed
{
PostMessage(window->hWnd, WM_TOGGLEFULLSCREEN, 0, 0); // Send A WM_TOGGLEFULLSCREEN Message
}
// REPLACE CAMERA
void ReshapeGL(int width, int height) // Reshape The Window When It's Moved Or Resized
{
extern float ciblex, cibley, zoom_total;
glViewport(0, 0, (GLsizei)(width), (GLsizei)(height)); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
gluPerspective(45.0f, (GLfloat)(width)/ (GLfloat)(height), // Calculate The Aspect Ratio Of The Window
0.1f, 500.0f);
pcamera.x = pcamera.y = ciblex = cibley = zoom_total = 0;
pcamera.z = 20;
!game_3d ? angle_y = 0 : angle_y = -40; // si pas game_3d angle_y=0 sinon angle_y=40
!game_3d ? player[0].y = -6.15 : player[0].y = -7.00; // si pas game_3d ...
angle_x = 0;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt( pcamera.x, pcamera.y, pcamera.z, // la caméra
ciblex, cibley, 0, // la cible
0.0, 1.0, 0.0 ); // le haut
}
// CHANGE RESOLUTION
BOOL ChangeScreenResolution(int width, int height, int bitsPerPixel) // Change The Screen Resolution
{
DEVMODE dmScreenSettings; // Device Mode
ZeroMemory(&dmScreenSettings, sizeof(DEVMODE)); // Make Sure Memory Is Cleared
dmScreenSettings.dmSize = sizeof(DEVMODE); // Size Of The Devmode Structure
dmScreenSettings.dmPelsWidth = width; // Select Screen Width
dmScreenSettings.dmPelsHeight = height; // Select Screen Height
dmScreenSettings.dmBitsPerPel = bitsPerPixel; // Select Bits Per Pixel
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
return FALSE; // Display Change Failed, Return False
return TRUE; // Display Change Was Successful, Return True
}
void Fullscreen(void)
{
// fenêtre
//DWORD windowStyle = WS_OVERLAPPEDWINDOW; // Define Our Window Style
//DWORD windowExtendedStyle = WS_EX_APPWINDOW; // Define The Window's Extended Style
// fullscreen
DWORD windowStyle = WS_POPUP; // Set The WindowStyle To WS_POPUP (Popup Window)
DWORD windowExtendedStyle = WS_EX_TOPMOST; // Set The Extended Window Style To WS_EX_TOPMOST
// retrieve the resolution
HWND hDesktop = GetDesktopWindow();
HDC hDc = GetDC(hDesktop);
int w = GetDeviceCaps(hDc, PLANES) * GetDeviceCaps(hDc, HORZRES);
int h = GetDeviceCaps(hDc, PLANES) * GetDeviceCaps(hDc, VERTRES);
int bits = GetDeviceCaps(hDc, PLANES) * GetDeviceCaps(hDc, BITSPIXEL);
ReleaseDC(hDesktop, hDc);
// change style
DWORD dwStyle,dwNewStyle;
dwStyle = GetWindowLong(g_window->hWnd, (TRUE ? GWL_EXSTYLE : GWL_STYLE));
//dwNewStyle = (dwStyle & (~NULL)) | windowExtendedStyle;
//dwStyle = GetWindowLong(g_window->hWnd, GWL_EXSTYLE);
dwNewStyle = (dwStyle & (~NULL)) | windowExtendedStyle;
SetWindowLong(g_window->hWnd, (TRUE ? GWL_EXSTYLE : GWL_STYLE), dwNewStyle);
//SetWindowPos(g_window->hWnd,NULL,0,0,w,h,SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE);
//SetWindowLong(g_window->hWnd, GWL_EXSTYLE, dwNewStyle);
SetWindowPos(g_window->hWnd,NULL,0,0,w,h,SWP_NOZORDER);
}
// RETOURNE LA TAILLE DU BUREAU
void ReturnSystemMetrics(int *Width, int *Height, int *BitsPerPixel)
{
HWND hDesktop = GetDesktopWindow();
HDC hDc = GetDC(hDesktop);
*(Width) = GetDeviceCaps(hDc, PLANES) * GetDeviceCaps(hDc, HORZRES);
*(Height) = GetDeviceCaps(hDc, PLANES) * GetDeviceCaps(hDc, VERTRES);
*(BitsPerPixel) = GetDeviceCaps(hDc, PLANES) * GetDeviceCaps(hDc, BITSPIXEL);
ReleaseDC(hDesktop, hDc);
return;
// une autre méthode : HEIGHT = GetSystemMetrics(SM_CYSCREEN); WIDTH = GetSystemMetrics(SM_CXSCREEN);
}
//////////////////////////////////////////////////////////////////////////////////////
//
// DANS UN NOUVEAU THREAD - ESSAYE DE SE CONNECTER A INTERNET POUR DECLENCHER LA CONNEXION
// INTERNET ET EVENTUELLEMENT LE FIREWALL
//
void InternetConnect(void* dummy)
{
static bool already_tried = false;
if (already_tried) return;
InternetAttemptConnect(0);
HINTERNET my_internet = InternetOpen("Microsoft Internet Explorer", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, NULL);
if (InternetOpenUrl(my_internet, "http://www.google.com", NULL, NULL, NULL, NULL) == NULL)
{
if (GetLastError() == ERROR_INTERNET_EXTENDED_ERROR)
{
char buf[2000];
DWORD e, l=sizeof (buf);
InternetGetLastResponseInfo (&e, buf, &l);
MessageBox(g_hwndDlg, buf, "Internet Error", MB_APPLMODAL);
}
else
MessageBox(g_hwndDlg, "Info : Internet connection can't be used.", "Warning", MB_APPLMODAL);
}
already_tried = true;
_endthread();
}
//////////////////////////////////////////////////////////////////////////////////////
//
// CREATE WINDOW GL
//
//
BOOL CreateWindowGL(GL_Window* window) // This Code Creates Our OpenGL Window
{
DWORD windowStyle = WS_OVERLAPPEDWINDOW; // Define Our Window Style
DWORD windowExtendedStyle = WS_EX_APPWINDOW; // Define The Window's Extended Style
PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
window->init.bitsPerPixel, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // No Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
16, // 16Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};
RECT windowRect = {0, 0, window->init.width, window->init.height}; // Define Our Window Coordinates
GLuint PixelFormat; // Will Hold The Selected Pixel Format
// quick fullscreen mode
if (window->init.quickFullScreen == TRUE)
{
ShowCursor(TRUE); // Turn Off The Cursor
windowStyle = WS_POPUP; // Set The WindowStyle To WS_POPUP (Popup Window)
windowExtendedStyle |= WS_EX_TOPMOST; // Set The Extended Window Style To WS_EX_TOPMOST
} // (Top Window Covering Everything Else)
// fullscreen mode
else if (window->init.isFullScreen == TRUE) // Fullscreen Requested, Try Changing Video Modes
{
if (ChangeScreenResolution(window->init.width, window->init.height, window->init.bitsPerPixel))
{
ShowCursor(TRUE); // Turn On The Cursor
windowStyle = WS_POPUP; // Set The WindowStyle To WS_POPUP (Popup Window)
windowExtendedStyle |= WS_EX_TOPMOST; // Set The Extended Window Style To WS_EX_TOPMOST
} // (Top Window Covering Everything Else)
else
{
MessageBox(HWND_DESKTOP, "Mode Switch Failed.\nRunning In Windowed Mode.", "Error", MB_OK | MB_ICONEXCLAMATION);
window->init.isFullScreen = FALSE; // Set isFullscreen To False (Windowed Mode)
}
}
// window mode
else // If Fullscreen Was Not Selected
{
AdjustWindowRectEx(&windowRect, windowStyle, 0, windowExtendedStyle);// Adjust Window, Account For Window Borders
}
// window position (will be centered for the "window mode")
int left_pos = 0;
int top_pos = 0;
if (!window->init.isFullScreen && !window->init.quickFullScreen)
{
HWND hDesktop = GetDesktopWindow();
HDC hDc = GetDC(hDesktop);
int desktop_width = GetDeviceCaps(hDc, PLANES) * GetDeviceCaps(hDc, HORZRES);
int desktop_height = GetDeviceCaps(hDc, PLANES) * GetDeviceCaps(hDc, VERTRES);
ReleaseDC(hDesktop, hDc);
if (window->init.width < desktop_width && window->init.height < desktop_height) // on ne centre que si la fenêtre est + petite que le bureau
{
left_pos = desktop_width / 2 - window->init.width / 2;
top_pos = desktop_height / 2 - window->init.height / 2 - 40;
}
}
// Create The Game Window
window->hWnd = CreateWindowEx(windowExtendedStyle, // Extended Style
window->init.application->className, // Class Name
window->init.title, // Window Title
windowStyle, // Window Style
left_pos, top_pos, // Window X,Y Position
windowRect.right - windowRect.left, // Window Width
windowRect.bottom - windowRect.top, // Window Height
HWND_DESKTOP, // Desktop Is Window's Parent
0, // No Menu
window->init.application->hInstance, // Pass The Window Instance
window);
if (window->hWnd == 0) // Was Window Creation A Success?
return FALSE; // If Not Return False
// Get a Device Context for this Window
window->hDC = GetDC(window->hWnd); // Grab A Device Context
if (window->hDC == 0) // Did We Get A Device Context?
{
DestroyWindow(window->hWnd); // Destroy The Window
window->hWnd = 0; // Zero The Window Handle
return FALSE; // Return False
}
// Anti-aliasing
//
// Our first pass, Multisampling hasn't been created yet, so we create a window normally
// If it is supported, then we're on our second pass
// that means we want to use our pixel format for sampling
// so set PixelFormat to arbMultiSampleformat instead
if(!arbMultisampleSupported)
{
PixelFormat = ChoosePixelFormat (window->hDC, &pfd); // Find A Compatible Pixel Format
if (PixelFormat == 0) // Did We Find A Compatible Format?
{
// Failed
ReleaseDC (window->hWnd, window->hDC); // Release Our Device Context
window->hDC = 0; // Zero The Device Context
DestroyWindow (window->hWnd); // Destroy The Window
window->hWnd = 0; // Zero The Window Handle
return FALSE; // Return False
}
}
else
PixelFormat = arbMultisampleFormat;
if (SetPixelFormat (window->hDC, PixelFormat, &pfd) == FALSE) // Try To Set The Pixel Format
{
// Failed
ReleaseDC (window->hWnd, window->hDC); // Release Our Device Context
window->hDC = 0; // Zero The Device Context
DestroyWindow (window->hWnd); // Destroy The Window
window->hWnd = 0; // Zero The Window Handle
return FALSE; // Return False
}
window->hRC = wglCreateContext (window->hDC); // Try To Get A Rendering Context
if (window->hRC == 0) // Did We Get A Rendering Context?
{
// Failed
ReleaseDC (window->hWnd, window->hDC); // Release Our Device Context
window->hDC = 0; // Zero The Device Context
DestroyWindow (window->hWnd); // Destroy The Window
window->hWnd = 0; // Zero The Window Handle
return FALSE; // Return False
}
// Make The Rendering Context Our Current Rendering Context
if (wglMakeCurrent (window->hDC, window->hRC) == FALSE)
{
// Failed
wglDeleteContext (window->hRC); // Delete The Rendering Context
window->hRC = 0; // Zero The Rendering Context
ReleaseDC (window->hWnd, window->hDC); // Release Our Device Context
window->hDC = 0; // Zero The Device Context
DestroyWindow (window->hWnd); // Destroy The Window
window->hWnd = 0; // Zero The Window Handle
return FALSE; // Return False
}
/*
Now that our window is created, we want to query what samples are available
we call our InitMultiSample window
if we return a valid context, we want to destroy our current window
and create a new one using the multisample interface.
*/
if(!arbMultisampleSupported && game_option_anti_aliasing)
{
if(InitMultisample(window->init.application->hInstance,window->hWnd,pfd))
{
// Anti-aliasing disponible
DestroyWindowGL (window); // on détruit la fenêtre actuelle,
return CreateWindowGL(window); // et on relance la fonction dans laquelle
// on se trouve pour recréer une nouvelle
// fenêtre avec l'interface multisample !
}
}
// For text in loading screen
glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_FASTEST);
ShowWindow(window->hWnd, SW_NORMAL); // Make The Window Visible
window->isVisible = TRUE; // Set isVisible To True
ReshapeGL(window->init.width, window->init.height); // Reshape Our GL Window
ZeroMemory(window->keys, sizeof(Keys)); // Clear All Keys
return TRUE; // Window Creating Was A Success
// Initialization Will Be Done In WM_CREATE
}
//////////////////////////////////////////////////////////////////////////////////////
//
// DESTROY WINDOW GL
//
//
BOOL DestroyWindowGL(GL_Window* window) // Destroy The OpenGL Window & Release Resources
{
if (window->hWnd != 0) // Does The Window Have A Handle?
{
if (window->hDC != 0) // Does The Window Have A Device Context?
{
wglMakeCurrent(window->hDC, 0); // Set The Current Active Rendering Context To Zero
if (window->hRC != 0) // Does The Window Have A Rendering Context?
{
wglDeleteContext(window->hRC); // Release The Rendering Context
window->hRC = 0; // Zero The Rendering Context
}
ReleaseDC(window->hWnd, window->hDC); // Release The Device Context
window->hDC = 0; // Zero The Device Context
}
DestroyWindow(window->hWnd); // Destroy The Window
window->hWnd = 0; // Zero The Window Handle
}
if (window->init.isFullScreen) // Is Window In Fullscreen Mode
{
ChangeDisplaySettings(NULL, 0); // Switch Back To Desktop Resolution
ShowCursor(TRUE); // Show The Cursor
}
return TRUE; // Return True
}
//////////////////////////////////////////////////////////////////////////////////////
//
// Process Window Message Callbacks (GAME)
//
//
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
// Get The Window Context
GL_Window* window = (GL_Window*)(GetWindowLong(hWnd, GWL_USERDATA));
switch (uMsg) // Evaluate Window Message
{
case WM_SYSCOMMAND: // Intercept System Commands
{
switch (wParam) // Check System Calls
{
case SC_SCREENSAVE: // Screensaver Trying To Start?
case SC_MONITORPOWER: // Monitor Trying To Enter Powersave?
return 0; // Prevent From Happening
case SC_RESTORE:
{
//ShowWindow(window->hWnd, SW_SHOW);
//BOX("nono");
//return 0;
}
}
break; // Exit
}
return 0; // Return
case WM_CREATE: // Window Creation
{
CREATESTRUCT* creation = (CREATESTRUCT*)(lParam); // Store Window Structure Pointer
window = (GL_Window*)(creation->lpCreateParams);
SetWindowLong(hWnd, GWL_USERDATA, (LONG)(window));
}
return 0; // Return
case WM_CLOSE: // Closing The Window
TerminateApplication(window); // Terminate The Application
return 0; // Return
case WM_ENTERSIZEMOVE:
if (game_step == 2) // pendant le chargement on baisse la priorité
SetThreadPriority((void*)h_thread2, THREAD_PRIORITY_LOWEST);
return 0;
case WM_EXITSIZEMOVE:
{
if (game_step == 2) // pendant le chargement on remet en haute priorité
SetThreadPriority((void*)h_thread2, THREAD_PRIORITY_NORMAL );
else
SetThreadPriority((void*)h_thread2, THREAD_PRIORITY_NORMAL );
Fps_Reinitialize(); // FPS Méthode n°1 - To Avoid Jump Movement After Resize / Move
Fps2_firstpass = true; // FPS Méthode n°2
}
return 0;
case WM_SIZE: // Size Action Has Taken Place
switch (wParam) // Evaluate Size Action
{
case SIZE_MINIMIZED: // Was Window Minimized?
//BOX("minimized")
window->isVisible = FALSE; // Set isVisible To False
return 0; // Return
case SIZE_MAXIMIZED: // Was Window Maximized?
window->isVisible = TRUE; // Set isVisible To True
ReshapeGL(LOWORD(lParam), HIWORD(lParam)); // Reshape Window - LoWord=Width, HiWord=Height
window->init.width = LOWORD(lParam);
window->init.height = HIWORD(lParam);
Fps_Reinitialize(); // FPS Méthode n°1
Fps2_firstpass = true; // FPS Méthode n°2
return 0; // Return
case SIZE_RESTORED: // Was Window Restored?
window->isVisible = TRUE; // Set isVisible To True
ReshapeGL(LOWORD(lParam), HIWORD(lParam)); // Reshape Window - LoWord=Width, HiWord=Height
window->init.width = LOWORD(lParam);
window->init.height = HIWORD(lParam);
Fps_Reinitialize(); // FPS Méthode n°1
Fps2_firstpass = true; // FPS Méthode n°2
return 0; // Return
}
break; // Break
case WM_KEYDOWN: // Update Keyboard Buffers For Keys Pressed
if ((wParam >= 0) && (wParam <= 255)) // Is Key (wParam) In A Valid Range?
{
window->keys->keyDown[wParam] = TRUE; // Set The Selected Key (wParam) To True
if (game_option_wivik)
window->keys->wivik[wParam] = TRUE;
TCHAR temp[512];
wsprintf(temp,"%d",wParam);
//OutputDebugString(temp); // Pour savoir le code d'une touche pressée
return 0; // Return
}
break; // Break
case WM_KEYUP: // Update Keyboard Buffers For Keys Released
if ((wParam >= 0) && (wParam <= 255)) // Is Key (wParam) In A Valid Range?
{
window->keys->keyDown[wParam] = FALSE; // Set The Selected Key (wParam) To False
return 0; // Return
}
break; // Break
case WM_LBUTTONDOWN:
{
if (game_step != 4) return 0;
moving = true; // We are moving the scene
startx = LOWORD(lParam); // mouse x
starty = HIWORD(lParam); // mouse y
// largeur de résolution
int w = g_window->init.width;
// paliers de résolutions
int w2;
if (w >= 1600) w2 = 1600; else if (w >= 1280) w2 = 1280; else if (w >= 1024) w2 = 1024; else if (w >= 800) w2 = 800; else w2 = 640;
// déplacement equalizer (BOUTON ENFONÇÉ)
if (game_spectrum && w > 550)
if ((startx > equalizer_x+w+(-183)*w2/1024 && startx < equalizer_x+w+(-183+147)*w2/1024)
&& (starty > -equalizer_y+(+238-102)*w2/1024 && starty < -equalizer_y+238*w2/1024))
{
equalizer_moving = true; // l'equalizer est bougé
SetCursor(cur_hand_closed);
}
}
break;
case WM_LBUTTONUP:
{
// déplacement equalizer (BOUTON RELACHÉ)
if (equalizer_moving)
SetCursor(cur_hand);
moving = false; // We stop moving the scene
equalizer_moving = false; // We stop moving the equalizer
}
break;
case WM_MOUSEMOVE:
{
if (game_step != 4) return 0;
// largeur de résolution
int w = g_window->init.width;
// paliers de résolutions
int w2;
if (w >= 1600) w2 = 1600; else if (w >= 1280) w2 = 1280; else if (w >= 1024) w2 = 1024; else if (w >= 800) w2 = 800; else w2 = 640;
// equalizer (MOUSE OVER)
if (game_spectrum && w > 550)
if ((startx > equalizer_x+w+(-183)*w2/1024 && startx < equalizer_x+w+(-183+147)*w2/1024)
&& (starty > -equalizer_y+(+238-102)*w2/1024 && starty < -equalizer_y+238*w2/1024))
if (equalizer_moving)
SetCursor(cur_hand_closed);
else
SetCursor(cur_hand);
// déplacement equalizer (la souris est déplacée pendant que le bouton est pressé)
if (equalizer_moving)
{
equalizer_x += LOWORD(lParam) - startx;
equalizer_y += starty - HIWORD(lParam);
}
// rotation de la scène (bouton enfonçé mais pas sur l'équalizer)
else if (moving)
{
angle_x += (LOWORD(lParam) - startx) / 2; // souris axe x (/2 pour diminuer la vitesse)
angle_y += (HIWORD(lParam) - starty) / 2; // souris axe y (/2 pour diminuer la vitesse)
}
startx = LOWORD(lParam); // mouse x
starty = HIWORD(lParam); // mouse y
}
break;
case WM_TOGGLEFULLSCREEN: // Toggle FullScreen Mode On/Off
g_createFullScreen = (g_createFullScreen == TRUE) ? FALSE : TRUE;
PostMessage(hWnd, WM_QUIT, 0, 0);
break; // Break
}
return DefWindowProc(hWnd, uMsg, wParam, lParam); // Pass Unhandled Messages To DefWindowProc
}
//////////////////////////////////////////////////////////////////////////////////////
//
// REGISTER WINDOW CLASS
//
//
BOOL RegisterWindowClass(Application* application) // Register A Window Class For This Application.
{ // TRUE If Successful
// Register A Window Class
WNDCLASSEX windowClass; // Window Class
ZeroMemory(&windowClass, sizeof(WNDCLASSEX)); // Make Sure Memory Is Cleared
windowClass.cbSize = sizeof(WNDCLASSEX); // Size Of The windowClass Structure
windowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraws The Window For Any Movement / Resizing
windowClass.lpfnWndProc = (WNDPROC)(WindowProc); // WindowProc Handles Messages
windowClass.hInstance = application->hInstance; // Set The Instance
windowClass.hbrBackground = static_cast<HBRUSH>(GetStockObject(BLACK_BRUSH));// Class Background Brush Color
windowClass.hCursor = LoadCursor(application->hInstance, (LPCTSTR)IDC_CURSOR_CROSS);// Load The Arrow Pointer
windowClass.lpszClassName = application->className; // Sets The Applications Classname
windowClass.hIcon = LoadIcon(application->hInstance, (LPCTSTR)IDI_ICON_APP);
if (RegisterClassEx(&windowClass) == 0) // Did Registering The Class Fail?
{
// NOTE: Failure, Should Never Happen
MessageBox(HWND_DESKTOP, "RegisterClassEx Failed!", "Error", MB_OK | MB_ICONEXCLAMATION);
return FALSE; // Return False (Failure)
}
return TRUE; // Return True (Success)
}
//////////////////////////////////////////////////////////////////////////////////////
//
// THREAD - ON BAISSE LE VOLUME DE LA MUSIQUE
//
//
void FmodFadingOut(void* dummy)
{
int volume = 250;
do
{
volume -= 5;
FMUSIC_SetMasterVolume(my_mod_about,volume);
Sleep(10);
}
while(volume >= 0);
FMUSIC_StopSong(my_mod_about);
my_mod_about_on = false;
my_mod_about_working = false;
_endthread();
}
//////////////////////////////////////////////////////////////////////////////////////
//
// THREAD - ON AUGMENTE LE VOLUME DE LA MUSIQUE
//
//
void FmodFadingIn(void* dummy)
{
FMUSIC_SetMasterVolume(my_mod_about, 0);
if (!FMUSIC_IsPlaying(my_mod_about))
FMUSIC_PlaySong(my_mod_about);
my_mod_about_on = true;
int volume = 0;
do
{
volume += 5;
FMUSIC_SetMasterVolume(my_mod_about,volume);
Sleep(10);
}
while(volume <= 250);
my_mod_about_working = false;
_endthread();
}
//////////////////////////////////////////////////////////////////////////////////////
//
// THREAD - TRANSPARENCE DE LA FENETRE (WIN 2000/XP)
//
//
void DialogTransparency(void* dummy)
{
Sleep(250);
int alpha = 0;
DWORD dwStyle = GetWindowLong(g_hwndDlgAbout, GWL_EXSTYLE);
SetWindowLong(g_hwndDlgAbout, GWL_EXSTYLE, dwStyle | 0x00080000); // = WS_EX_LAYERED
#define LWA_ALPHA 0x00000002
SLWA_FUNC MySetLayeredWindowAttributes;
HMODULE hUser32 = GetModuleHandle("USER32.DLL");
if (!hUser32) _endthread();
MySetLayeredWindowAttributes = (SLWA_FUNC)GetProcAddress(hUser32,"SetLayeredWindowAttributes");
do
{
if (MySetLayeredWindowAttributes)
MySetLayeredWindowAttributes(g_hwndDlgAbout,NULL,alpha,LWA_ALPHA);
alpha += 30;
Sleep(2);
}
while(alpha <= 255);
// retour au mode normal
if (MySetLayeredWindowAttributes)
MySetLayeredWindowAttributes(g_hwndDlgAbout,NULL,255,LWA_ALPHA);
SetWindowLong(g_hwndDlgAbout,GWL_EXSTYLE,dwStyle & ~0x80000);
_endthread();
}
//////////////////////////////////////////////////////////////////////////////////////
//
// CALLBACK - DIALOG BOX ABOUT (readme...)
//
//
BOOL CALLBACK DialogAboutProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
g_hwndDlgAbout = hwndDlg; // Global handle
static HWND edit_handle = NULL;
switch (message)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDCANCEL: // close (escape) : hidden button (called automatically when the escape key is pressed)
case IDC_BUTTON_CLOSE: // close (button)
SendMessage(hwndDlg, WM_CLOSE, 0, 0);
return TRUE;
case IDC_BUTTON_MUTE:
{
if (!my_mod_about_working)
{
my_mod_about_working = true;
if (FMUSIC_IsPlaying(my_mod_about)) // stop the music
{
// place l'icône "MUSIQUE ON" dans le bouton
HICON hU = (HICON)LoadImage(window.init.application->hInstance, MAKEINTRESOURCE(IDB_BUTTON_PLAY), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
SendMessage(GetDlgItem(hwndDlg,IDC_BUTTON_MUTE), BM_SETIMAGE, IMAGE_BITMAP, (LPARAM) (DWORD) hU );
_beginthread( FmodFadingOut, 0, NULL );
}
else // start the music
{
// place l'icône "MUSIQUE OFF" dans le bouton
HICON hU = (HICON)LoadImage(window.init.application->hInstance, MAKEINTRESOURCE(IDB_BUTTON_MUTE), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
SendMessage(GetDlgItem(hwndDlg,IDC_BUTTON_MUTE), BM_SETIMAGE, IMAGE_BITMAP, (LPARAM) (DWORD) hU );
_beginthread( FmodFadingIn, 0, NULL );
}
}
}
return TRUE;
case IDC_HOMEPAGE:
ShellExecute(hwndDlg, "open", "http://spaceinvadersgl.sourceforge.net", NULL, NULL, SW_SHOWNORMAL);
return TRUE;
case IDC_MAIL:
ShellExecute(hwndDlg, "open", "https://sourceforge.net/forum/?group_id=74529", NULL, NULL, SW_SHOWNORMAL);
return TRUE;
case IDC_CHECK_WIVIK:
if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_WIVIK))
{
EnableWindow( GetDlgItem(hwndDlg,IDC_SLIDER_WIVIK), TRUE );
EnableWindow( GetDlgItem(hwndDlg,IDC_TEXT_WIVIK), TRUE );
game_option_wivik = true;
}
else
{
EnableWindow( GetDlgItem(hwndDlg,IDC_SLIDER_WIVIK), FALSE );
EnableWindow( GetDlgItem(hwndDlg,IDC_TEXT_WIVIK), FALSE );
game_option_wivik = false;
}
return TRUE;
}
switch (HIWORD(wParam))
{
case BN_CLICKED:
break;
}
return FALSE;
case WM_HSCROLL:
{
// GET SLIDER POSITION FOR WIVIK ON-SCREEN KEYBOARD
game_option_holddown_wivik = SendMessage(GetDlgItem(hwndDlg,IDC_SLIDER_WIVIK), TBM_GETPOS, 0, 0);
char message[512]="";
if (game_lang == 0 || game_lang == 2)
strcpy(message, "1 click = ");
else if (game_lang == 1)
strcpy(message, "1 clic = ");
char temp[10]="";
_ltoa(game_option_holddown_wivik, temp, 10);
strcat(message, temp);
if (game_lang == 0)
strcat(message, "ms hold down key");
else if (game_lang == 1)
strcat(message, "ms de touche appuyée");
else if (game_lang == 2)
strcat(message, "ms pulsación tecla abajo");
SetWindowText(GetDlgItem(hwndDlg,IDC_TEXT_WIVIK), message);
}
return TRUE;
case WM_CLOSE: // Close (X, Alt+F4) also called with escape key and close button (see IDCANCEL: and IDC_BUTTON_CLOSE:)
{
// SAUVEGARDE DANS LA BASE DE REGISTRE DU DELAI WIVIK ON-SCREEN KEYBOARD
HKEY key;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\SpaceInvaders-OpenGL\\", 0, KEY_WRITE, &key) == ERROR_SUCCESS)
{
// Wivik Activé ?
if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_WIVIK))
game_option_wivik = 1;
else
game_option_wivik = 0;
RegSetValueEx(key, "game_option_wivik", 0, REG_BINARY, (LPBYTE) &game_option_wivik, sizeof(bool));
// Wivik Délai
RegSetValueEx(key, "game_option_holddown_wivik", 0, REG_DWORD, (LPBYTE) &game_option_holddown_wivik, sizeof(DWORD));
}
RegCloseKey(key);
EndDialog(hwndDlg, TRUE);
}
return TRUE;
case WM_INITDIALOG:
{
//// FADING TRANSPARENCE
//// on met l'opacité à 0
//DWORD dwStyle = GetWindowLong(hwndDlg, GWL_EXSTYLE);
//SetWindowLong(hwndDlg, (TRUE ? GWL_EXSTYLE : GWL_STYLE), dwStyle | 0x00080000);
//#define LWA_ALPHA 0x00000002
//SLWA_FUNC MySetLayeredWindowAttributes;
//HMODULE hUser32 = GetModuleHandle("USER32.DLL");
//if (hUser32)
//{
// MySetLayeredWindowAttributes = (SLWA_FUNC)GetProcAddress(hUser32,"SetLayeredWindowAttributes");
// if (MySetLayeredWindowAttributes)
// MySetLayeredWindowAttributes(hwndDlg,NULL,0,LWA_ALPHA);
//}
//// on lance le thread qui augmente l'opacité
//_beginthread( DialogTransparency, 0, NULL );
// SLIDE BAR FOR WIVIK ON-SCREEN KEYBOARD
SendMessage(GetDlgItem(hwndDlg,IDC_SLIDER_WIVIK), TBM_SETRANGEMIN, TRUE, 100);
SendMessage(GetDlgItem(hwndDlg,IDC_SLIDER_WIVIK), TBM_SETRANGEMAX, TRUE, 500);
SendMessage(GetDlgItem(hwndDlg,IDC_SLIDER_WIVIK), TBM_SETPOS, TRUE, game_option_holddown_wivik);
char message[512]="";
if (game_lang == 0 || game_lang == 2)
strcpy(message, "1 click = ");
else if (game_lang == 1)
strcpy(message, "1 clic = ");
char temp[10]="";
_ltoa(game_option_holddown_wivik, temp, 10);
strcat(message, temp);
if (game_lang == 0)
strcat(message, "ms hold down key");
else if (game_lang == 1)
strcat(message, "ms de touche appuyée");
else if (game_lang == 2)
strcat(message, "ms pulsación tecla abajo");
SetWindowText(GetDlgItem(hwndDlg,IDC_TEXT_WIVIK), message);
if (game_option_wivik)
CheckDlgButton(hwndDlg, IDC_CHECK_WIVIK, BST_CHECKED);
else
{
EnableWindow( GetDlgItem(hwndDlg,IDC_SLIDER_WIVIK), FALSE );
EnableWindow( GetDlgItem(hwndDlg,IDC_TEXT_WIVIK), FALSE );
}
// HYPERLIENS
ConvertStaticToHyperlink(hwndDlg, IDC_HOMEPAGE);
ConvertStaticToHyperlink(hwndDlg, IDC_MAIL);
// EDIT BOX (fichier readme.txt)
edit_handle = CreateWindowEx(
WS_EX_CLIENTEDGE,
"EDIT",
NULL,
WS_CHILD | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_LEFT | ES_MULTILINE | ES_WANTRETURN,
10, 50,
553, 347,
hwndDlg,
NULL,
(HINSTANCE)GetWindowLong(hwndDlg, GWL_HINSTANCE),
NULL);
if(edit_handle == NULL)
MessageBox(NULL, "Could not create edit control!", "Error", MB_OK | MB_ICONERROR);
// on crée la nouvelle font
HFONT t_font = CreateFont(12, 0, 0, 0, FW_NORMAL, false, false, false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, 12, "Lucida Console");
SendMessage(edit_handle, WM_SETFONT, (WPARAM)t_font, MAKELONG(true, 0));
// on remplit l'Edit Box par le texte du fichier Readme.txt
HRSRC hrsrc;
if (game_lang == 0)
hrsrc = FindResource(0, MAKEINTRESOURCE(IDR_README_TXT), "TEXT");
else if (game_lang == 1)
hrsrc = FindResource(0, MAKEINTRESOURCE(IDR_README_FR_TXT), "TEXT");
else if (game_lang == 2)
hrsrc = FindResource(0, MAKEINTRESOURCE(IDR_README_ES_TXT), "TEXT");
HGLOBAL resource = LoadResource(0, hrsrc);
void* buffer = LockResource(resource);
unsigned int size = SizeofResource(NULL, hrsrc);
char* my_text = (char*)buffer;
UnlockResource(resource);
FreeResource(resource);
SendMessage(edit_handle, WM_SETTEXT, NULL, (LPARAM)my_text);
ShowWindow(edit_handle, SW_SHOW);
// Bouton musique (on/off)
static bool first = true;
if (my_mod_about_on || first)
{
// place l'icône "MUSIQUE OFF"
HICON hU = (HICON)LoadImage(window.init.application->hInstance, MAKEINTRESOURCE(IDB_BUTTON_MUTE), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
SendMessage(GetDlgItem(hwndDlg,IDC_BUTTON_MUTE), BM_SETIMAGE, IMAGE_BITMAP, (LPARAM) (DWORD) hU );
}
else
{
// place l'icône "MUSIQUE ON"
HICON hU = (HICON)LoadImage(window.init.application->hInstance, MAKEINTRESOURCE(IDB_BUTTON_PLAY), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
SendMessage(GetDlgItem(hwndDlg,IDC_BUTTON_MUTE), BM_SETIMAGE, IMAGE_BITMAP, (LPARAM) (DWORD) hU );
}
first = false;
// Translate the DialogBox
translate(1, hwndDlg);
return TRUE;
}
/*
// transparence de fenêtre windows à mettre dans WM_PAINT (à voir)
case WM_CREATE:
{
// Transparence de la fenêtre
// on ajoute le style WS_EX_LAYERED (0x00080000) à la DialogBox
DWORD dwStyle,dwNewStyle;
dwStyle = GetWindowLong(hwndDlg, (TRUE ? GWL_EXSTYLE : GWL_STYLE));
dwNewStyle = (dwStyle & (~NULL)) | 0x00080000;
SetWindowLong(hwndDlg, (TRUE ? GWL_EXSTYLE : GWL_STYLE), dwNewStyle);
SetWindowPos(hwndDlg,NULL,0,0,0,0,SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE);
// puis on règle l'alpha
#define WS_EX_LAYERED 0x00080000
#define LWA_COLORKEY 0x00000001
#define LWA_ALPHA 0x00000002
BYTE alpha=200,Anim=1;
SLWA_FUNC MySetLayeredWindowAttributes;
HMODULE hUser32 = GetModuleHandle("USER32.DLL");
if (!hUser32) return FALSE;
MySetLayeredWindowAttributes = (SLWA_FUNC)GetProcAddress(hUser32,"SetLayeredWindowAttributes");
if (MySetLayeredWindowAttributes)
MySetLayeredWindowAttributes(hwndDlg,NULL,alpha,LWA_ALPHA);
}*/
}
return FALSE; // DialogBox procedure must return FALSE for messages not handled.