Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/ui/ui-drv/win32/about.c
blob: 22b040d9def81232a1648885f518e00f98ed561e (plain)
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
#include <windows.h>
#include "fconfig.h"
#include "xerror.h"
#include "ui_win32.h"
#include "about.h"
void CenterWindow(HWND hwndChild, HWND hwndParent)
{
    RECT rChild, rParent, rWorkArea;
    int wChild, hChild, wParent, hParent;
    int xNew, yNew;
    BOOL bResult;

    GetWindowRect(hwndChild, &rChild);
    wChild = rChild.right - rChild.left;
    hChild = rChild.bottom - rChild.top;

    GetWindowRect(hwndParent, &rParent);
    wParent = rParent.right - rParent.left;
    hParent = rParent.bottom - rParent.top;

    bResult = SystemParametersInfo(SPI_GETWORKAREA,	// system parameter to query or set
				   sizeof(RECT), &rWorkArea, 0);
    if (!bResult) {
	rWorkArea.left = rWorkArea.top = 0;
	rWorkArea.right = GetSystemMetrics(SM_CXSCREEN);
	rWorkArea.bottom = GetSystemMetrics(SM_CYSCREEN);
    }

    xNew = rParent.left + ((wParent - wChild) / 2);
    if (xNew < rWorkArea.left) {
	xNew = rWorkArea.left;
    } else if ((xNew + wChild) > rWorkArea.right) {
	xNew = rWorkArea.right - wChild;
    }

    yNew = rParent.top + ((hParent - hChild) / 2);
    if (yNew < rWorkArea.top) {
	yNew = rWorkArea.top;
    } else if ((yNew + hChild) > rWorkArea.bottom) {
	yNew = rWorkArea.bottom - hChild;
    }

    SetWindowPos(hwndChild, NULL, xNew, yNew, 0, 0,
		 SWP_NOSIZE | SWP_NOZORDER);
    return;
}


static LPTSTR GetStringRes(int id)
{
    static TCHAR buffer[MAX_PATH];

    buffer[0] = 0;
    LoadString(GetModuleHandle(NULL), id, buffer, MAX_PATH);
    return buffer;
}

static LRESULT CALLBACK
About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    static HFONT hfontDlg;	// Font for dialog text
    static HFONT hFinePrint;	// Font for 'fine print' in dialog
    DWORD dwVerInfoSize;	// Size of version information block
    LPSTR lpVersion;		// String pointer to 'version' text
    DWORD dwVerHnd = 0;		// An 'ignored' parameter, always '0'
    UINT uVersionLen;
    WORD wRootLen;
    BOOL bRetCode;
    int i;
    char szFullPath[256];
    char szResult[256];
    char szGetName[256];
    DWORD dwVersion;
    char szVersion[40];
    DWORD dwResult;

    switch (message) {
    case WM_INITDIALOG:
	ShowWindow(hDlg, SW_HIDE);

	if (PRIMARYLANGID(GetUserDefaultLangID()) == LANG_JAPANESE) {
	    hfontDlg =
		CreateFont(14, 0, 0, 0, 0, 0, 0, 0, SHIFTJIS_CHARSET, 0, 0,
			   0, VARIABLE_PITCH | FF_DONTCARE, "");
	    hFinePrint =
		CreateFont(11, 0, 0, 0, 0, 0, 0, 0, SHIFTJIS_CHARSET, 0, 0,
			   0, VARIABLE_PITCH | FF_DONTCARE, "");
	} else {
	    hfontDlg = CreateFont(14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
				  VARIABLE_PITCH | FF_SWISS, "");
	    hFinePrint = CreateFont(11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
				    VARIABLE_PITCH | FF_SWISS, "");
	}

	CenterWindow(hDlg, GetWindow(hDlg, GW_OWNER));
	GetModuleFileName(hInstance, szFullPath, sizeof(szFullPath));
#if 0
	// Now lets dive in and pull out the version information:
	dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd);
	if (dwVerInfoSize) {
	    LPSTR lpstrVffInfo;
	    HANDLE hMem;
	    hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
	    lpstrVffInfo = GlobalLock(hMem);
	    GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize,
			       lpstrVffInfo);
	    // The below 'hex' value looks a little confusing, but
	    // essentially what it is, is the hexidecimal representation
	    // of a couple different values that represent the language
	    // and character set that we are wanting string values for.
	    // 040904E4 is a very common one, because it means:
	    //   US English, Windows MultiLingual characterset
	    // Or to pull it all apart:
	    // 04------        = SUBLANG_ENGLISH_USA
	    // --09----        = LANG_ENGLISH
	    // --11----        = LANG_JAPANESE
	    // ----04E4 = 1252 = Codepage for Windows:Multilingual

	    lstrcpy(szGetName, GetStringRes(IDS_VER_INFO_LANG));

	    wRootLen = (WORD) lstrlen(szGetName);	// Save this position

	    // Set the title of the dialog:
	    lstrcat(szGetName, "ProductName");
	    bRetCode = VerQueryValue((LPVOID) lpstrVffInfo,
				     (LPSTR) szGetName,
				     (LPVOID) & lpVersion,
				     (UINT *) & uVersionLen);

	    // Notice order of version and string...
	    if (PRIMARYLANGID(GetUserDefaultLangID()) == LANG_JAPANESE) {
		lstrcpy(szResult, lpVersion);
		lstrcat(szResult, " のバージョン情報");
	    } else {
		lstrcpy(szResult, "About ");
		lstrcat(szResult, lpVersion);
	    }

	    // -----------------------------------------------------

	    SetWindowText(hDlg, szResult);

	    // Walk through the dialog items that we want to replace:
	    for (i = DLG_VERFIRST; i <= DLG_VERLAST; i++) {
		GetDlgItemText(hDlg, i, szResult, sizeof(szResult));
		szGetName[wRootLen] = (char) 0;
		lstrcat(szGetName, szResult);
		uVersionLen = 0;
		lpVersion = NULL;
		x_message("lpstrVffInfo %s", lpstrVffInfo);
		bRetCode = VerQueryValue((LPVOID) lpstrVffInfo,
					 (LPSTR) szGetName,
					 (LPVOID) & lpVersion,
					 (UINT *) & uVersionLen);

		if (bRetCode && uVersionLen && lpVersion) {
		    // Replace dialog item text with version info
		    lstrcpy(szResult, lpVersion);
		    SetDlgItemText(hDlg, i, szResult);
		} else {
		    dwResult = GetLastError();

		    wsprintf(szResult, GetStringRes(IDS_VERSION_ERROR),
			     dwResult);
		    SetDlgItemText(hDlg, i, szResult);
		}
		SendMessage(GetDlgItem(hDlg, i), WM_SETFONT,
			    /* (ULONG_PTR) */
			    (unsigned long *) ((i == DLG_VERLAST) ?
					       hFinePrint : hfontDlg),
			    TRUE);
	    }			// for (i = DLG_VERFIRST; i <= DLG_VERLAST; i++)


	    GlobalUnlock(hMem);
	    GlobalFree(hMem);
	} else {
	    // No version information available.
	}			// if (dwVerInfoSize)
#endif
	for (i = DLG_VERFIRST; i <= IDC_LICENSE; i++) {
	    SendMessage(GetDlgItem(hDlg, i), WM_SETFONT,
			/* (ULONG_PTR) */
			(unsigned long *) ((i == DLG_VERLAST) ? hFinePrint
					   : hfontDlg), TRUE);
	}			// for (i = DLG_VERFIRST; i <= DLG_VERLAST; i++)

	SendMessage(GetDlgItem(hDlg, IDC_LABEL), WM_SETFONT,
		    (WPARAM) hfontDlg, (LPARAM) TRUE);

	// We are  using GetVersion rather then GetVersionEx
	// because earlier versions of Windows NT and Win32s
	// didn't include GetVersionEx:
	dwVersion = GetVersion();

	if (dwVersion < 0x80000000) {
	    // Windows NT
	    wsprintf(szVersion, "Microsoft Windows NT %u.%u (Build: %u)",
		     (DWORD) (LOBYTE(LOWORD(dwVersion))),
		     (DWORD) (HIBYTE(LOWORD(dwVersion))),
		     (DWORD) (HIWORD(dwVersion)));
	} else if (LOBYTE(LOWORD(dwVersion)) < 4) {
	    // Win32s
	    wsprintf(szVersion, "Microsoft Win32s %u.%u (Build: %u)",
		     (DWORD) (LOBYTE(LOWORD(dwVersion))),
		     (DWORD) (HIBYTE(LOWORD(dwVersion))),
		     (DWORD) (HIWORD(dwVersion) & ~0x8000));
	} else {
	    // Windows 95
	    wsprintf(szVersion, "Microsoft Windows 95 %u.%u",
		     (DWORD) (LOBYTE(LOWORD(dwVersion))),
		     (DWORD) (HIBYTE(LOWORD(dwVersion))));
	}

	SetWindowText(GetDlgItem(hDlg, IDC_OSVERSION), szVersion);
	ShowWindow(hDlg, SW_SHOW);
	return (TRUE);

    case WM_COMMAND:
	if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
	    EndDialog(hDlg, TRUE);
	    DeleteObject(hfontDlg);
	    DeleteObject(hFinePrint);
	    return (TRUE);
	}
	break;
    }

    return FALSE;
}

void AboutBox(void)
{
#ifdef DDRAW_DRIVER
    if (directX == 1)
	return;
#endif
    DialogBox(hInstance, "AboutBox", hWnd, (DLGPROC) About);
}