Click here to Skip to main content
Click here to Skip to main content

XCharMap - A dialog to display a character map

, 3 Jun 2003 CPOL
Rate this:
Please Sign up or sign in to vote.
XCharMap demonstrates the use of CXCharMap, a class that displays a character map similar to the Windows Character Map utility.
<!-- Add the rest of your HTML here -->

Introduction

In some apps, the user may want to select how to display certain characters. For example, in text editors, it is common to have option to display whitespace (space and tab). When I had this requirement recently, I tried to use Microsoft's Character Map to allow user to select the display characters. Unfortunately, unless you are willing to use clipboard, there is no way to seamlessly integrate Character Map into your app. So here is XCharMap, my implementation of Character Map as a convenient dialog that you can customize to meet your needs.

The XCharMap Dialog

        XCharMap screenshot

The XCharMap dialog displays 256 characters in selected font. In dialog caption, the character code under the cursor is displayed in hex, octal, and decimal. Below character grid are optional UI elements, which you can remove from the display by calling XCharMap APIs. When user left-clicks (or right-clicks) a character, it is displayed in left-click/right-click box. The last character that was left-clicked may be copied to Characters to copy edit box by clicking on Select. Clicking on Copy will then transfer contents of edit box to clipboard.

To remove Characters to copy UI elements, you can call

  • CXCharMap::EnableCharsToCopy(FALSE).

To remove left-click/right-click UI elements, you can call

  • CXCharMap::EnableClicks(FALSE).

When both sets of UI elements are removed, the XCharMap dialog will be shrunk to fit character grid. To remove character code display in dialog caption, you can call

  • CXCharMap::EnableCharacterCode(FALSE).

Here is code from XCharMapTestDlg.cpp that shows how to call CXCharMap and disable all optional UI elements:

void CXCharMapTestDlg::OnTest()
{
    CXCharMap dlg;

    dlg.EnableCharsToCopy(FALSE);
    dlg.EnableClicks(FALSE);
    dlg.EnableCharacterCode(FALSE);

    if (dlg.DoModal() == IDOK)
    {
        // process return here
        TRACE(_T("m_nLeftClickRow=%d\n"), dlg.m_nLeftClickRow);
        TRACE(_T("m_nLeftClickCol=%d\n"), dlg.m_nLeftClickCol);
        TRACE(_T("m_nRightClickRow=%d\n"), dlg.m_nRightClickRow);
        TRACE(_T("m_nRightClickCol=%d\n"), dlg.m_nRightClickCol);
    }
} 

How To Use

To integrate IsOpenType() into your app, you first need to add following files to your project:

  • Clipboard.cpp
  • Clipboard.h
  • GetFontFile.cpp
  • GetFontFile.h
  • IsOpenType.cpp
  • IsOpenType.h
  • XCharGrid.cpp
  • XCharGrid.h
  • XCharMap.cpp
  • XCharMap.h
  • XFontPreviewCombo.cpp
  • XFontPreviewCombo.h

Next, include the header file XCharMap.h in appropriate project files. Now you are ready to start using CXCharMap.

Limitations

Currently the XCharMap implementation does not support Unicode.

Acknowledgments and references

Revision History

Version 1.0 - 2003 June 4

  • Initial public release.

Usage

This software is released into the public domain. You are free to use it in any way you like. If you modify it or extend it, please to consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Hans Dietrich
Software Developer (Senior) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.
 
Recently, I have moved to Los Angeles where I am doing consulting and development work.
 
For consulting and custom software development, please see www.hdsoft.org.






Comments and Discussions

 
GeneralUnicode version PinmemberE Olivier18-Aug-04 0:46 
GeneralDetecting OpenType Fonts Pinmembergjr29-Apr-04 22:38 
GeneralRe: Detecting OpenType Fonts PinmemberHans Dietrich30-Apr-04 1:34 
GeneralRe: Detecting OpenType Fonts Pinmembergjr30-Apr-04 19:27 
Problem is not in filename identification since I bypassed that with a unit test routine along the lines of:-
 
#if defined(_DEBUG)
void DB_TestIsOpenType(void) // validate IsOpenType() function
{
DB_SHOWENTRY(::DB_TestIsOpenType);
#define WFDIR "H:\\WINNT\\fonts\\" // Windows Fonts directory
 
// If not found, should be false
_ASSERT(!IsOpenType(NULL)); // NULL
_ASSERT(!IsOpenType(_T(""))); // NULstr
_ASSERT(!IsOpenType(_T(WFDIR "ABC.XYZ"))); // Non existent file
 
// FON files - definitely NOT OpenType!
_ASSERT(!IsOpenType(_T(WFDIR "8x13-iso8859-1.fon")));
_ASSERT(!IsOpenType(_T(WFDIR "8X16.FON")));
_ASSERT(!IsOpenType(_T(WFDIR "ACRSEC.FON")));
_ASSERT(!IsOpenType(_T(WFDIR "acrsecI.fon")));
_ASSERT(!IsOpenType(_T(WFDIR "HVDOSBOX.FON")));
_ASSERT(!IsOpenType(_T(WFDIR "HVRASTER.FON")));
_ASSERT(!IsOpenType(_T(WFDIR "MODERN.FON")));
_ASSERT(!IsOpenType(_T(WFDIR "ROMAN.FON")));
_ASSERT(!IsOpenType(_T(WFDIR "SANSMONO.FON")));
 
// TTF files - only SOME are OpenType
_MUSTDO(_T("zz - Check these against WinNT Fonts Applet"))
_ASSERT(IsOpenType(_T(WFDIR "ARBLI___.TTF")));
_ASSERT(!IsOpenType(_T(WFDIR "CAREFREE.TTF")));
_ASSERT(IsOpenType(_T(WFDIR "COUR.TTF")));
_ASSERT(IsOpenType(_T(WFDIR "COURI.TTF")));
_ASSERT(!IsOpenType(_T(WFDIR "Digits.ttf")));
_ASSERT(IsOpenType(_T(WFDIR "GEORGIA.TTF")));
_ASSERT(!IsOpenType(_T(WFDIR "Gothicb.ttf")));
_ASSERT(!IsOpenType(_T(WFDIR "HazardSigns.ttf")));
_ASSERT(!IsOpenType(_T(WFDIR "InOfOne_.ttf")));
_ASSERT(IsOpenType(_T(WFDIR "Lc______.ttf")));
_ASSERT(IsOpenType(_T(WFDIR "L_10646.TTF")));
_ASSERT(IsOpenType(_T(WFDIR "MICROSS.TTF")));
_ASSERT(!IsOpenType(_T(WFDIR "PrintersOrnamentsOne.ttf")));
_ASSERT(!IsOpenType(_T(WFDIR "Perfect DOS VGA 437 Win.ttf")));
_ASSERT(!IsOpenType(_T(WFDIR "Perfect DOS VGA 437.ttf")));
_ASSERT(!IsOpenType(_T(WFDIR "PictureA.ttf")));
_ASSERT(IsOpenType(_T(WFDIR "Timnreb.ttf")));
_ASSERT(IsOpenType(_T(WFDIR "Schlbk.ttf")));
_ASSERT(IsOpenType(_T(WFDIR "Schlbkb.ttf")));
_ASSERT(IsOpenType(_T(WFDIR "Schlbkbi.ttf")));
_ASSERT(IsOpenType(_T(WFDIR "Schlbki.ttf")));
_ASSERT(!IsOpenType(_T(WFDIR "SANSMP.TTF")));
 
// OTF files - ALL definitely OpenType
// DWORD FontType can be TRUETYPE_FONTTYPE or DEVICE_FONTTYPE
_ASSERT(IsOpenType(_T(WFDIR "BalladeContour.otf")));
_ASSERT(IsOpenType(_T(WFDIR "BalladeHf.otf")));
_ASSERT(IsOpenType(_T(WFDIR "BalladeSh.otf")));
_ASSERT(IsOpenType(_T(WFDIR "Gotisch-Schatten.otf")));
_ASSERT(IsOpenType(_T(WFDIR "GotischA-Bold.otf")));
_ASSERT(IsOpenType(_T(WFDIR "GotischA.otf")));
_ASSERT(IsOpenType(_T(WFDIR "GotischB-Bold.otf")));
_ASSERT(IsOpenType(_T(WFDIR "GotischB.otf")));
_ASSERT(IsOpenType(_T(WFDIR "GotischC-Bold.otf")));
_ASSERT(IsOpenType(_T(WFDIR "GotischC.otf")));
_ASSERT(IsOpenType(_T(WFDIR "GotischD-Bold.otf")));
_ASSERT(IsOpenType(_T(WFDIR "GotischD.otf")));
_ASSERT(IsOpenType(_T(WFDIR "GotischSchmal.otf")));
_ASSERT(IsOpenType(_T(WFDIR "GotischSchmuck-Bold.otf")));
_ASSERT(IsOpenType(_T(WFDIR "GotischSchmuck.otf")));
_ASSERT(IsOpenType(_T(WFDIR "Monument.otf")));
_ASSERT(IsOpenType(_T(WFDIR "RomanDecoratedInitials.otf")));
 
#undef WFDIR
} // DB_TestIsOpenType
#endif // _DEBUG
 
with the filenames taken from Windows XP font directory.
 
Comparing result with another approach it appears problem lies in the function IsOpenType() but I haven't had time to look at it in detail.
If the beach doesn't beckon too much I will try to check it out this weekend.
Rgds
GJR
 
gjr
GeneralRe: Detecting OpenType Fonts Pinmembergjr1-May-04 22:09 
Generalunicode... PinmemberManikandan28-Mar-04 21:31 
AnswerRe: unicode... PinmentorHans Dietrich2-Apr-11 5:16 
GeneralDoes not display chars of Windings font PinmemberPnirff13-Jun-03 1:02 
GeneralRe: Does not display chars of Windings font PinmemberHans Dietrich13-Jun-03 2:57 
GeneralRe: Does not display chars of Windings font PinmemberPnirff13-Jun-03 4:47 
GeneralUseless PinmemberJohn R. Shaw5-Jun-03 16:23 
GeneralRe: Useless PinmemberStephan Poirier9-Jun-03 21:11 
GeneralRe: Useless PinmemberJohn R. Shaw10-Jun-03 3:16 
GeneralRe: Useless PinmemberStephan Poirier10-Jun-03 14:37 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150326.1 | Last Updated 4 Jun 2003
Article Copyright 2003 by Hans Dietrich
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid