1 /* 2 * PROJECT: input.dll 3 * FILE: dll/cpl/input/input.c 4 * PURPOSE: input.dll 5 * PROGRAMMER: Dmitry Chapyshev (lentind@yandex.ru) 6 * Colin Finck 7 * UPDATE HISTORY: 8 * 06-09-2007 Created 9 */ 10 11 #include "input.h" 12 13 #define NUM_APPLETS (1) 14 15 static LONG CALLBACK SystemApplet(HWND hwnd, UINT uMsg, LPARAM lParam1, LPARAM lParam2); 16 17 HINSTANCE hApplet = NULL; 18 BOOL g_bRebootNeeded = FALSE; 19 20 /* Applets */ 21 static APPLET Applets[NUM_APPLETS] = 22 { 23 {IDI_CPLSYSTEM, IDS_CPLSYSTEMNAME, IDS_CPLSYSTEMDESCRIPTION, SystemApplet} 24 }; 25 26 27 static VOID 28 InitPropSheetPage(PROPSHEETPAGEW *page, WORD idDlg, DLGPROC DlgProc) 29 { 30 ZeroMemory(page, sizeof(*page)); 31 32 page->dwSize = sizeof(*page); 33 page->dwFlags = PSP_DEFAULT; 34 page->hInstance = hApplet; 35 page->pszTemplate = MAKEINTRESOURCEW(idDlg); 36 page->pfnDlgProc = DlgProc; 37 } 38 39 static BOOL AskForReboot(HWND hwndDlg) 40 { 41 WCHAR szText[128], szCaption[64]; 42 LoadStringW(hApplet, IDS_REBOOT_NOW, szText, _countof(szText)); 43 LoadStringW(hApplet, IDS_LANGUAGE, szCaption, _countof(szCaption)); 44 return (MessageBoxW(hwndDlg, szText, szCaption, MB_ICONINFORMATION | MB_YESNO) == IDYES); 45 } 46 47 static int CALLBACK 48 PropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam) 49 { 50 switch (uMsg) 51 { 52 case PSCB_INITIALIZED: 53 { 54 /* Set large icon correctly */ 55 HICON hIcon = LoadIconW(hApplet, MAKEINTRESOURCEW(IDI_CPLSYSTEM)); 56 SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon); 57 break; 58 } 59 60 case PSCB_BUTTONPRESSED: 61 { 62 switch (lParam) 63 { 64 case PSBTN_OK: 65 case PSBTN_APPLYNOW: 66 { 67 if (g_bRebootNeeded && AskForReboot(hwndDlg)) 68 { 69 EnableProcessPrivileges(SE_SHUTDOWN_NAME, TRUE); 70 ExitWindowsEx(EWX_REBOOT | EWX_FORCE, 0); 71 } 72 break; 73 } 74 } 75 break; 76 } 77 } 78 return 0; 79 } 80 81 /* First Applet */ 82 static LONG CALLBACK 83 SystemApplet(HWND hwnd, UINT uMsg, LPARAM lParam1, LPARAM lParam2) 84 { 85 PROPSHEETPAGEW page[2]; 86 PROPSHEETHEADERW header; 87 88 ZeroMemory(&header, sizeof(header)); 89 90 header.dwSize = sizeof(header); 91 header.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK; 92 header.hwndParent = hwnd; 93 header.hInstance = hApplet; 94 header.pszIcon = MAKEINTRESOURCEW(IDI_CPLSYSTEM); 95 header.pszCaption = MAKEINTRESOURCEW(IDS_CPLSYSTEMNAME); 96 header.nPages = ARRAYSIZE(page); 97 header.nStartPage = 0; 98 header.ppsp = page; 99 header.pfnCallback = PropSheetProc; 100 101 /* Settings */ 102 InitPropSheetPage(&page[0], IDD_PROPPAGESETTINGS, SettingsPageProc); 103 104 /* Advanced Settings */ 105 InitPropSheetPage(&page[1], IDD_PROPPAGEADVANCEDSETTINGS, AdvancedSettingsPageProc); 106 107 return (LONG)(PropertySheetW(&header) != -1); 108 } 109 110 111 /* Control Panel Callback */ 112 LONG CALLBACK 113 CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2) 114 { 115 CPLINFO *CPlInfo; 116 UINT i = (UINT)lParam1; 117 118 switch (uMsg) 119 { 120 case CPL_INIT: 121 return TRUE; 122 123 case CPL_GETCOUNT: 124 return NUM_APPLETS; 125 126 case CPL_INQUIRE: 127 if (i < NUM_APPLETS) 128 { 129 CPlInfo = (CPLINFO*)lParam2; 130 CPlInfo->lData = 0; 131 CPlInfo->idIcon = Applets[i].idIcon; 132 CPlInfo->idName = Applets[i].idName; 133 CPlInfo->idInfo = Applets[i].idDescription; 134 } 135 else 136 { 137 return TRUE; 138 } 139 break; 140 141 case CPL_DBLCLK: 142 if (i < NUM_APPLETS) 143 Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2); 144 else 145 return TRUE; 146 break; 147 } 148 149 return FALSE; 150 } 151 152 153 BOOL WINAPI 154 DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved) 155 { 156 UNREFERENCED_PARAMETER(lpvReserved); 157 158 switch (dwReason) 159 { 160 case DLL_PROCESS_ATTACH: 161 case DLL_THREAD_ATTACH: 162 hApplet = hinstDLL; 163 break; 164 } 165 166 return TRUE; 167 } 168 169 /* EOF */ 170