HexTools, Hex and Binary Dialog Controls



Click here for larger image

Environment: VC6 SP4, NT4 SP6, W98 SE, W2000 SP1

I was missing hex and binary controls in the MFC. First I created a CEdit derived class; however, this solution didn't satisfied me. I think it's much more comfortable for a developer to use only one DDX_Custom(..) function in the dialogs DoDataExchange(..) instead of having an CWnd derived member. Neither the "BitWnd.h" nor the "HexText.h" have to be included in the dialogs header file. CBitWnd and CHexText are two independent classes.

CBitWnd

CBitWnd is a CStatic derived class that is dynamically allocated and sub classed during the call to the DDX_BitWnd(..) function. It uses CheckBoxes

How to use:

Add a Static control to your dialog resource.
Include the "BitWnd.h" to your dialogs CPP-File:

#include "BitWnd.h"

Add the

template <typename T_>
inline void DDX_BitWnd(
    CDataExchange* pDX,    //
    UINT nID,              // BN_CLICK sends WM_COMMAND to 
                           //    the Parent with this ID
    T_&value,              // the value
    BOOL bVertical=FALSE,  // low bit right(default), vertical: low
                           //    bit top
    int nCountOfBits=0,    // 0 : creates sizeof(value)*8 Checkboxes
    CStringArray *pStringArray =NULL, // NULL: button text=   "0".."n"
    DWORD dwDisableMask=0x00000000,   // You may disable some of the 
                                      //    lowest 32 bits
    int nSpaceExtra = 2)              // the space behind each 4th
                                      //         Checkbox in Pixel

to your dialogs DoDataExchange() outside the AFX_DATA_MAP comments:

void CHexToolsDlg::DoDataExchange(CDataExchange* pDX)
{
  ...
  //}}AFX_DATA_MAP 
  // with default parameter : horizontal, display all bits, Text: "0".."n",
  // all bits enabled, 2 Pixel space between each 4th and 5th Checkbox
  DDX_BitWnd(pDX,IDC_STATIC_VAR,m_nVar); 

CHexText

CHexText is a container class for static stringconversion functions. The Headers contains overload DDX_HexText(..) functions for BYTE, WORD, DWORD, char, short, int and CString. It is possible to show/edit strings that contain NULL-char.

How to use:

  • Add the "HexText.h" and "HexText.cpp" to your project.
  • Add an edit control to your dialog template.(e.g. IDC_EDIT_MYSTRING)
  • Create a member with the Class Wizard.( e.g. m_strMyString)
  • Include the "HexText.h" to your dialogs CPP-File:
  • Replace the DDX_Text(..) with DDX_HexText in your dialogs DoDataExchange(..), and move it out of the AFX_DATA_MAP comments:
void CHexToolsDlg::DoDataExchange(CDataExchange* pDX)
{
  ...
  //}}AFX_DATA_MAP
  DDX_HexText(pDX,IDC_EDIT_MYSTRING,m_strMyString);

There's an aditional function:

void  DDX_TextHexBracket(CDataExchange* pDX,int nID, CString &str);

It shows characters in the Range of [32..127] as characters an theotherasdecimalnumberslikeHTML-tags:<0>..<31>,<127>..<255>. Usually I use this to monitor serial IO for protocols that include plain text as well as non-printable characters like STX , ETX or NULL.

Downloads

Download demo project - [20] Kb
Download source - [8] Kb
The latest versions may be found at:
www.schikos.de


Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • A modern mobile IT strategy is no longer an option, it is an absolute business necessity. Today's most productive employees are not tied to a desk, an office, or a location. They are mobile. And your company's IT strategy has to be ready to support them with easy, reliable, 24/7 access to the business information they need, from anywhere in the world, across a broad range of communication devices. Here's how some of the nation's most progressive corporations are meeting the many needs of their mobile workers …

  • Agile methodologies give development and test teams the ability to build software at a faster rate than ever before. Combining DevOps with hybrid cloud architectures give teams not just the principles, but also the technology necessary to achieve their goals. By combining hybrid cloud and DevOps: IT departments maintain control, visibility, and security Dev/test teams remain agile and collaborative Organizational barriers are broken down Innovation and automation can thrive Download this white paper to …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds