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 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 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 WCHAR Caption[256]; 93 LONG Ret = 0; 94 95 UNREFERENCED_PARAMETER(uMsg); 96 UNREFERENCED_PARAMETER(wParam); 97 UNREFERENCED_PARAMETER(lParam); 98 99 if (RegisterMonthCalControl(hApplet) && 100 RegisterClockControl()) 101 { 102 LoadStringW(hApplet, IDS_CPLNAME, Caption, sizeof(Caption) / sizeof(WCHAR)); 103 104 ZeroMemory(&psh, sizeof(PROPSHEETHEADERW)); 105 psh.dwSize = sizeof(PROPSHEETHEADERW); 106 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_PROPTITLE | PSH_USEICONID | PSH_USECALLBACK; 107 psh.hwndParent = hwnd; 108 psh.hInstance = hApplet; 109 psh.pszIcon = MAKEINTRESOURCEW(IDC_CPLICON); 110 psh.pszCaption = Caption; 111 psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGEW); 112 psh.nStartPage = 0; 113 psh.ppsp = psp; 114 psh.pfnCallback = PropSheetProc; 115 116 InitPropSheetPage(&psp[0], IDD_DATETIMEPAGE, DateTimePageProc); 117 InitPropSheetPage(&psp[1], IDD_TIMEZONEPAGE, TimeZonePageProc); 118 InitPropSheetPage(&psp[2], IDD_INETTIMEPAGE, InetTimePageProc); 119 120 Ret = (LONG)(PropertySheetW(&psh) != -1); 121 122 UnregisterMonthCalControl(hApplet); 123 UnregisterClockControl(); 124 } 125 126 return Ret; 127 } 128 129 130 /* Control Panel Callback */ 131 LONG CALLBACK 132 CPlApplet(HWND hwndCpl, 133 UINT uMsg, 134 LPARAM lParam1, 135 LPARAM lParam2) 136 { 137 INT i = (INT)lParam1; 138 139 switch (uMsg) 140 { 141 case CPL_INIT: 142 return TRUE; 143 144 case CPL_GETCOUNT: 145 return NUM_APPLETS; 146 147 case CPL_INQUIRE: 148 { 149 CPLINFO *CPlInfo = (CPLINFO*)lParam2; 150 CPlInfo->lData = 0; 151 CPlInfo->idIcon = Applets[i].idIcon; 152 CPlInfo->idName = Applets[i].idName; 153 CPlInfo->idInfo = Applets[i].idDescription; 154 } 155 break; 156 157 case CPL_DBLCLK: 158 { 159 Applets[i].AppletProc(hwndCpl, uMsg, lParam1, lParam2); 160 } 161 break; 162 } 163 return FALSE; 164 } 165 166 167 BOOL WINAPI 168 DllMain(HINSTANCE hinstDLL, 169 DWORD dwReason, 170 LPVOID lpReserved) 171 { 172 UNREFERENCED_PARAMETER(lpReserved); 173 174 switch (dwReason) 175 { 176 case DLL_PROCESS_ATTACH: 177 { 178 INITCOMMONCONTROLSEX InitControls; 179 180 InitControls.dwSize = sizeof(INITCOMMONCONTROLSEX); 181 InitControls.dwICC = ICC_DATE_CLASSES | ICC_PROGRESS_CLASS | ICC_UPDOWN_CLASS; 182 InitCommonControlsEx(&InitControls); 183 184 hApplet = hinstDLL; 185 } 186 break; 187 } 188 189 return TRUE; 190 } 191