1 /* 2 * PROJECT: ReactOS Console Configuration DLL 3 * LICENSE: GPL - See COPYING in the top level directory 4 * FILE: dll/win32/console/console.c 5 * PURPOSE: initialization of DLL 6 * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@student.tugraz.at) 7 */ 8 9 #include "console.h" 10 11 #define NUM_APPLETS (1) 12 #define WM_SETCONSOLE (WM_USER+10) 13 14 15 LONG APIENTRY InitApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam); 16 INT_PTR CALLBACK OptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); 17 INT_PTR CALLBACK FontProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); 18 INT_PTR CALLBACK LayoutProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); 19 INT_PTR CALLBACK ColorsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); 20 21 HINSTANCE hApplet = 0; 22 23 /* Applets */ 24 APPLET Applets[NUM_APPLETS] = 25 { 26 {IDC_CPLICON, IDS_CPLNAME, IDS_CPLDESCRIPTION, InitApplet} 27 }; 28 29 static COLORREF s_Colors[] = 30 { 31 RGB(0, 0, 0), 32 RGB(0, 0, 128), 33 RGB(0, 128, 0), 34 RGB(0, 128, 128), 35 RGB(128, 0, 0), 36 RGB(128, 0, 128), 37 RGB(128, 128, 0), 38 RGB(192, 192, 192), 39 RGB(128, 128, 128), 40 RGB(0, 0, 255), 41 RGB(0, 255, 0), 42 RGB(0, 255, 255), 43 RGB(255, 0, 0), 44 RGB(255, 0, 255), 45 RGB(255, 255, 0), 46 RGB(255, 255, 255) 47 }; 48 49 static void 50 InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc, LPARAM lParam) 51 { 52 ZeroMemory(psp, sizeof(PROPSHEETPAGE)); 53 psp->dwSize = sizeof(PROPSHEETPAGE); 54 psp->dwFlags = PSP_DEFAULT; 55 psp->hInstance = hApplet; 56 psp->pszTemplate = MAKEINTRESOURCE(idDlg); 57 psp->pfnDlgProc = DlgProc; 58 psp->lParam = lParam; 59 } 60 61 PConsoleInfo 62 AllocConsoleInfo() 63 { 64 PConsoleInfo pConInfo; 65 66 pConInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ConsoleInfo)); 67 68 return pConInfo; 69 } 70 71 void 72 InitConsoleDefaults(PConsoleInfo pConInfo) 73 { 74 /* Initialize struct */ 75 pConInfo->InsertMode = TRUE; 76 pConInfo->HistoryBufferSize = 50; 77 pConInfo->NumberOfHistoryBuffers = 5; 78 pConInfo->ScreenText = RGB(192, 192, 192); 79 pConInfo->ScreenBackground = RGB(0, 0, 0); 80 pConInfo->PopupText = RGB(128, 0, 128); 81 pConInfo->PopupBackground = RGB(255, 255, 255); 82 pConInfo->WindowSize = (DWORD)MAKELONG(80, 25); 83 pConInfo->WindowPosition = UINT_MAX; 84 pConInfo->ScreenBuffer = MAKELONG(80, 300); 85 pConInfo->UseRasterFonts = TRUE; 86 pConInfo->FontSize = (DWORD)MAKELONG(8, 12); 87 pConInfo->FontWeight = FW_NORMAL; 88 memcpy(pConInfo->Colors, s_Colors, sizeof(s_Colors)); 89 } 90 91 92 INT_PTR 93 CALLBACK 94 ApplyProc( 95 HWND hwndDlg, 96 UINT uMsg, 97 WPARAM wParam, 98 LPARAM lParam 99 ) 100 { 101 HWND hDlgCtrl; 102 103 UNREFERENCED_PARAMETER(lParam); 104 105 switch(uMsg) 106 { 107 case WM_INITDIALOG: 108 { 109 hDlgCtrl = GetDlgItem(hwndDlg, IDC_RADIO_APPLY_CURRENT); 110 SendMessage(hDlgCtrl, BM_SETCHECK, BST_CHECKED, 0); 111 return TRUE; 112 } 113 case WM_COMMAND: 114 { 115 if (LOWORD(wParam) == IDOK) 116 { 117 hDlgCtrl = GetDlgItem(hwndDlg, IDC_RADIO_APPLY_CURRENT); 118 if ( SendMessage(hDlgCtrl, BM_GETCHECK, 0, 0) == BST_CHECKED ) 119 EndDialog(hwndDlg, IDC_RADIO_APPLY_CURRENT); 120 else 121 EndDialog(hwndDlg, IDC_RADIO_APPLY_ALL); 122 } 123 else if (LOWORD(wParam) == IDCANCEL) 124 { 125 EndDialog(hwndDlg, IDCANCEL); 126 } 127 break; 128 } 129 default: 130 break; 131 } 132 return FALSE; 133 134 } 135 136 void 137 ApplyConsoleInfo(HWND hwndDlg, PConsoleInfo pConInfo) 138 { 139 INT_PTR res = 0; 140 141 res = DialogBox(hApplet, MAKEINTRESOURCE(IDD_APPLYOPTIONS), hwndDlg, ApplyProc); 142 143 if (res == IDCANCEL) 144 { 145 /* Don't destroy when user presses cancel */ 146 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE); 147 } 148 else if ( res == IDC_RADIO_APPLY_ALL ) 149 { 150 pConInfo->AppliedConfig = TRUE; 151 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, PSNRET_NOERROR); 152 SendMessage(pConInfo->hConsoleWindow, PM_APPLY_CONSOLE_INFO, (WPARAM)pConInfo, (LPARAM)TRUE); 153 } 154 else if ( res == IDC_RADIO_APPLY_CURRENT ) 155 { 156 pConInfo->AppliedConfig = TRUE; 157 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, PSNRET_NOERROR); 158 SendMessage(pConInfo->hConsoleWindow, PM_APPLY_CONSOLE_INFO, (WPARAM)pConInfo, (LPARAM)TRUE); 159 } 160 } 161 162 /* First Applet */ 163 LONG APIENTRY 164 InitApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam) 165 { 166 PROPSHEETPAGE psp[4]; 167 PROPSHEETHEADER psh; 168 INT i=0; 169 PConsoleInfo pConInfo; 170 WCHAR szTitle[100]; 171 PConsoleInfo pSharedInfo = (PConsoleInfo)wParam; 172 173 UNREFERENCED_PARAMETER(uMsg); 174 175 /* 176 * console.dll shares information with win32csr with wParam, lParam 177 * 178 * wParam is a pointer to a ConsoleInfo struct 179 * lParam is a boolean parameter which specifies whether defaults should be shown 180 */ 181 182 pConInfo = AllocConsoleInfo(); 183 if (!pConInfo) 184 { 185 return 0; 186 } 187 188 if (lParam) 189 { 190 /* Use defaults */ 191 InitConsoleDefaults(pConInfo); 192 } 193 else 194 { 195 if (IsBadReadPtr((const void *)pSharedInfo, sizeof(ConsoleInfo))) 196 { 197 /* Use defaults */ 198 InitConsoleDefaults(pConInfo); 199 } 200 else 201 { 202 pConInfo->InsertMode = pSharedInfo->InsertMode; 203 pConInfo->HistoryBufferSize = pSharedInfo->HistoryBufferSize; 204 pConInfo->NumberOfHistoryBuffers = pSharedInfo->NumberOfHistoryBuffers; 205 pConInfo->ScreenText = pSharedInfo->ScreenText; 206 pConInfo->ScreenBackground = pSharedInfo->ScreenBackground; 207 pConInfo->PopupText = pSharedInfo->PopupText; 208 pConInfo->PopupBackground = pSharedInfo->PopupBackground; 209 pConInfo->WindowSize = pSharedInfo->WindowSize; 210 pConInfo->WindowPosition = pSharedInfo->WindowPosition; 211 pConInfo->ScreenBuffer = pSharedInfo->ScreenBuffer; 212 pConInfo->UseRasterFonts = pSharedInfo->UseRasterFonts; 213 pConInfo->FontSize = pSharedInfo->FontSize; 214 pConInfo->FontWeight = pSharedInfo->FontWeight; 215 memcpy(pConInfo->Colors, pSharedInfo->Colors, sizeof(s_Colors)); 216 } 217 } 218 219 /* console window -> is notified on a property change event */ 220 pConInfo->hConsoleWindow = hwnd; 221 222 ZeroMemory(&psh, sizeof(PROPSHEETHEADER)); 223 psh.dwSize = sizeof(PROPSHEETHEADER); 224 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW; 225 if(_tcslen(pConInfo->szProcessName)) 226 { 227 psh.dwFlags |= PSH_PROPTITLE; 228 psh.pszCaption = pConInfo->szProcessName; 229 } 230 else 231 { 232 if (!GetConsoleTitleW(szTitle, sizeof(szTitle)/sizeof(WCHAR))) 233 { 234 _tcscpy(szTitle, _T("cmd.exe")); 235 } 236 szTitle[(sizeof(szTitle)/sizeof(WCHAR))-1] = _T('\0'); 237 psh.pszCaption = szTitle; 238 } 239 240 psh.hwndParent = hwnd; 241 psh.hInstance = hApplet; 242 psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDC_CPLICON)); 243 psh.nPages = 4; 244 psh.nStartPage = 0; 245 psh.ppsp = psp; 246 247 InitPropSheetPage(&psp[i++], IDD_PROPPAGEOPTIONS, (DLGPROC) OptionsProc, (LPARAM)pConInfo); 248 InitPropSheetPage(&psp[i++], IDD_PROPPAGEFONT, (DLGPROC) FontProc, (LPARAM)pConInfo); 249 InitPropSheetPage(&psp[i++], IDD_PROPPAGELAYOUT, (DLGPROC) LayoutProc, (LPARAM)pConInfo); 250 InitPropSheetPage(&psp[i++], IDD_PROPPAGECOLORS, (DLGPROC) ColorsProc, (LPARAM)pConInfo); 251 252 return (PropertySheet(&psh) != -1); 253 } 254 255 /* Control Panel Callback */ 256 LONG CALLBACK 257 CPlApplet( 258 HWND hwndCPl, 259 UINT uMsg, 260 LPARAM lParam1, 261 LPARAM lParam2) 262 { 263 switch(uMsg) 264 { 265 case CPL_INIT: 266 { 267 return TRUE; 268 } 269 case CPL_GETCOUNT: 270 { 271 return NUM_APPLETS; 272 } 273 case CPL_INQUIRE: 274 { 275 CPLINFO *CPlInfo = (CPLINFO*)lParam2; 276 CPlInfo->idIcon = Applets[0].idIcon; 277 CPlInfo->idName = Applets[0].idName; 278 CPlInfo->idInfo = Applets[0].idDescription; 279 break; 280 } 281 case CPL_DBLCLK: 282 { 283 InitApplet(hwndCPl, uMsg, lParam1, lParam2); 284 break; 285 } 286 } 287 return FALSE; 288 } 289 290 291 INT 292 WINAPI 293 DllMain( 294 HINSTANCE hinstDLL, 295 DWORD dwReason, 296 LPVOID lpvReserved) 297 { 298 UNREFERENCED_PARAMETER(lpvReserved); 299 300 switch(dwReason) 301 { 302 case DLL_PROCESS_ATTACH: 303 case DLL_THREAD_ATTACH: 304 hApplet = hinstDLL; 305 break; 306 } 307 return TRUE; 308 } 309