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

  • Packaged application development teams frequently operate with limited testing environments due to time and labor constraints. By virtualizing the entire application stack, packaged application development teams can deliver business results faster, at higher quality, and with lower risk.

  • With 81% of employees using their phones at work, companies have stopped asking: "Is corporate data leaking from personal devices?" and started asking: "How do we effectively prevent corporate data from leaking from personal devices?" The answer has not been simple. ZixOne raises the bar on BYOD security by not allowing email data to reside on the device. In addition, Zix allows employees to maintain complete control of their personal device, therefore satisfying privacy demands of valued employees and the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds