When I was writing an application for an Arabic customer in C++, I noticed that the buttons/labels in my CDialog
did not understand my Arabic text. This class allows you to write any Unicode text in the button control. (And you can use it as a direction for making the same for a static label, for instance).
This article started as a simple project to display Arabic text from a MySQL database / file on images/dialogs. I noticed that when you write Unicode characters into the developer environment directly, you need to convert it to Unicode first. That's is why I make use of the function MultiByteToWideChar
in the sample application.
The implementation of the CUniButton
is done in the following steps:
CButton
to CUniButton
. Change:
CButton m_button1;
to:
CUniButton m_button1;
UniButton
header file into your Dialog header: #include "unibutton.h"
To change text/font/reading order, use the following:
m_button1.SetText(L"Unicode text goes here"); m_button1.SetRTL(0);//no right to left m_button1.SetFont("Tahoma",30);
For Arabic, set the RTL
to True
:
Add the Usp10.lib library to your project dependencies.
The following functions are implemented:
void SetHilightColors (COLORREF hilight,COLORREF hilightText);
void SetNormalColors (COLORREF clrBkgnd,COLORREF clrText);
void SetText(WCHAR *szText);
void SetRTL(int bRTL);
void SetDefaultSSAFlags(DWORD dwFlags);
void SetFont(char *szFaceName, int height);
void SetHorizontalAlignment(_AlignHorz hAlign);
void SetVerticalAlignment(_AlignVert vAlign);
I'm just starting to learn how to use Unicode characters in projects. It is possible that I forgot to implement some important features. If so, you probably want to modify the functions: PlotTXTUnicode
and/or CalcTXTUnicode
.