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

  • 10 Rules that Make or Break Enterprise App Development Projects In today's app-driven world, application development is a top priority. Even so, 68% of enterprise application delivery projects fail. Designing and building applications that pay for themselves and adapt to future needs is incredibly difficult. Executing one successful project is lucky, but making it a repeatable process and strategic advantage? That's where the money is. With help from our most experienced project leads and software engineers, …

  • As more and more organizations migrate to the cloud, many are faced with hidden costs emerging from unexpected places. Two non-obvious and non-trivial factors can drive up costs. First are separate charges for everything from server memory to intrusion detection. Second are the high personnel costs for early-generation, manually operated clouds. These costs can rack up quickly, creating total cost of ownership (TCO) surprises. Keeping TCO low in the cloud is essentially a matter of management strategy. IT …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds