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

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

  • The latest release of SugarCRM's flagship product gives users new tools to build extraordinary customer relationships. Read an in-depth analysis of SugarCRM's enhanced ability to help companies execute their customer-facing initiatives from Ovum, a leading technology research firm.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds