fixed part of bug 910 change to ReactOS
[reactos.git] / reactos / lib / cpl / sysdm / general.c
1 /*
2 * ReactOS
3 * Copyright (C) 2004 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id$
20 *
21 * PROJECT: ReactOS System Control Panel
22 * FILE: lib/cpl/system/general.c
23 * PURPOSE: General System Information
24 * PROGRAMMER: Thomas Weidenmueller (w3seek@users.sourceforge.net)
25 * UPDATE HISTORY:
26 * 03-04-2004 Created
27 */
28 #include <windows.h>
29 #include <tchar.h>
30 #include <stdlib.h>
31
32 #include "resource.h"
33 #include "sysdm.h"
34
35 void
36 ShowLastWin32Error(HWND hWndOwner)
37 {
38 LPTSTR lpMsg;
39 DWORD LastError;
40
41 LastError = GetLastError();
42
43 if((LastError == 0) || !FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
44 FORMAT_MESSAGE_FROM_SYSTEM, NULL, LastError,
45 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPTSTR)&lpMsg, 0,
46 NULL))
47 {
48 return;
49 }
50
51 MessageBox(hWndOwner, lpMsg, NULL, MB_OK | MB_ICONERROR);
52
53 LocalFree((LPVOID)lpMsg);
54 }
55
56 typedef struct
57 {
58 HWND hDlg;
59 } OSITINFO, *POSITINFO;
60
61 DWORD WINAPI
62 ObtainSystemInformationThread(POSITINFO posit)
63 {
64 HRSRC hResInfo;
65 HGLOBAL hResMem;
66 WCHAR *LicenseText;
67
68 /* wait a bit */
69 Sleep(100);
70
71 /* load license from resource */
72 if(!(hResInfo = FindResource(hApplet, MAKEINTRESOURCE(RC_LICENSE),
73 MAKEINTRESOURCE(RTDATA))) ||
74 !(hResMem = LoadResource(hApplet, hResInfo)) ||
75 !(LicenseText = LockResource(hResMem)))
76 {
77 ShowLastWin32Error(posit->hDlg);
78 goto LoadSystemInfo;
79 }
80 /* insert the license into the edit control (unicode!) */
81 SetDlgItemText(posit->hDlg, IDC_LICENSEMEMO, LicenseText);
82 SendDlgItemMessage(posit->hDlg, IDC_LICENSEMEMO, EM_SETSEL, 0, 0);
83
84 LoadSystemInfo:
85 /* FIXME */
86 /*free:*/
87 HeapFree(GetProcessHeap(), 0, posit);
88
89 return 0;
90 }
91
92 /* Property page dialog callback */
93 INT_PTR CALLBACK
94 GeneralPageProc(
95 HWND hwndDlg,
96 UINT uMsg,
97 WPARAM wParam,
98 LPARAM lParam
99 )
100 {
101 switch(uMsg)
102 {
103 case WM_INITDIALOG:
104 {
105 HANDLE Thread;
106 DWORD ThreadId;
107 POSITINFO posit;
108
109 posit = (POSITINFO)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(OSITINFO));
110 if(!posit)
111 {
112 ShowLastWin32Error(hwndDlg);
113 return FALSE;
114 }
115 posit->hDlg = hwndDlg;
116 Thread = CreateThread(NULL,
117 0,
118 (LPTHREAD_START_ROUTINE)ObtainSystemInformationThread,
119 (PVOID)posit,
120 0,
121 &ThreadId);
122 if(Thread)
123 {
124 CloseHandle(Thread);
125 return FALSE;
126 }
127
128 break;
129 }
130 }
131 return FALSE;
132 }
133