March 28, 2024, 02:35:04 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Problem with richedit setselfont()

Started by ExMember001, January 05, 2009, 04:19:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ExMember001

I have a problem with setselfont from crichedit class.
Setselfont in the userguide say :
If there is no selection the font is changed for all characters entered after the insertion point.

but using the example below you will see that if you select a font with Symbol character set (like Webdings)
the font is not changed until something is selected.

what am i doing wrong?



#include "windows.inc"
#include "commctrl.inc"
#define IDC_FONTS 1000
#define ID_Rich   1001

#define FONTSIZE 16
WNDPROC g_DlgProc;

class CDlg:CDialog
{
declare virtual  OnInitDialog(),int;
declare virtual OnClose(),int;
declare virtual OnControl(INT nID, INT nNotifyCode, unsigned INT hControl),INT;
CCombobox m_fonts;
CRICHEDIT m_Red;
}

global sub main()
{
CDlg d1;
d1.Create(0,0,360,202,0x80CA0080,0,"Font Picker",0);
d1.DoModal();
return 0;
}

CDlg::OnClose(),int
{
CloseDialog(1);
return true;
}

CDlg::OnInitDialog(),int
{
/* Initialize any controls here */
CenterWindow();

// subclass the dialog
SetProp(m_hwnd, "this", this);
g_DlgProc = SetWindowLong(m_hwnd, GWL_WNDPROC, &SubclassDlgProc);

m_fonts.Create(6,16,350,350,0x50A10242|CBS_OWNERDRAWFIXED|ACBS_SORT,IDC_FONTS,"",this);

m_Red.Create(10,50,340,150,0x50B01044,ID_Rich,"",this);

// enum fonts
HDC dc = GetDC(m_hwnd);
EnumFontFamilies(dc, NULL, &EnumFontsCb, m_fonts.m_hwnd);
ReleaseDC(m_hwnd, dc);

return true;
}


sub EnumFontsCb(ENUMLOGFONT *lpelf, NEWTEXTMETRIC *lpntm, DWORD FontType, HWND hwndCombo),int
{
if (SendMessage(hwndCombo, CB_FINDSTRINGEXACT, -1, &lpelf->elfLogFont.lfFaceName) == CB_ERR)
{
SendMessage(hwndCombo, CB_ADDSTRING, 0, &lpelf->elfLogFont.lfFaceName);
}
return 1;
}

CDlg::OnControl(INT nID, INT nNotifyCode, unsigned INT hControl),INT
{
select nID
{
case IDC_FONTS:
    if(nNotifyCode = 1)
{

m_Red.SetFocus();
string font = m_fonts.GetItemText(m_fonts.GetCurSel());
    m_Red.SetSelFont(font, 16, false, DEFAULT_CHARSET);

}
}
}


sub SubclassDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam),LRESULT
{
dstring szFace[64];
LOGFONT lf;
CWindow *pWin;
CCombobox *pCombo;

switch (uMsg)
{
case WM_MEASUREITEM:
*(MEASUREITEMSTRUCT)lParam.itemWidth  = 1;
*(MEASUREITEMSTRUCT)lParam.itemHeight = FONTSIZE + 2;

case WM_DRAWITEM:
DRAWITEMSTRUCT *pdis = &*(DRAWITEMSTRUCT)lParam;
// erase
HBRUSH hbr = GetSysColorBrush(IIF(pdis->itemState & ODS_SELECTED, COLOR_HIGHLIGHT, COLOR_WINDOW));
FillRect(pdis->hDC, &pdis->rcItem, hbr);

pWin          = GetProp(hwnd, "this");
pCombo        = pWin->GetControl(IDC_FONTS);

if (pdis->itemID != -1)
{
szFace        = pCombo->GetItemText(pdis->itemID);
ZeroMemory(&lf, sizeof(lf));
lf.lfFaceName = szFace;
lf.lfHeight   = -MulDiv(FONTSIZE, GetDeviceCaps(pdis->hDC, LOGPIXELSY), 72);
// create and select new font
HFONT font    = SelectObject(pdis->hDC, CreateFontIndirect(&lf));
// draw transparent text
SetBkMode(pdis->hDC, TRANSPARENT);
pdis->rcItem.left += 2;
DrawText(pdis->hDC, szFace, len(szFace), &pdis->rcItem, DT_SINGLELINE | DT_VCENTER);
// restore old, delete new font
DeleteObject(SelectObject(pdis->hDC, font));
}
return 0;
}
return CallWindowProc(g_DlgProc, hWnd, uMsg, wParam, lParam);
}