Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenconsole.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Console Configuration DLL 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: dll/win32/console/console.c 00005 * PURPOSE: initialization of DLL 00006 * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@student.tugraz.at) 00007 */ 00008 00009 #include "console.h" 00010 00011 #define NUM_APPLETS (1) 00012 #define WM_SETCONSOLE (WM_USER+10) 00013 00014 00015 LONG APIENTRY InitApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam); 00016 INT_PTR CALLBACK OptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); 00017 INT_PTR CALLBACK FontProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); 00018 INT_PTR CALLBACK LayoutProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); 00019 INT_PTR CALLBACK ColorsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); 00020 00021 HINSTANCE hApplet = 0; 00022 00023 /* Applets */ 00024 APPLET Applets[NUM_APPLETS] = 00025 { 00026 {IDC_CPLICON, IDS_CPLNAME, IDS_CPLDESCRIPTION, InitApplet} 00027 }; 00028 00029 static COLORREF s_Colors[] = 00030 { 00031 RGB(0, 0, 0), 00032 RGB(0, 0, 128), 00033 RGB(0, 128, 0), 00034 RGB(0, 128, 128), 00035 RGB(128, 0, 0), 00036 RGB(128, 0, 128), 00037 RGB(128, 128, 0), 00038 RGB(192, 192, 192), 00039 RGB(128, 128, 128), 00040 RGB(0, 0, 255), 00041 RGB(0, 255, 0), 00042 RGB(0, 255, 255), 00043 RGB(255, 0, 0), 00044 RGB(255, 0, 255), 00045 RGB(255, 255, 0), 00046 RGB(255, 255, 255) 00047 }; 00048 00049 static void 00050 InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc, LPARAM lParam) 00051 { 00052 ZeroMemory(psp, sizeof(PROPSHEETPAGE)); 00053 psp->dwSize = sizeof(PROPSHEETPAGE); 00054 psp->dwFlags = PSP_DEFAULT; 00055 psp->hInstance = hApplet; 00056 psp->pszTemplate = MAKEINTRESOURCE(idDlg); 00057 psp->pfnDlgProc = DlgProc; 00058 psp->lParam = lParam; 00059 } 00060 00061 PConsoleInfo 00062 AllocConsoleInfo() 00063 { 00064 PConsoleInfo pConInfo; 00065 00066 pConInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ConsoleInfo)); 00067 00068 return pConInfo; 00069 } 00070 00071 void 00072 InitConsoleDefaults(PConsoleInfo pConInfo) 00073 { 00074 /* Initialize struct */ 00075 pConInfo->InsertMode = TRUE; 00076 pConInfo->HistoryBufferSize = 50; 00077 pConInfo->NumberOfHistoryBuffers = 5; 00078 pConInfo->ScreenText = RGB(192, 192, 192); 00079 pConInfo->ScreenBackground = RGB(0, 0, 0); 00080 pConInfo->PopupText = RGB(128, 0, 128); 00081 pConInfo->PopupBackground = RGB(255, 255, 255); 00082 pConInfo->WindowSize = (DWORD)MAKELONG(80, 25); 00083 pConInfo->WindowPosition = UINT_MAX; 00084 pConInfo->ScreenBuffer = MAKELONG(80, 300); 00085 pConInfo->UseRasterFonts = TRUE; 00086 pConInfo->FontSize = (DWORD)MAKELONG(8, 12); 00087 pConInfo->FontWeight = FW_NORMAL; 00088 memcpy(pConInfo->Colors, s_Colors, sizeof(s_Colors)); 00089 } 00090 00091 00092 INT_PTR 00093 CALLBACK 00094 ApplyProc( 00095 HWND hwndDlg, 00096 UINT uMsg, 00097 WPARAM wParam, 00098 LPARAM lParam 00099 ) 00100 { 00101 HWND hDlgCtrl; 00102 00103 UNREFERENCED_PARAMETER(lParam); 00104 00105 switch(uMsg) 00106 { 00107 case WM_INITDIALOG: 00108 { 00109 hDlgCtrl = GetDlgItem(hwndDlg, IDC_RADIO_APPLY_CURRENT); 00110 SendMessage(hDlgCtrl, BM_SETCHECK, BST_CHECKED, 0); 00111 return TRUE; 00112 } 00113 case WM_COMMAND: 00114 { 00115 if (LOWORD(wParam) == IDOK) 00116 { 00117 hDlgCtrl = GetDlgItem(hwndDlg, IDC_RADIO_APPLY_CURRENT); 00118 if ( SendMessage(hDlgCtrl, BM_GETCHECK, 0, 0) == BST_CHECKED ) 00119 EndDialog(hwndDlg, IDC_RADIO_APPLY_CURRENT); 00120 else 00121 EndDialog(hwndDlg, IDC_RADIO_APPLY_ALL); 00122 } 00123 else if (LOWORD(wParam) == IDCANCEL) 00124 { 00125 EndDialog(hwndDlg, IDCANCEL); 00126 } 00127 break; 00128 } 00129 default: 00130 break; 00131 } 00132 return FALSE; 00133 00134 } 00135 00136 void 00137 ApplyConsoleInfo(HWND hwndDlg, PConsoleInfo pConInfo) 00138 { 00139 INT_PTR res = 0; 00140 00141 res = DialogBox(hApplet, MAKEINTRESOURCE(IDD_APPLYOPTIONS), hwndDlg, ApplyProc); 00142 00143 if (res == IDCANCEL) 00144 { 00145 /* Don't destroy when user presses cancel */ 00146 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE); 00147 } 00148 else if ( res == IDC_RADIO_APPLY_ALL ) 00149 { 00150 pConInfo->AppliedConfig = TRUE; 00151 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, PSNRET_NOERROR); 00152 SendMessage(pConInfo->hConsoleWindow, PM_APPLY_CONSOLE_INFO, (WPARAM)pConInfo, (LPARAM)TRUE); 00153 } 00154 else if ( res == IDC_RADIO_APPLY_CURRENT ) 00155 { 00156 pConInfo->AppliedConfig = TRUE; 00157 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, PSNRET_NOERROR); 00158 SendMessage(pConInfo->hConsoleWindow, PM_APPLY_CONSOLE_INFO, (WPARAM)pConInfo, (LPARAM)TRUE); 00159 } 00160 } 00161 00162 /* First Applet */ 00163 LONG APIENTRY 00164 InitApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam) 00165 { 00166 PROPSHEETPAGE psp[4]; 00167 PROPSHEETHEADER psh; 00168 INT i=0; 00169 PConsoleInfo pConInfo; 00170 WCHAR szTitle[100]; 00171 PConsoleInfo pSharedInfo = (PConsoleInfo)wParam; 00172 00173 UNREFERENCED_PARAMETER(uMsg); 00174 00175 /* 00176 * console.dll shares information with win32csr with wParam, lParam 00177 * 00178 * wParam is a pointer to a ConsoleInfo struct 00179 * lParam is a boolean parameter which specifies whether defaults should be shown 00180 */ 00181 00182 pConInfo = AllocConsoleInfo(); 00183 if (!pConInfo) 00184 { 00185 return 0; 00186 } 00187 00188 if (lParam) 00189 { 00190 /* Use defaults */ 00191 InitConsoleDefaults(pConInfo); 00192 } 00193 else 00194 { 00195 if (IsBadReadPtr((const void *)pSharedInfo, sizeof(ConsoleInfo))) 00196 { 00197 /* Use defaults */ 00198 InitConsoleDefaults(pConInfo); 00199 } 00200 else 00201 { 00202 pConInfo->InsertMode = pSharedInfo->InsertMode; 00203 pConInfo->HistoryBufferSize = pSharedInfo->HistoryBufferSize; 00204 pConInfo->NumberOfHistoryBuffers = pSharedInfo->NumberOfHistoryBuffers; 00205 pConInfo->ScreenText = pSharedInfo->ScreenText; 00206 pConInfo->ScreenBackground = pSharedInfo->ScreenBackground; 00207 pConInfo->PopupText = pSharedInfo->PopupText; 00208 pConInfo->PopupBackground = pSharedInfo->PopupBackground; 00209 pConInfo->WindowSize = pSharedInfo->WindowSize; 00210 pConInfo->WindowPosition = pSharedInfo->WindowPosition; 00211 pConInfo->ScreenBuffer = pSharedInfo->ScreenBuffer; 00212 pConInfo->UseRasterFonts = pSharedInfo->UseRasterFonts; 00213 pConInfo->FontSize = pSharedInfo->FontSize; 00214 pConInfo->FontWeight = pSharedInfo->FontWeight; 00215 memcpy(pConInfo->Colors, pSharedInfo->Colors, sizeof(s_Colors)); 00216 } 00217 } 00218 00219 /* console window -> is notified on a property change event */ 00220 pConInfo->hConsoleWindow = hwnd; 00221 00222 ZeroMemory(&psh, sizeof(PROPSHEETHEADER)); 00223 psh.dwSize = sizeof(PROPSHEETHEADER); 00224 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW; 00225 if(_tcslen(pConInfo->szProcessName)) 00226 { 00227 psh.dwFlags |= PSH_PROPTITLE; 00228 psh.pszCaption = pConInfo->szProcessName; 00229 } 00230 else 00231 { 00232 if (!GetConsoleTitleW(szTitle, sizeof(szTitle)/sizeof(WCHAR))) 00233 { 00234 _tcscpy(szTitle, _T("cmd.exe")); 00235 } 00236 szTitle[(sizeof(szTitle)/sizeof(WCHAR))-1] = _T('\0'); 00237 psh.pszCaption = szTitle; 00238 } 00239 00240 psh.hwndParent = hwnd; 00241 psh.hInstance = hApplet; 00242 psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDC_CPLICON)); 00243 psh.nPages = 4; 00244 psh.nStartPage = 0; 00245 psh.ppsp = psp; 00246 00247 InitPropSheetPage(&psp[i++], IDD_PROPPAGEOPTIONS, (DLGPROC) OptionsProc, (LPARAM)pConInfo); 00248 InitPropSheetPage(&psp[i++], IDD_PROPPAGEFONT, (DLGPROC) FontProc, (LPARAM)pConInfo); 00249 InitPropSheetPage(&psp[i++], IDD_PROPPAGELAYOUT, (DLGPROC) LayoutProc, (LPARAM)pConInfo); 00250 InitPropSheetPage(&psp[i++], IDD_PROPPAGECOLORS, (DLGPROC) ColorsProc, (LPARAM)pConInfo); 00251 00252 return (PropertySheet(&psh) != -1); 00253 } 00254 00255 /* Control Panel Callback */ 00256 LONG CALLBACK 00257 CPlApplet( 00258 HWND hwndCPl, 00259 UINT uMsg, 00260 LPARAM lParam1, 00261 LPARAM lParam2) 00262 { 00263 switch(uMsg) 00264 { 00265 case CPL_INIT: 00266 { 00267 return TRUE; 00268 } 00269 case CPL_GETCOUNT: 00270 { 00271 return NUM_APPLETS; 00272 } 00273 case CPL_INQUIRE: 00274 { 00275 CPLINFO *CPlInfo = (CPLINFO*)lParam2; 00276 CPlInfo->idIcon = Applets[0].idIcon; 00277 CPlInfo->idName = Applets[0].idName; 00278 CPlInfo->idInfo = Applets[0].idDescription; 00279 break; 00280 } 00281 case CPL_DBLCLK: 00282 { 00283 InitApplet(hwndCPl, uMsg, lParam1, lParam2); 00284 break; 00285 } 00286 } 00287 return FALSE; 00288 } 00289 00290 00291 INT 00292 WINAPI 00293 DllMain( 00294 HINSTANCE hinstDLL, 00295 DWORD dwReason, 00296 LPVOID lpvReserved) 00297 { 00298 UNREFERENCED_PARAMETER(lpvReserved); 00299 00300 switch(dwReason) 00301 { 00302 case DLL_PROCESS_ATTACH: 00303 case DLL_THREAD_ATTACH: 00304 hApplet = hinstDLL; 00305 break; 00306 } 00307 return TRUE; 00308 } Generated on Sun May 27 2012 04:16:55 for ReactOS by
1.7.6.1
|