static UINT_PTR CALLBACK CFHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM /* lParam */) { // lParam = m_cf.lCustData when uiMsg == WM_INITDIALOG // but we don't need it as 'pwfd_self' must be set before calling // since we cannot be sure WM_INITDIALOG is the first call. if (uiMsg == WM_INITDIALOG) { ASSERT(pwfd_self); ::SetWindowText(hdlg, pwfd_self->m_title); if (pwfd_self->m_iType == CFontsDialog::VKEYBOARDFONT) { // Disable things we don't allow changed - defined in MFC's dlgs.h /* cmb2 = 0x0471 = Font style combobox stc2 = 0x0441 = Font style text ("Font st&yle:") */ EnableWindow(GetDlgItem(hdlg, cmb2), FALSE); // style EnableWindow(GetDlgItem(hdlg, stc2), FALSE); // style /* cmb5 = 0x0474 = Script combobox stc7 = 0x0446 = Script text ("Sc&ript:") */ EnableWindow(GetDlgItem(hdlg, cmb5), FALSE); // script ShowWindow(GetDlgItem(hdlg, cmb5), SW_HIDE); // script ShowWindow(GetDlgItem(hdlg, stc7), SW_HIDE); // script } return TRUE; } if (uiMsg == WM_COMMAND && HIWORD(wParam) == BN_CLICKED) { if (LOWORD(wParam) == IDC_SETSAMPLETEXT) { CSampleTextDlg stDlg(NULL, pwfd_self->m_sampletext); INT_PTR rc = stDlg.DoModal(); if (rc == IDOK) { pwfd_self->m_sampletext = stDlg.m_sampletext; ::SetDlgItemText(hdlg, stc5, pwfd_self->m_sampletext); ::InvalidateRect(hdlg, NULL, TRUE); } return TRUE; // We processed message } if (LOWORD(wParam) == IDC_RESETFONT) { if (pwfd_self->m_iType == CFontsDialog::VKEYBOARDFONT) { pwfd_self->m_bReset = true; pwfd_self->PostMessage(WM_COMMAND, MAKEWPARAM(IDOK, BN_CLICKED), 0); return TRUE; // We processed message } LOGFONT dfltFont = {0}; wchar_t wc_pt[4] = {0, 0, 0, 0}; // Due to a documentation bug in WM_CHOOSEFONT_SETLOGFONT - instead of just this: // pwfd_self->SendMessage(WM_CHOOSEFONT_SETLOGFONT, 0, (LPARAM)&dfltFont); // Need to do: switch (pwfd_self->m_iType) { case CFontsDialog::PASSWORDFONT: Fonts::GetInstance()->GetDefaultPasswordFont(dfltFont); break; case CFontsDialog::TREELISTFONT: case CFontsDialog::NOTESFONT: memcpy(&dfltFont, &dfltTreeListFont, sizeof(LOGFONT)); break; case CFontsDialog::ADDEDITFONT: Fonts::GetInstance()->GetDefaultAddEditFont(dfltFont); break; case CFontsDialog::VKEYBOARDFONT: // Shouldn't get here as processed earlier return FALSE; // NO "default" statement to generate compiler error if enum missing } // First get point_size = (height - Internal Leading) * 72 / LOGPIXELSY // Assume "Internal Leading" == 0 CClientDC dc((CWnd *)pwfd_self); int pt = -MulDiv(dfltFont.lfHeight, 72, dc.GetDeviceCaps(LOGPIXELSY)); _snwprintf_s(wc_pt, 4, L"%d", pt); SendMessage(GetDlgItem(hdlg, cmb1), CB_SELECTSTRING, (WPARAM)(-1), (LPARAM)dfltFont.lfFaceName); SendMessage(GetDlgItem(hdlg, cmb3), CB_SELECTSTRING, (WPARAM)(-1), (LPARAM)wc_pt); SendMessage(hdlg, WM_COMMAND, MAKEWPARAM(cmb3, CBN_SELCHANGE), (LPARAM)GetDlgItem(hdlg, cmb3)); pwfd_self->SendMessage(WM_CHOOSEFONT_SETLOGFONT, 0, (LPARAM)&dfltFont); pwfd_self->m_sampletext.LoadString(IDS_SAMPLETEXT); ::SetDlgItemText(hdlg, stc5, pwfd_self->m_sampletext); return TRUE; // We processed message } } // For some reason, we keep having to change the sample text! ::SetDlgItemText(hdlg, stc5, pwfd_self->m_sampletext); return FALSE; // We didn't process message }
static UINT_PTR CALLBACK CFHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM /* lParam */) { // lParam = m_cf.lCustData when uiMsg == WM_INITDIALOG // but we don't need it as 'pwfd_self' must be set before calling // since we cannot be sure WM_INITDIALOG is the first call. if (uiMsg == WM_INITDIALOG) { ASSERT(pwfd_self); ::SetWindowText(hdlg, pwfd_self->m_title); if (pwfd_self->m_iType == VKFONT) { // Disable things we don't allow changed EnableWindow(GetDlgItem(hdlg, cmb2), FALSE); // style EnableWindow(GetDlgItem(hdlg, stc2), FALSE); // style #if 0 EnableWindow(GetDlgItem(hdlg, cmb3), FALSE); // size EnableWindow(GetDlgItem(hdlg, stc3), FALSE); // size // Make Edit in Size ComboBox R-O SendMessage(GetDlgItem(GetDlgItem(hdlg, cmb3), 1001), EM_SETREADONLY, TRUE, 0); #endif EnableWindow(GetDlgItem(hdlg, cmb5), FALSE); // script ShowWindow(GetDlgItem(hdlg, cmb5), SW_HIDE); // script ShowWindow(GetDlgItem(hdlg, stc7), SW_HIDE); // script } return TRUE; } if (uiMsg == WM_COMMAND && HIWORD(wParam) == BN_CLICKED) { if (LOWORD(wParam) == IDC_SETSAMPLETEXT) { CSampleTextDlg stDlg(NULL, pwfd_self->m_sampletext); INT_PTR rc = stDlg.DoModal(); if (rc == IDOK) { pwfd_self->m_sampletext = stDlg.m_sampletext; ::SetDlgItemText(hdlg, stc5, pwfd_self->m_sampletext); ::InvalidateRect(hdlg, NULL, TRUE); } return TRUE; // We processed message } if (LOWORD(wParam) == IDC_RESETFONT) { if (pwfd_self->m_iType == VKFONT) { pwfd_self->m_bReset = true; pwfd_self->PostMessage(WM_COMMAND, IDABORT, 0); return TRUE; // We processed message } LOGFONT dfltFont; wchar_t wc_pt[4] = {0, 0, 0, 0}; // Due to a documentation bug in WM_CHOOSEFONT_SETLOGFONT - instead of just this: // pwfd_self->SendMessage(WM_CHOOSEFONT_SETLOGFONT, 0, (LPARAM)&dfltFont); // Need to do: switch (pwfd_self->m_iType) { case PWFONT: Fonts::GetInstance()->GetDefaultPasswordFont(dfltFont); break; case TLFONT: memcpy(&dfltFont, &dfltTreeListFont, sizeof(LOGFONT)); break; default: ASSERT(0); return FALSE; } // First get point_size = (height - Internal Leading) * 72 / LOGPIXELSY // Assume "Internal Leading" == 0 CClientDC dc((CWnd *)pwfd_self); int pt = -MulDiv(dfltFont.lfHeight, 72, dc.GetDeviceCaps(LOGPIXELSY)); _snwprintf_s(wc_pt, 4, L"%d", pt); SendMessage(GetDlgItem(hdlg, cmb1), CB_SELECTSTRING, (WPARAM)(-1), (LPARAM)dfltFont.lfFaceName); SendMessage(GetDlgItem(hdlg, cmb3), CB_SELECTSTRING, (WPARAM)(-1), (LPARAM)wc_pt); SendMessage(hdlg, WM_COMMAND, MAKEWPARAM(cmb3, CBN_SELCHANGE), (LPARAM)GetDlgItem(hdlg, cmb3)); pwfd_self->SendMessage(WM_CHOOSEFONT_SETLOGFONT, 0, (LPARAM)&dfltFont); return TRUE; // We processed message } } // For some reason, we keep having to change the sample text! ::SetDlgItemText(hdlg, stc5, pwfd_self->m_sampletext); return FALSE; // We didn't process message }