-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwin_system.cpp
148 lines (124 loc) · 3.39 KB
/
win_system.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
/****************************************************************
xerxes engine
win_system.cpp
****************************************************************/
/**************** TODO *************
+ Redo VFILE* stuff and A_IMAGE.
+ fix strlwr in a_image
***********************************/
#include "xerxes.h"
/***************************** data *****************************/
HWND hMainWnd;
HINSTANCE hMainInst;
/****************************************************************/
bool AppIsForeground;
int DesktopBPP;
/***************************** code *****************************/
LRESULT APIENTRY WndProc(HWND hWnd, UINT message,WPARAM wParam, LPARAM lParam);
void HandleMessages();
int APIENTRY WinMain(HINSTANCE hCurrentInst, HINSTANCE zwhocares, LPSTR szCommandline, int nCmdShow)
{
WNDCLASS WndClass;
hMainInst = hCurrentInst;
memset(&WndClass, 0, sizeof(WNDCLASS));
WndClass.hCursor = LoadCursor(0, IDC_ARROW);
WndClass.hIcon = LoadIcon(NULL, MAKEINTRESOURCE(IDI_APPLICATION));
WndClass.lpszClassName = "xerxestype";
WndClass.hInstance = hMainInst;
WndClass.lpfnWndProc = WndProc;
RegisterClass(&WndClass);
hMainWnd = CreateWindowEx(0, "xerxestype", "xerxes", WS_VISIBLE | WS_OVERLAPPED | WS_THICKFRAME | WS_CAPTION, GetSystemMetrics(SM_CXSCREEN)/2-160, GetSystemMetrics(SM_CYSCREEN)/2-140, 320, 240, NULL, NULL, hMainInst, NULL);
ShowWindow(hMainWnd, SW_NORMAL);
UpdateWindow(hMainWnd);
HandleMessages();
AppIsForeground = true;
DesktopBPP = GetDeviceCaps(GetDC(NULL), BITSPIXEL);
SetWindowText(hMainWnd, APPNAME);
srand(timeGetTime());
log_Init(true);
mouse_Init();
InitKeyboard();
joy_Init();
timer_Init(100);
ShowCursor(0);
xmain(__argc,__argv);
err("");
return 0;
}
void HandleMessages(void)
{
MSG msg;
while (PeekMessage(&msg, hMainWnd, (int) NULL, (int) NULL, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
LRESULT APIENTRY WndProc(HWND hWnd, UINT message,WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CLOSE:
err("");
break;
case WM_ACTIVATE:
if (LOWORD(wParam) == WA_INACTIVE)
AppIsForeground = false;
else
AppIsForeground = true;
break;
case WM_ACTIVATEAPP:
if (!(BOOL)wParam)
AppIsForeground = false;
else
AppIsForeground = true;
return 0;
case WM_SYSCOMMAND:
if (wParam == SC_CLOSE)
err("");
break;
case WM_SYSKEYDOWN:
if (wParam == 'X')
err("");
if(wParam==VK_RETURN&&!(lParam&0x40000000))
{
if(!vid_SetMode(vid_xres,vid_yres,vid_bpp,!vid_window,MODE_SOFTWARE))
err("");
return 0;
}
return 0;
case WM_KEYDOWN: return 0;
case WM_KEYUP: return 0;
case WM_LBUTTONDOWN: mouse_l = true; break;
case WM_LBUTTONUP: mouse_l = false; break;
case WM_RBUTTONDOWN: mouse_r = true; break;
case WM_RBUTTONUP: mouse_r = false; break;
case WM_MBUTTONDOWN: mouse_m = true; break;
case WM_MBUTTONUP: mouse_m = false; break;
case WM_MOUSEWHEEL:
mwheel += (short) HIWORD(wParam);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
void err(char *str, ...)
{
va_list argptr;
char msg[256];
va_start(argptr, str);
vsprintf(msg, str, argptr);
va_end(argptr);
if(vid_Close)
{
vid_Close();
DestroyWindow(hMainWnd);
}
if (strlen(msg))
{
MessageBox(GetDesktopWindow(), msg, APPNAME, MB_OK | MB_TASKMODAL);
log("Exiting: %s", msg);
}
UseSound = false;
PostQuitMessage(0);
exit(strlen(msg)==0?0:-1);
}