return DEFAULT_CHARSET;
}
+
+static VOID
+AddFontToList(
+ IN HWND hWndList,
+ IN LPCWSTR pszFontName,
+ IN DWORD FontType)
+{
+ INT idx;
+
+ /* Make sure the font doesn't already exist in the list */
+ if (SendMessageW(hWndList, LB_FINDSTRINGEXACT, 0, (LPARAM)pszFontName) != LB_ERR)
+ return;
+
+ /* Add the font */
+ idx = (INT)SendMessageW(hWndList, LB_ADDSTRING, 0, (LPARAM)pszFontName);
+ if (idx == LB_ERR)
+ {
+ DPRINT1("Failed to add font '%S'\n", pszFontName);
+ return;
+ }
+
+ DPRINT1("Add font '%S'\n", pszFontName);
+
+ /* Store this information in the list-item's userdata area */
+ // SendMessageW(hWndList, LB_SETITEMDATA, idx, MAKEWPARAM(fFixed, fTrueType));
+ SendMessageW(hWndList, LB_SETITEMDATA, idx, (WPARAM)FontType);
+}
+
static BOOL CALLBACK
EnumFontNamesProc(PLOGFONTW lplf,
PNEWTEXTMETRICW lpntm,
return TRUE;
}
- /* Make sure the font doesn't already exist in the list */
- if (SendMessageW(hwndCombo, LB_FINDSTRINGEXACT, 0, (LPARAM)pszName) == LB_ERR)
- {
- /* Add the font */
- INT idx = (INT)SendMessageW(hwndCombo, LB_ADDSTRING, 0, (LPARAM)pszName);
-
- DPRINT1("Add font '%S' (lfPitchAndFamily = %d)\n", pszName, lplf->lfPitchAndFamily);
-
- /* Store this information in the list-item's userdata area */
- // SendMessageW(hwndCombo, LB_SETITEMDATA, idx, MAKEWPARAM(fFixed, fTrueType));
- SendMessageW(hwndCombo, LB_SETITEMDATA, idx, (WPARAM)FontType);
- }
+ /* Add the font to the list */
+ AddFontToList(hwndCombo, pszName, /* MAKEWPARAM(fFixed, fTrueType) */ FontType);
return TRUE;
}
FontTypeChange(HWND hwndDlg,
PCONSOLE_STATE_INFO pConInfo)
{
+ HWND hListBox = GetDlgItem(hwndDlg, IDC_LBOX_FONTTYPE);
INT Length, nSel;
LPWSTR FaceName;
-
HDC hDC;
LOGFONTW lf;
- nSel = (INT)SendDlgItemMessageW(hwndDlg, IDC_LBOX_FONTTYPE,
- LB_GETCURSEL, 0, 0);
+ nSel = (INT)SendMessageW(hListBox, LB_GETCURSEL, 0, 0);
if (nSel == LB_ERR) return;
- Length = (INT)SendDlgItemMessageW(hwndDlg, IDC_LBOX_FONTTYPE,
- LB_GETTEXTLEN, nSel, 0);
+ Length = (INT)SendMessageW(hListBox, LB_GETTEXTLEN, nSel, 0);
if (Length == LB_ERR) return;
FaceName = HeapAlloc(GetProcessHeap(),
(Length + 1) * sizeof(WCHAR));
if (FaceName == NULL) return;
- Length = (INT)SendDlgItemMessageW(hwndDlg, IDC_LBOX_FONTTYPE,
- LB_GETTEXT, nSel, (LPARAM)FaceName);
- FaceName[Length] = '\0';
+ Length = (INT)SendMessageW(hListBox, LB_GETTEXT, nSel, (LPARAM)FaceName);
+ FaceName[Length] = L'\0';
- Length = min(Length/*wcslen(FaceName) + 1*/, LF_FACESIZE - 1); // wcsnlen
- wcsncpy(pConInfo->FaceName, FaceName, LF_FACESIZE);
- pConInfo->FaceName[Length] = L'\0';
+ StringCchCopyW(pConInfo->FaceName, ARRAYSIZE(pConInfo->FaceName), FaceName);
DPRINT1("pConInfo->FaceName = '%S'\n", pConInfo->FaceName);
/* Enumerate the available sizes for the selected font */
ZeroMemory(&lf, sizeof(lf));
lf.lfCharSet = DEFAULT_CHARSET; // CodePageToCharSet(pConInfo->CodePage);
// lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
- wcsncpy(lf.lfFaceName, FaceName, LF_FACESIZE);
- lf.lfFaceName[Length] = L'\0';
+ StringCchCopyW(lf.lfFaceName, ARRAYSIZE(lf.lfFaceName), FaceName);
hDC = GetDC(NULL);
EnumFontFamiliesExW(hDC, &lf, (FONTENUMPROCW)EnumFontSizesProc,
FontSizeChange(HWND hwndDlg,
PCONSOLE_STATE_INFO pConInfo)
{
+ HWND hListBox = GetDlgItem(hwndDlg, IDC_LBOX_FONTSIZE);
INT nSel;
ULONG FontSize;
WCHAR FontSizeStr[20];
- nSel = (INT)SendDlgItemMessageW(hwndDlg, IDC_LBOX_FONTSIZE,
- LB_GETCURSEL, 0, 0);
+ nSel = (INT)SendMessageW(hListBox, LB_GETCURSEL, 0, 0);
if (nSel == LB_ERR) return;
/*
* Width = FontSize.X = LOWORD(FontSize);
* Height = FontSize.Y = HIWORD(FontSize);
*/
- FontSize = (ULONG)SendDlgItemMessageW(hwndDlg, IDC_LBOX_FONTSIZE,
- LB_GETITEMDATA, nSel, 0);
+ FontSize = (ULONG)SendMessageW(hListBox, LB_GETITEMDATA, nSel, 0);
if (FontSize == LB_ERR) return;
pConInfo->FontSize.X = LOWORD(FontSize);
InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_SELECT_FONT_PREVIEW), NULL, TRUE);
swprintf(FontSizeStr, L"%2d", pConInfo->FontSize.X);
- SetWindowText(GetDlgItem(hwndDlg, IDC_FONT_SIZE_X), FontSizeStr);
+ SetDlgItemText(hwndDlg, IDC_FONT_SIZE_X, FontSizeStr);
swprintf(FontSizeStr, L"%2d", pConInfo->FontSize.Y);
- SetWindowText(GetDlgItem(hwndDlg, IDC_FONT_SIZE_Y), FontSizeStr);
+ SetDlgItemText(hwndDlg, IDC_FONT_SIZE_Y, FontSizeStr);
}
{
case WM_INITDIALOG:
{
+ HWND hListBox = GetDlgItem(hwndDlg, IDC_LBOX_FONTTYPE);
HDC hDC;
LOGFONTW lf;
INT idx;
// lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
hDC = GetDC(NULL);
- EnumFontFamiliesExW(hDC, &lf, (FONTENUMPROCW)EnumFontNamesProc,
- (LPARAM)GetDlgItem(hwndDlg, IDC_LBOX_FONTTYPE), 0);
+ EnumFontFamiliesExW(hDC, &lf, (FONTENUMPROCW)EnumFontNamesProc, (LPARAM)hListBox, 0);
ReleaseDC(NULL, hDC);
- idx = (INT)SendDlgItemMessageW(hwndDlg, IDC_LBOX_FONTTYPE, LB_GETCOUNT, 0, 0);
+ idx = (INT)SendMessageW(hListBox, LB_GETCOUNT, 0, 0);
if ((idx == 0) || (idx == LB_ERR))
{
DPRINT1("The ideal console fonts are not found; manually add default ones.\n");
/* This world is not ideal. We have to do it realistically. */
- idx = (INT)SendDlgItemMessageW(hwndDlg, IDC_LBOX_FONTTYPE, LB_ADDSTRING, 0,
- (LPARAM)L"Lucida Console");
- if (idx != LB_ERR)
- {
- SendDlgItemMessageW(hwndDlg, IDC_LBOX_FONTTYPE,
- LB_SETITEMDATA, idx, TRUETYPE_FONTTYPE);
- }
-
+ AddFontToList(hListBox, L"Lucida Console", TRUETYPE_FONTTYPE);
if (CodePageToCharSet(ConInfo->CodePage) != DEFAULT_CHARSET)
- {
- idx = (INT)SendDlgItemMessageW(hwndDlg, IDC_LBOX_FONTTYPE, LB_ADDSTRING, 0,
- (LPARAM)L"Droid Sans Fallback");
- if (idx != LB_ERR)
- {
- SendDlgItemMessageW(hwndDlg, IDC_LBOX_FONTTYPE,
- LB_SETITEMDATA, idx, TRUETYPE_FONTTYPE);
- }
- }
+ AddFontToList(hListBox, L"Droid Sans Fallback", TRUETYPE_FONTTYPE);
}
DPRINT1("ConInfo->FaceName = '%S'\n", ConInfo->FaceName);
- idx = (INT)SendDlgItemMessageW(hwndDlg, IDC_LBOX_FONTTYPE,
- LB_FINDSTRINGEXACT, 0, (LPARAM)ConInfo->FaceName);
+ idx = (INT)SendMessageW(hListBox, LB_FINDSTRINGEXACT, 0, (LPARAM)ConInfo->FaceName);
if (idx != LB_ERR)
- {
- SendDlgItemMessageW(hwndDlg, IDC_LBOX_FONTTYPE,
- LB_SETCURSEL, (WPARAM)idx, 0);
- }
+ SendMessageW(hListBox, LB_SETCURSEL, (WPARAM)idx, 0);
FontTypeChange(hwndDlg, ConInfo);