[CRT] Remove useless #undef abort from process.h
[reactos.git] / dll / cpl / timedate / timedate.c
1 /*
2 * PROJECT: ReactOS Timedate Control Panel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/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 PWSTR 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, (PWSTR)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 static int CALLBACK
71 PropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam)
72 {
73 // NOTE: This callback is needed to set large icon correctly.
74 HICON hIcon;
75 switch (uMsg)
76 {
77 case PSCB_INITIALIZED:
78 {
79 hIcon = LoadIconW(hApplet, MAKEINTRESOURCEW(IDC_CPLICON));
80 SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
81 break;
82 }
83 }
84 return 0;
85 }
86
87 static LONG APIENTRY
88 Applet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
89 {
90 PROPSHEETHEADER psh;
91 PROPSHEETPAGEW psp[3];
92 LONG Ret = 0;
93
94 UNREFERENCED_PARAMETER(uMsg);
95 UNREFERENCED_PARAMETER(wParam);
96 UNREFERENCED_PARAMETER(lParam);
97
98 if (RegisterMonthCalControl(hApplet) &&
99 RegisterClockControl())
100 {
101 ZeroMemory(&psh, sizeof(PROPSHEETHEADERW));
102 psh.dwSize = sizeof(PROPSHEETHEADERW);
103 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_PROPTITLE | PSH_USEICONID | PSH_USECALLBACK;
104 psh.hwndParent = hwnd;
105 psh.hInstance = hApplet;
106 psh.pszIcon = MAKEINTRESOURCEW(IDC_CPLICON);
107 psh.pszCaption = MAKEINTRESOURCEW(IDS_CPLNAME);
108 psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGEW);
109 psh.nStartPage = 0;
110 psh.ppsp = psp;
111 psh.pfnCallback = PropSheetProc;
112
113 InitPropSheetPage(&psp[0], IDD_DATETIMEPAGE, DateTimePageProc);
114 InitPropSheetPage(&psp[1], IDD_TIMEZONEPAGE, TimeZonePageProc);
115 InitPropSheetPage(&psp[2], IDD_INETTIMEPAGE, InetTimePageProc);
116
117 Ret = (LONG)(PropertySheetW(&psh) != -1);
118
119 UnregisterMonthCalControl(hApplet);
120 UnregisterClockControl();
121 }
122
123 return Ret;
124 }
125
126
127 /* Control Panel Callback */
128 LONG CALLBACK
129 CPlApplet(HWND hwndCpl,
130 UINT uMsg,
131 LPARAM lParam1,
132 LPARAM lParam2)
133 {
134 UINT i = (UINT)lParam1;
135
136 switch (uMsg)
137 {
138 case CPL_INIT:
139 return TRUE;
140
141 case CPL_GETCOUNT:
142 return NUM_APPLETS;
143
144 case CPL_INQUIRE:
145 if (i < NUM_APPLETS)
146 {
147 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
148 CPlInfo->lData = 0;
149 CPlInfo->idIcon = Applets[i].idIcon;
150 CPlInfo->idName = Applets[i].idName;
151 CPlInfo->idInfo = Applets[i].idDescription;
152 }
153 else
154 {
155 return TRUE;
156 }
157 break;
158
159 case CPL_DBLCLK:
160 if (i < NUM_APPLETS)
161 Applets[i].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
162 else
163 return TRUE;
164 break;
165 }
166 return FALSE;
167 }
168
169
170 BOOL WINAPI
171 DllMain(HINSTANCE hinstDLL,
172 DWORD dwReason,
173 LPVOID lpReserved)
174 {
175 UNREFERENCED_PARAMETER(lpReserved);
176
177 switch (dwReason)
178 {
179 case DLL_PROCESS_ATTACH:
180 {
181 INITCOMMONCONTROLSEX InitControls;
182
183 InitControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
184 InitControls.dwICC = ICC_DATE_CLASSES | ICC_PROGRESS_CLASS | ICC_UPDOWN_CLASS;
185 InitCommonControlsEx(&InitControls);
186
187 hApplet = hinstDLL;
188 }
189 break;
190 }
191
192 return TRUE;
193 }