Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

XCharMap - A dialog to display a character map

0.00/5 (No votes)
3 Jun 2003 2  
XCharMap demonstrates the use of CXCharMap, a class that displays a character map similar to the Windows Character Map utility.

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