.: Home :: Contact Us :.  
  



Hans Dietrich Software

free and licensed software

   

XHexViewCtrl image image

XHexViewCtrl implements a non-MFC Win32 control for viewing (display only) streaming hex data - for example, device monitoring data arriving via serial port. The retail download includes VS2008 projects for dialog, MDI, and C# demo (uses DLL), and VS6 projects for dialog and DLL. See bottom of this page for link to download free XHexViewCtrl demo.

XHexViewCtrl Demo

screenshot

The above screenshot shows XHexViewCtrl used in a dialog-based app. The retail download includes additional samples: an MDI app, and a .NET app that uses XHexViewCtrl in a DLL.

XHexViewCtrl Features

XHexViewCtrl is very full-featured and offers many ways to customize:
screenshot You can choose to display the offset in hex or decimal, and the number of digits.
screenshot You can choose the columns to display: offset, hex, characters, and the separator lines.
screenshot You can set the number of bytes per line and how they are grouped.
screenshot You can display a scrolling marquee under the main display window, which makes it easier to read text that contains actual words.
screenshot You can choose the encoding of incoming data:

ASCII   EBCDIC
screenshot      screenshot
     
UCS-2 Big Endian   UCS-2 Little Endian
screenshot      screenshot
UCS-2   

UCS-2, also known as ISO-10646-UCS-2, represents each character as a 2-byte, unsigned integer between 0 and 65,535. Thus the letter A is represented by the 2 bytes 00 and 41 (in hexadecimal).

UCS-2 comes in two variations, big endian and little endian. In big endian UCS-2, the most significant byte of the character comes first. In little endian UCS-2, the order is reversed. Thus, in big endian UCS-2, the letter A is #x0041, and in little endian UCS-2, A is #x4100. Little endian UCS-2 is what is used by Windows programs compiled with the UNICODE option.

To distinguish between big endian and little endian UCS-2, a document encoded in UCS-2 customarily begins with Unicode character #xFEFF, commonly called the byte-order mark (BOM). Thus, a program can look at the first two bytes of a UCS-2 document and tell immediately whether the document is big or little endian, depending on whether those bytes are #xFEFF or #xFFFE.

Because BOM use and detection cannot be depended upon for real-time data streaming, XHexViewCtrl allows you to select the correct encoding for your application.

screenshot Of course, you can choose color for each display element, including alternating data background color, to distinguish new data:

screenshot

The dialog demo shows how color groupings can be saved as a "theme" (these themes are implemented in the dialog as a convenience, and are not a XHexViewCtrl facility). Here are some of the themes that the dialog implements:

Click to enlarge.
screenshot screenshot screenshot
screenshot screenshot screenshot
screenshot You can choose individual colors for each of the control characters (< 0x20):

screenshot

screenshot You can choose fonts:

screenshot

screenshot You can optionally display a "No Data" message when the control has no data to display:

screenshot

Sending Data to XHexViewCtrl

There are several ways to send data to a XHexViewCtrl:
  1. Call the function AddData() - this is convenient when the data is available in the hosting app.
  2. Use WM_COPYDATA - this can be used when you want to display data from a different app (not the one hosting XHexViewCtrl). The dialog demo shows how this works: in the second app, use code like this:
        COPYDATASTRUCT cds = { 0 };
        cds.lpData = &g_buf[m_nBufferIndex];
        cds.cbData = n;
        ::SendMessage(m_hWndDemo, WM_COPYDATA, (WPARAM) m_hWnd, (LPARAM) &cds);
    
    and in the hosting app use this code:
    LRESULT CDlg::OnCopyData(WPARAM /*wParam*/, LPARAM lParam)
    {
        COPYDATASTRUCT *pCDS = (COPYDATASTRUCT *) lParam;
        if (pCDS == NULL)
        {
            ASSERT(FALSE);
            return FALSE;
        }
    
        if (pCDS->lpData)
        {
            if (pCDS->cbData)
            {
                LPBYTE buf = (LPBYTE)pCDS->lpData;
                m_HexViewCtrl.AddData(buf, pCDS->cbData);
            }
            else
            {
                TRACE(_T("ERROR - cbData is 0\n"));
            }
        }
        else
        {
            TRACE(_T("ERROR - lpData is NULL\n"));
        }
    
        return 0;
    }
    
    The dialog demo shows an example using MFC, but this can also be done in C# or VB.
  3. Use your preferred IPC mechanism - data can be sent to the hosting app by any IPC mechanism, including pipes and sockets, and then displayed using AddData().

XHexViewWriter Utility

To see how XHexViewCtrl functions with data being sent from another app, you can use the XHexViewWriter utility that is included (with full source code) in the retail download:

screenshot

This utility allows you to send five types of data, with varying speed and amounts, to the dialog demo.

Working with the Marquee

The scrolling marquee beneath the hex display is ideal for when incoming data contains recognizable words or groups of data. You can turn the marquee on/off and set the scrolling speed:

screenshot

When you enable marquee pause, clicking in the marquee window will pause the scroll; another click will resume it.

Clipboard Operations

You can copy the data currently displayed to the clipboard as text or as a bitmap:

screenshot

How To Use

Step 1: Add Files

All the files you need to add to your project are in the XHexViewCtrl folder in the download:
  • CXDC.h
  • CXPoint.h
  • CXRect.h
  • XHexViewCtrl.cpp
  • XHexViewCtrl.h
  • XMeteredSection.cpp
  • XMeteredSection.h
  • XTrace.h
All of the .cpp files above should be set to Not Using Precompiled Headers.

Step 2: Create XHexViewCtrl

Dlg.cpp shows how to create the XHexViewCtrl object:
    VERIFY(m_HexViewCtrl.Create(AfxGetInstanceHandle(), 
        WS_CHILD | WS_VISIBLE | WS_TABSTOP,
        WS_EX_CLIENTEDGE, rect, m_hWnd, 9001));

Step 3: Set XHexViewCtrl Attributes

You should now set the colors, fonts, and other attributes for the XHexViewCtrl object.

Step 4: Add Data to XHexViewCtrl

Add data to XHexViewCtrl object using polling, timer, or IPC mechanism.

CXHexViewCtrl Class Members

Construction
  CXHexViewCtrl() Default constructor
  virtual HWND Create(HINSTANCE hInstance, DWORD dwStyle, DWORD dwExStyle, const RECT& rect, HWND hParent, UINT nID) Creates and initializes the window associated with the CXHexViewCtrl object

Attributes
  m_hWnd Window handle of XHexViewCtrl

Fonts
  TCHAR * GetFontName() Returns name of data/header font
  int GetFontPointSize() Returns point size of data/header font
  CXHexViewCtrl& SetFont(LPCTSTR lpszFontName, int nFontPointSize, BOOL bInvalidate = TRUE) Set font for data/header font
  TCHAR * GetNoDataFontName() Returns font name of 'No Data' message
  int GetNoDataFontPointSize() Returns font point size of 'No Data' message
  BOOL GetNoDataFontBold() Returns font bold flag of 'No Data' message
  CXHexViewCtrl& SetNoDataFont(LPCTSTR lpszFontName, int nFontPointSize, BOOL bBold, BOOL bInvalidate = TRUE) Sets font for 'No Data' message
  TCHAR * GetMarqueeFontName() Returns font name of marquee
  int GetMarqueeFontPointSize() Returns font point size of marquee
  BOOL GetMarqueeFontBold() Returns font bold flag of marquee
  CXHexViewCtrl& SetMarqueeFont(LPCTSTR lpszFontName, int nFontPointSize, BOOL bBold, BOOL bInvalidate = TRUE) Sets font for marquee

Colors
  COLORREF GetAltDataBackgroundColor() Returns alternate data background color
  COLORREF GetDataBackgroundColor() Returns data background color
  COLORREF GetDataTextColor() Returns data text color
  COLORREF GetDisabledBackgroundColor() Returns disabled data background color
  COLORREF GetDisabledTextColor() Returns disabled data text color
  COLORREF GetHeaderTextColor() Returns header text color
  COLORREF GetMarqueeBackgroundColor() Returns marquee background color
  COLORREF GetMarqueeTextColor() Returns marquee text color
  COLORREF GetNoDataTextColor() Returns 'No Data' text color
  COLORREF GetOffsetTextColor() Returns offset text color
  COLORREF GetSeparatorColor() Returns separator color
  CXHexViewCtrl& ResetColors(BOOL bInvalidate = TRUE) Reset colors to their default values
  CXHexViewCtrl& SetAltDataBackgroundColor(COLORREF cr, BOOL bInvalidate = TRUE) Sets alternate data background color
  CXHexViewCtrl& SetDataBackgroundColor(COLORREF cr, BOOL bInvalidate = TRUE) Sets data background color
  CXHexViewCtrl& SetDataTextColor(COLORREF cr, BOOL bInvalidate = TRUE) Sets data text color
  CXHexViewCtrl& SetDisabledBackgroundColor(COLORREF cr, BOOL bInvalidate = TRUE) Sets disabled background color
  CXHexViewCtrl& SetDisabledTextColor(COLORREF cr, BOOL bInvalidate = TRUE) Sets disabled text color
  CXHexViewCtrl& SetHeaderTextColor(COLORREF cr, BOOL bInvalidate = TRUE) Sets header text color
  CXHexViewCtrl& SetMarqueeBackgroundColor(COLORREF cr, BOOL bInvalidate = TRUE) Sets marquee background color
  CXHexViewCtrl& SetMarqueeTextColor(COLORREF cr, BOOL bInvalidate = TRUE) Sets marquee text color
  CXHexViewCtrl& SetNoDataTextColor(COLORREF cr, BOOL bInvalidate = TRUE) Sets 'No Data' text color
  CXHexViewCtrl& SetOffsetTextColor(COLORREF cr, BOOL bInvalidate = TRUE) Sets offset text color
  CXHexViewCtrl& SetSeparatorColor(COLORREF cr, BOOL bInvalidate = TRUE) Sets separator color

Control Character (< 0x20) Colors
  COLORREF GetControlCharTextColor(int index) Returns text color for control character at index
  COLORREF GetControlCharBackgroundColor(int index) Returns background color for control character at index
  COLORREF * GetControlCharTextColors(COLORREF * pCR) Returns all 32 control character text colors
  COLORREF * GetControlCharBackgroundColors(COLORREF * pCR) Returns all 32 control character background colors
  CXHexViewCtrl& SetControlCharTextColors(COLORREF * pCR, BOOL bInvalidate = TRUE) Sets all 32 control character text colors
  CXHexViewCtrl& SetControlCharBackgroundColors(COLORREF * pCR, BOOL bInvalidate = TRUE) Sets all 32 control character background colors
  CXHexViewCtrl& SetControlCharTextColors(COLORREF cr, BOOL bInvalidate = TRUE) Sets all 32 control character text colors to the same color
  CXHexViewCtrl& SetControlCharBackgroundColors(COLORREF cr, BOOL bInvalidate = TRUE) Sets all 32 control character background colors to the same color
  CXHexViewCtrl& SetControlCharTextColor(COLORREF cr, int index, BOOL bInvalidate = TRUE) Sets text color for control character at index
  CXHexViewCtrl& SetControlCharBackgroundColor(COLORREF cr, int index, BOOL bInvalidate = TRUE) Sets background color for control character at index

Other Attributes
  BOOL GetAllowMarqueePause() Returns marquee pause allow flag
  BOOL GetAnimateNoData() Returns 'No Data' flag
  BOOL GetAutoScroll() Returns auto-scroll flag
  int GetBufferSize() Returns buffer size
  int GetBytesPerGroup() Returns bytes per group
  int GetBytesPerLine() Returns bytes per line
  eCHARSET GetCharSet() Returns encoding
  BOOL GetContinuousOffset() Returns continuous offset flag
  BOOL GetDisplayChars() Returns char display flag
  BOOL GetDisplayHeader() Returns header display flag
  BOOL GetDisplayHex() Returns hex display flag
  BOOL GetDisplayMarquee() Returns marquee display flag
  BOOL GetDisplayOffset() Returns offset display flag
  BOOL GetDisplaySeparatorLines() Returns separator line flag
  void GetLastUpdateTime(LPSYSTEMTIME st) Returns system time of last update
  int GetMarqueeSpeed() Returns marquee speed
  int GetMaxBytes() Returns max bytes to buffer
  int GetMaxUpdateSize() Returns max update size
  BOOL GetNewDataAlert() Returns new data alert flag
  TCHAR * GetNoDataMessage() Returns 'No Data' message
  int GetOffsetBase() Returns offset base
  int GetOffsetDigits() Returns number of offset digits
  TCHAR * GetOffsetHeader() Returns offset header
  eOFFSET GetOffsetType() Returns offset type
  TCHAR GetSubstituteChar() Returns substitute char (for < 0x20)
  BOOL GetUseAlternateBackgroundColor() Returns alternate background flag
  BOOL GetUseMeteredSection() Returns metered section flag
  int GetWheelScrollLines() Returns number of lines to scroll per wheel message
  CXHexViewCtrl& ResetMaxUpdateSize() Reset max update size received
  CXHexViewCtrl& ResetTotalBytes() Reset total bytes received
  CXHexViewCtrl& SetAllowMarqueePause(BOOL bFlag) Sets marquee pause flag; TRUE = click in marquee window will pause marquee
  CXHexViewCtrl& SetAnimateNoData(BOOL bFlag, BOOL bInvalidate = TRUE) Sets 'No Data' flag; TRUE = 'No Data' message will be displayed
  CXHexViewCtrl& SetAutoScroll(BOOL bFlag) Sets auto scroll flag; TRUE = XHexViewCtrl window will automatically scroll to end
  CXHexViewCtrl& SetBytesPerGroup(int n, BOOL bInvalidate = TRUE) Sets number of bytes per group
  CXHexViewCtrl& SetBytesPerLine(int n, BOOL bInvalidate = TRUE) Sets number of bytes per line
  CXHexViewCtrl& SetCharSet(eCHARSET charset, BOOL bInvalidate = TRUE) Sets encoding
  CXHexViewCtrl& SetContinuousOffset(BOOL bFlag) Sets continuous offset; TRUE = offset will continue to increment
  CXHexViewCtrl& SetDisplayChars(BOOL bFlag, BOOL bInvalidate = TRUE) Sets display characters flag
  CXHexViewCtrl& SetDisplayHeader(BOOL bFlag, BOOL bInvalidate = TRUE) Sets display header flag
  CXHexViewCtrl& SetDisplayHex(BOOL bFlag, BOOL bInvalidate = TRUE) Sets display hex flag
  CXHexViewCtrl& SetDisplayMarquee(BOOL bFlag, BOOL bInvalidate = TRUE) Sets display marquee flag
  CXHexViewCtrl& SetDisplayOffset(BOOL bFlag, BOOL bInvalidate = TRUE) Sets display offset flag
  CXHexViewCtrl& SetDisplaySeparatorLines(BOOL bFlag, BOOL bInvalidate = TRUE) Sets display separator lines flag
  CXHexViewCtrl& SetMarqueeSpeed(int nSpeed) Sets marquee speed (time delay between characters)
  CXHexViewCtrl& SetMaxBytes(int n, BOOL bInvalidate = TRUE) Sets max bytes to buffer; 0 = no max
  CXHexViewCtrl& SetNewDataAlert(BOOL bFlag) Sets new data alert sound
  CXHexViewCtrl& SetNoDataMessage(LPCTSTR lpszNoDataMessage, BOOL bInvalidate = TRUE) Sets 'No Data' message
  CXHexViewCtrl& SetOffsetBase(int base, BOOL bInvalidate = TRUE) Sets offset base
  CXHexViewCtrl& SetOffsetDigits(int n, BOOL bInvalidate = TRUE) Sets number of offset digits
  CXHexViewCtrl& SetOffsetHeader(LPCTSTR lpszOffsetHeader, BOOL bInvalidate = TRUE) Sets offset header caption
  CXHexViewCtrl& SetOffsetType(eOFFSET offset, BOOL bInvalidate = TRUE) Sets offset type
  CXHexViewCtrl& SetSubstituteChar(TCHAR cSubstitute, BOOL bInvalidate = TRUE) Sets substitute character (for < 0x20)
  CXHexViewCtrl& SetUseAlternateBackgroundColor(BOOL bFlag, BOOL bInvalidate = TRUE) Sets alternate background color flag
  CXHexViewCtrl& SetUseMeteredSection(BOOL bFlag) Sets metered section flag
  CXHexViewCtrl& SetWheelScrollLines(int n) Sets number of lines to scroll per wheel message

Clipboard Operations
  int CopyText() Copies display text to clipboard
  BOOL CopyBitmap() Copies XHexViewCtrl window bitmap to clipboard
  void ClearClipboard() Clears clipboard

Data Operations
  CXHexViewCtrl& AddData(LPBYTE buf, size_t bufsize) Adds data to XHexViewCtrl
  void Clear() Clears XHexViewCtrl

Revision History

Version 1.1 - 2010 July 19

  • Initial release

Buy latest version

Buy XHexViewCtrl 1.1 license – $50.00 per developer. Includes full source code to XHexViewCtrl, XHexViewCtrl DLL, MFC dialog and MDI samples, C# sample, and XHexViewWriter utility. All supplied with VS2008 projects. VS6 projects also included for dialog and DLL.   
  

Free download