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

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds