[MSI]
[reactos.git] / reactos / dll / cpl / timedate / timedate.c
1 /*
2 * PROJECT: ReactOS Timedate Control Panel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: lib/cpl/timedate/timedate.c
5 * PURPOSE: ReactOS Timedate Control Panel
6 * COPYRIGHT: Copyright 2004-2005 Eric Kohl
7 * Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
8 *
9 */
10
11 #include <timedate.h>
12
13 #define NUM_APPLETS 1
14
15 static LONG APIENTRY Applet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam);
16
17 HINSTANCE hApplet;
18
19 /* Applets */
20 APPLET Applets[NUM_APPLETS] =
21 {
22 {IDC_CPLICON, IDS_CPLNAME, IDS_CPLDESCRIPTION, Applet}
23 };
24
25 #if DBG
26 VOID DisplayWin32ErrorDbg(DWORD dwErrorCode, const char *file, int line)
27 #else
28 VOID DisplayWin32Error(DWORD dwErrorCode)
29 #endif
30 {
31 LPVOID lpMsgBuf;
32 #if DBG
33 WCHAR szMsg[255];
34 #endif
35
36 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
37 FORMAT_MESSAGE_FROM_SYSTEM |
38 FORMAT_MESSAGE_IGNORE_INSERTS,
39 NULL,
40 dwErrorCode,
41 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
42 (LPWSTR) &lpMsgBuf,
43 0,
44 NULL );
45
46 #if DBG
47 if (swprintf(szMsg, L"%hs:%d: %s", file, line, lpMsgBuf))
48 {
49 MessageBoxW(NULL, szMsg, NULL, MB_OK | MB_ICONERROR);
50 }
51 #else
52 MessageBox(NULL, lpMsgBuf, NULL, MB_OK | MB_ICONERROR);
53 #endif
54
55 LocalFree(lpMsgBuf);
56 }
57
58
59 static VOID
60 InitPropSheetPage(PROPSHEETPAGEW *psp, WORD idDlg, DLGPROC DlgProc)
61 {
62 ZeroMemory(psp, sizeof(PROPSHEETPAGEW));
63 psp->dwSize = sizeof(PROPSHEETPAGEW);
64 psp->dwFlags = PSP_DEFAULT;
65 psp->hInstance = hApplet;
66 psp->pszTemplate = MAKEINTRESOURCEW(idDlg);
67 psp->pfnDlgProc = DlgProc;
68 }
69
70
71 static LONG APIENTRY
72 Applet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
73 {
74 PROPSHEETHEADER psh;
75 PROPSHEETPAGEW psp[3];
76 WCHAR Caption[256];
77 LONG Ret = 0;
78
79 UNREFERENCED_PARAMETER(uMsg);
80 UNREFERENCED_PARAMETER(wParam);
81 UNREFERENCED_PARAMETER(lParam);
82
83 if (RegisterMonthCalControl(hApplet) &&
84 RegisterClockControl())
85 {
86 LoadStringW(hApplet, IDS_CPLNAME, Caption, sizeof(Caption) / sizeof(WCHAR));
87
88 ZeroMemory(&psh, sizeof(PROPSHEETHEADERW));
89 psh.dwSize = sizeof(PROPSHEETHEADERW);
90 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_PROPTITLE;
91 psh.hwndParent = hwnd;
92 psh.hInstance = hApplet;
93 psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCEW(IDC_CPLICON));
94 psh.pszCaption = Caption;
95 psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGEW);
96 psh.nStartPage = 0;
97 psh.ppsp = psp;
98
99 InitPropSheetPage(&psp[0], IDD_DATETIMEPAGE, (DLGPROC) DateTimePageProc);
100 InitPropSheetPage(&psp[1], IDD_TIMEZONEPAGE, (DLGPROC) TimeZonePageProc);
101 InitPropSheetPage(&psp[2], IDD_INETTIMEPAGE, (DLGPROC) InetTimePageProc);
102
103 Ret = (LONG)(PropertySheetW(&psh) != -1);
104
105 UnregisterMonthCalControl(hApplet);
106 UnregisterClockControl();
107 }
108
109 return Ret;
110 }
111
112
113 /* Control Panel Callback */
114 LONG CALLBACK
115 CPlApplet(HWND hwndCpl,
116 UINT uMsg,
117 LPARAM lParam1,
118 LPARAM lParam2)
119 {
120 INT i = (INT)lParam1;
121
122 switch (uMsg)
123 {
124 case CPL_INIT:
125 return TRUE;
126
127 case CPL_GETCOUNT:
128 return NUM_APPLETS;
129
130 case CPL_INQUIRE:
131 {
132 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
133 CPlInfo->lData = 0;
134 CPlInfo->idIcon = Applets[i].idIcon;
135 CPlInfo->idName = Applets[i].idName;
136 CPlInfo->idInfo = Applets[i].idDescription;
137 }
138 break;
139
140 case CPL_DBLCLK:
141 {
142 Applets[i].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
143 }
144 break;
145 }
146 return FALSE;
147 }
148
149
150 BOOL WINAPI
151 DllMain(HINSTANCE hinstDLL,
152 DWORD dwReason,
153 LPVOID lpReserved)
154 {
155 UNREFERENCED_PARAMETER(lpReserved);
156
157 switch (dwReason)
158 {
159 case DLL_PROCESS_ATTACH:
160 {
161 INITCOMMONCONTROLSEX InitControls;
162
163 InitControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
164 InitControls.dwICC = ICC_DATE_CLASSES | ICC_PROGRESS_CLASS | ICC_UPDOWN_CLASS;
165 InitCommonControlsEx(&InitControls);
166
167 hApplet = hinstDLL;
168 }
169 break;
170 }
171
172 return TRUE;
173 }