Use MFC CRichEditCtrl to display QR code with proper size

277 Views Asked by At

I am trying to display a QR code in a MFC CRichEditCtrl, but the resulting size is way too small.

This is the code I'm using to put the QR into the edit control:

    SETTEXTEX TextInfo = {0};
    TextInfo.flags = ST_SELECTION;
    TextInfo.codepage = CP_UTF8;
    LRESULT res = ::SendMessage(m_editQR.m_hWnd, EM_SETTEXTEX, (WPARAM)&TextInfo, (LPARAM)buffer);

The "buffer" parameter is a char array; its content is read from a UTF-8 file containing the QR code string. This file shows this way in Notepad++:

QR as shown in Notepad++

The QR code also shows correctly if I print the same buffer in a console app I made for tests.

However, the QR code is shown in my MFC testing app like this:

Tiny QR shown in MFC rich edit ctrl

It looks like a problem with the size of the font used to render the QR (I'm using the default for the Rich Edit control). So I tried to change the font and its size.

This is the code I'm using to set up the char format:

CHARFORMAT selCharformat;
m_editQR.GetSelectionCharFormat(selCharformat);
selCharformat.cbSize = sizeof(CHARFORMAT);
selCharformat.dwMask = CFM_FACE | CFM_SIZE | CFM_CHARSET;
selCharformat.yHeight = 20*8;
selCharformat.bCharSet = DEFAULT_CHARSET;
selCharformat.bPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
lstrcpy(selCharformat.szFaceName, _T("Console")); 
BOOL bRes = m_editQR.SetSelectionCharFormat(selCharformat);

But then the QR is messed up, like this:

QR code in edit control after changing its char format

I guess there is a problem with the setup of my Rich Edit ctrl, but can't find the correct settings (I'm not very experienced with MFC).

Can you guys help?

0

There are 0 best solutions below