-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
155 lines (133 loc) · 2.87 KB
/
main.c
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
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <shlwapi.h>
#include <shellapi.h>
#include "resources.h"
#include "thetisskinmaker.h"
#define CLASS_NAME L"Win32SkinMakerClass"
static BOOL
ShouldContinue(void)
{
WCHAR expanded[MAX_PATH];
if(!ExpandEnvironmentStringsW(THETIS_SKIN_PATH, expanded, MAX_PATH))
return FALSE;
if(!PathFileExistsW(expanded))
return FALSE;
return TRUE;
}
static LRESULT CALLBACK
AboutDlgProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch(msg)
{
case WM_INITDIALOG:
break;
case WM_COMMAND:
switch(LOWORD(wparam))
{
case IDOK:
EndDialog(hwnd, IDOK);
break;
case IDCANCEL:
EndDialog(hwnd, IDCANCEL);
}
default:
return FALSE;
}
return TRUE;
}
static LRESULT CALLBACK
WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch(msg)
{
case WM_CREATE:
OnCreate(hwnd);
break;
case WM_DESTROY:
if(imageBitmap)
{
DeleteObject(imageBitmap);
}
PostQuitMessage(0);
break;
case WM_COMMAND:
switch(LOWORD(wparam))
{
case IDM_HELP_ABOUT:
{
DialogBoxW(GetModuleHandle(NULL),
MAKEINTRESOURCEW(IDD_ABOUT),
hwnd,
AboutDlgProc);
}
break;
case IDC_PREVIEW_BUTTON:
OnPreviewButtonClick(hwnd);
break;
case IDC_IMAGE_BUTTON:
OnImageButtonClick(hwnd);
break;
case IDC_SAVE_BUTTON:
OnSaveButtonClick(hwnd);
break;
case IDC_NEW_BUTTON:
OnNewButtonClick(hwnd);
break;
}
break;
default:
return DefWindowProc(hwnd, msg, wparam, lparam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE instance,
HINSTANCE prevInstance,
LPSTR cmdLine,
int cmdShow)
{
WNDCLASSW wc = {0};
if(!ShouldContinue())
{
MessageBoxW(NULL,
L"No skins were found. Is Thetis installed properly?",
L"Skins Not Found",
MB_OK | MB_ICONERROR);
return -1;
}
wc.hbrBackground = (HBRUSH) COLOR_WINDOW;
wc.lpfnWndProc = WndProc;
wc.hInstance = instance;
wc.lpszMenuName = MAKEINTRESOURCEW(IDR_MAINMENU);
wc.lpszClassName = CLASS_NAME;
RegisterClassW(&wc);
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
int windowX = (screenWidth/2) - (WINDOW_WIDTH/2);
int windowY = (screenHeight/2) - (WINDOW_HEIGHT/2);
HWND hwnd = CreateWindowExW(0,
CLASS_NAME,
WINDOW_NAME,
WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX & ~WS_MAXIMIZEBOX,
windowX, /* x */
windowY, /* y */
WINDOW_WIDTH, /* width */
WINDOW_HEIGHT, /* height */
NULL,
NULL,
instance,
NULL);
if(!hwnd)
{
ERROR_BOX(L"Failed to create window!");
return -1;
}
ShowWindow(hwnd, cmdShow);
MSG msg = {0};
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}