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)
13 LONG APIENTRY
InitApplet(HWND hwnd
, UINT uMsg
, LPARAM wParam
, LPARAM lParam
);
14 INT_PTR CALLBACK
OptionsProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
15 INT_PTR CALLBACK
FontProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
16 INT_PTR CALLBACK
LayoutProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
17 INT_PTR CALLBACK
ColorsProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
19 HINSTANCE hApplet
= 0;
22 APPLET Applets
[NUM_APPLETS
] =
24 {IDC_CPLICON
, IDS_CPLNAME
, IDS_CPLDESCRIPTION
, InitApplet
}
28 * Default 16-color palette for foreground and background
29 * (corresponding flags in comments).
31 const COLORREF s_Colors
[16] =
33 RGB(0, 0, 0), // (Black)
34 RGB(0, 0, 128), // BLUE
35 RGB(0, 128, 0), // GREEN
36 RGB(0, 128, 128), // BLUE | GREEN
37 RGB(128, 0, 0), // RED
38 RGB(128, 0, 128), // BLUE | RED
39 RGB(128, 128, 0), // GREEN | RED
40 RGB(192, 192, 192), // BLUE | GREEN | RED
42 RGB(128, 128, 128), // (Grey) INTENSITY
43 RGB(0, 0, 255), // BLUE | INTENSITY
44 RGB(0, 255, 0), // GREEN | INTENSITY
45 RGB(0, 255, 255), // BLUE | GREEN | INTENSITY
46 RGB(255, 0, 0), // RED | INTENSITY
47 RGB(255, 0, 255), // BLUE | RED | INTENSITY
48 RGB(255, 255, 0), // GREEN | RED | INTENSITY
49 RGB(255, 255, 255) // BLUE | GREEN | RED | INTENSITY
51 /* Default attributes */
52 #define DEFAULT_SCREEN_ATTRIB (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)
53 #define DEFAULT_POPUP_ATTRIB (FOREGROUND_BLUE | FOREGROUND_RED | \
54 BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY)
56 #define CSR_DEFAULT_CURSOR_SIZE 25
59 InitPropSheetPage(PROPSHEETPAGE
*psp
,
64 ZeroMemory(psp
, sizeof(PROPSHEETPAGE
));
65 psp
->dwSize
= sizeof(PROPSHEETPAGE
);
66 psp
->dwFlags
= PSP_DEFAULT
;
67 psp
->hInstance
= hApplet
;
68 psp
->pszTemplate
= MAKEINTRESOURCE(idDlg
);
69 psp
->pfnDlgProc
= DlgProc
;
76 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CONSOLE_PROPS
));
80 InitConsoleDefaults(PCONSOLE_PROPS pConInfo
)
82 /* Initialize the default properties */
83 pConInfo
->ci
.HistoryBufferSize
= 50;
84 pConInfo
->ci
.NumberOfHistoryBuffers
= 4;
85 pConInfo
->ci
.HistoryNoDup
= FALSE
;
86 pConInfo
->ci
.FullScreen
= FALSE
;
87 pConInfo
->ci
.QuickEdit
= FALSE
;
88 pConInfo
->ci
.InsertMode
= TRUE
;
89 // pConInfo->ci.InputBufferSize;
90 pConInfo
->ci
.ScreenBufferSize
= (COORD
){80, 300};
91 pConInfo
->ci
.ConsoleSize
= (COORD
){80, 25};
92 pConInfo
->ci
.CursorBlinkOn
= TRUE
;
93 pConInfo
->ci
.ForceCursorOff
= FALSE
;
94 pConInfo
->ci
.CursorSize
= CSR_DEFAULT_CURSOR_SIZE
;
95 pConInfo
->ci
.ScreenAttrib
= DEFAULT_SCREEN_ATTRIB
;
96 pConInfo
->ci
.PopupAttrib
= DEFAULT_POPUP_ATTRIB
;
97 pConInfo
->ci
.CodePage
= 0;
98 pConInfo
->ci
.ConsoleTitle
[0] = L
'\0';
100 pConInfo
->ci
.u
.GuiInfo
.FaceName
[0] = L
'\0';
101 pConInfo
->ci
.u
.GuiInfo
.FontFamily
= FF_DONTCARE
;
102 pConInfo
->ci
.u
.GuiInfo
.FontSize
= 0;
103 pConInfo
->ci
.u
.GuiInfo
.FontWeight
= FW_DONTCARE
;
104 pConInfo
->ci
.u
.GuiInfo
.UseRasterFonts
= TRUE
;
106 pConInfo
->ci
.u
.GuiInfo
.AutoPosition
= TRUE
;
107 pConInfo
->ci
.u
.GuiInfo
.WindowOrigin
= (POINT
){0, 0};
109 memcpy(pConInfo
->ci
.Colors
, s_Colors
, sizeof(s_Colors
));
114 ApplyProc(HWND hwndDlg
,
121 UNREFERENCED_PARAMETER(lParam
);
127 hDlgCtrl
= GetDlgItem(hwndDlg
, IDC_RADIO_APPLY_CURRENT
);
128 SendMessage(hDlgCtrl
, BM_SETCHECK
, BST_CHECKED
, 0);
133 if (LOWORD(wParam
) == IDOK
)
135 hDlgCtrl
= GetDlgItem(hwndDlg
, IDC_RADIO_APPLY_CURRENT
);
136 if (SendMessage(hDlgCtrl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
)
137 EndDialog(hwndDlg
, IDC_RADIO_APPLY_CURRENT
);
139 EndDialog(hwndDlg
, IDC_RADIO_APPLY_ALL
);
141 else if (LOWORD(wParam
) == IDCANCEL
)
143 EndDialog(hwndDlg
, IDCANCEL
);
155 ApplyConsoleInfo(HWND hwndDlg
,
156 PCONSOLE_PROPS pConInfo
)
160 res
= DialogBox(hApplet
, MAKEINTRESOURCE(IDD_APPLYOPTIONS
), hwndDlg
, ApplyProc
);
163 /* Don't destroy when user presses cancel */
164 SetWindowLongPtr(hwndDlg
, DWLP_MSGRESULT
, PSNRET_INVALID_NOCHANGEPAGE
);
167 else if (res
== IDC_RADIO_APPLY_ALL
|| res
== IDC_RADIO_APPLY_CURRENT
)
170 PCONSOLE_PROPS pSharedInfo
;
172 /* Create a memory section to share with the server, and map it */
173 hSection
= CreateFileMapping(INVALID_HANDLE_VALUE
,
177 sizeof(CONSOLE_PROPS
),
181 // DPRINT1("Error when creating file mapping, error = %d\n", GetLastError());
185 pSharedInfo
= MapViewOfFile(hSection
, FILE_MAP_ALL_ACCESS
, 0, 0, 0);
188 // DPRINT1("Error when mapping view of file, error = %d\n", GetLastError());
189 CloseHandle(hSection
);
193 /* We are applying the chosen configuration */
194 pConInfo
->AppliedConfig
= TRUE
;
196 /* Copy the console info into the section */
197 RtlCopyMemory(pSharedInfo
, pConInfo
, sizeof(CONSOLE_PROPS
));
200 UnmapViewOfFile(pSharedInfo
);
202 /* Signal to the console server that it can apply the new configuration */
203 SetWindowLongPtr(hwndDlg
, DWLP_MSGRESULT
, PSNRET_NOERROR
);
204 SendMessage(pConInfo
->hConsoleWindow
,
205 PM_APPLY_CONSOLE_INFO
,
207 (LPARAM
)(res
== IDC_RADIO_APPLY_ALL
));
209 /* Close the section and return */
210 CloseHandle(hSection
);
219 InitApplet(HWND hWnd
, UINT uMsg
, LPARAM wParam
, LPARAM lParam
)
221 HANDLE hSection
= (HANDLE
)wParam
;
222 PCONSOLE_PROPS pSharedInfo
;
223 PCONSOLE_PROPS pConInfo
;
224 WCHAR szTitle
[MAX_PATH
+ 1];
225 PROPSHEETPAGE psp
[4];
229 UNREFERENCED_PARAMETER(uMsg
);
232 * CONSOLE.DLL shares information with CONSRV with wParam:
233 * wParam is a handle to a shared section holding a CONSOLE_PROPS struct.
235 * NOTE: lParam is not used.
238 /* Allocate a local buffer to hold console information */
239 pConInfo
= AllocConsoleInfo();
240 if (!pConInfo
) return 0;
242 /* Map the shared section */
243 pSharedInfo
= MapViewOfFile(hSection
, FILE_MAP_READ
, 0, 0, 0);
244 if (pSharedInfo
== NULL
)
246 HeapFree(GetProcessHeap(), 0, pConInfo
);
250 // if (IsBadReadPtr((PVOID)pSharedInfo, sizeof(CONSOLE_PROPS)))
254 /* Find the console window and whether we must use default parameters */
255 pConInfo
->hConsoleWindow
= pSharedInfo
->hConsoleWindow
;
256 pConInfo
->ShowDefaultParams
= pSharedInfo
->ShowDefaultParams
;
258 if (pConInfo
->ShowDefaultParams
)
261 InitConsoleDefaults(pConInfo
);
265 /* Copy the shared data into our allocated buffer */
266 RtlCopyMemory(pConInfo
, pSharedInfo
, sizeof(CONSOLE_PROPS
));
269 /* Close the section */
270 UnmapViewOfFile(pSharedInfo
);
271 CloseHandle(hSection
);
273 /* Initialize the property sheet structure */
274 ZeroMemory(&psh
, sizeof(PROPSHEETHEADER
));
275 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
276 psh
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_PROPTITLE
| /* PSH_USEHICON */ PSH_USEICONID
| PSH_NOAPPLYNOW
;
278 if (pConInfo
->ci
.ConsoleTitle
[0] != L
'\0')
280 wcsncpy(szTitle
, L
"\"", sizeof(szTitle
) / sizeof(szTitle
[0]));
281 wcsncat(szTitle
, pConInfo
->ci
.ConsoleTitle
, sizeof(szTitle
) / sizeof(szTitle
[0]));
282 wcsncat(szTitle
, L
"\"", sizeof(szTitle
) / sizeof(szTitle
[0]));
286 wcscpy(szTitle
, L
"ReactOS Console");
288 psh
.pszCaption
= szTitle
;
290 psh
.hwndParent
= pConInfo
->hConsoleWindow
;
291 psh
.hInstance
= hApplet
;
292 // psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDC_CPLICON));
293 psh
.pszIcon
= MAKEINTRESOURCE(IDC_CPLICON
);
298 InitPropSheetPage(&psp
[i
++], IDD_PROPPAGEOPTIONS
, (DLGPROC
) OptionsProc
, (LPARAM
)pConInfo
);
299 InitPropSheetPage(&psp
[i
++], IDD_PROPPAGEFONT
, (DLGPROC
) FontProc
, (LPARAM
)pConInfo
);
300 InitPropSheetPage(&psp
[i
++], IDD_PROPPAGELAYOUT
, (DLGPROC
) LayoutProc
, (LPARAM
)pConInfo
);
301 InitPropSheetPage(&psp
[i
++], IDD_PROPPAGECOLORS
, (DLGPROC
) ColorsProc
, (LPARAM
)pConInfo
);
303 return (PropertySheet(&psh
) != -1);
306 /* Control Panel Callback */
308 CPlApplet(HWND hwndCPl
,
323 CPLINFO
*CPlInfo
= (CPLINFO
*)lParam2
;
324 CPlInfo
->idIcon
= Applets
[0].idIcon
;
325 CPlInfo
->idName
= Applets
[0].idName
;
326 CPlInfo
->idInfo
= Applets
[0].idDescription
;
331 InitApplet(hwndCPl
, uMsg
, lParam1
, lParam2
);
341 DllMain(HINSTANCE hinstDLL
,
345 UNREFERENCED_PARAMETER(lpvReserved
);
349 case DLL_PROCESS_ATTACH
:
350 case DLL_THREAD_ATTACH
: