Click here to Skip to main content
15,897,273 members
Articles / Desktop Programming / MFC
Article

Unicode Owner Draw Button Control

Rate me:
Please Sign up or sign in to vote.
3.75/5 (4 votes)
30 Sep 20051 min read 56.2K   1.9K   37   2
Shows you how to display Unicode strings in an owner draw button control.

Sample Image

Introduction

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).

Background

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.

Using the code

The implementation of the CUniButton is done in the following steps:

  1. Add a button to your dialog and set the Owner-Draw property to True.
  2. Add a member variable for your button and change CButton to CUniButton.

    Change:

    CButton m_button1;
    

    to:

    CUniButton m_button1;
    
  3. Add the 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);

Points of Interest

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.

History

  • Version 1.0: 25/09/2005

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Netherlands Netherlands
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionusp10.lib ? Pin
jayart5-Apr-06 5:04
jayart5-Apr-06 5:04 
GeneralMSLU Pin
Anonymous2-Oct-05 11:55
Anonymous2-Oct-05 11:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.