分类: C/C++
2008-09-14 20:38:55
CPPDumpCtrl
is a Dump Control based on MFC and the CWnd class. It implements basic behavior to edit/view Data in HEX, DEC, BIN, OCT and/or ASCII view.
To use the PPDumpCtrl
control in your project you will need to add a number of files to your project:
Where PPDumpCtrl.* is a main CPPDumpCtrl
control source and header files, and PPNumEdit.* is a CPPNumEdit
control files (class for in-place editing).
Include file PPDumpCtrl.h in the header file where will be use the CPPDumpCtrl
control
In your application, create a member variable for the control. Please note that this variable is a pointer:
CPPDumpCtrl* m_hex_ctrl;
Now create the control. For dialog-based applications, in your OnInitDialog:
// Call the base-class method CDialog::OnInitDialog();
// Create the CPPDumpCtrl object m_hex_ctrl = new CPPDumpCtrl; m_hex_ctrl->Create(CRect(0, 0, 100, 100), this, 100);
Remember to destroy the control or you will get a memory leak. This can be done, for example, in your class destructor:
if (m_hex_ctrl) delete m_hex_ctrl;
For initialize CPPDumpCtrol in your OnInitDialog
add following lines:
//Attach the Data Arrays to the CPPDumpCtrl object m_dump_ctrl.SetPointerData(256, nNewData, nOldData, FALSE);
//where nNewData and nOldData is a //pointer to the arrays with data for //dumping, and 256 - length of the arrays
Also you can set styles, fonts and colors here
Construction |
|
Constructs a CPPDumpCtrl object. | |
Constructs a CPPDumpCtrl object. | |
Initialization |
|
Sets the pointers to data arrays and sets the length of data arrays | |
Sets offset for viewing address | |
Appearance |
|
Sets the styles in default value | |
Sets the styles | |
Changes the style of a control | |
Retrieves information about the control styles | |
Sets data for read only | |
Checks may be data changed or not | |
Sets the character which will drawn instead special characters (code: 0 - 31) | |
Color Functions |
|
Sets the control colors to the default colors. | |
Specifies the color to use for the control. | |
Retrieves the color for the control. | |
Notification |
|
Enable notification about changing the data or the view. | |
Is enabled notification about changing the data or the view.. | |
Font Functions |
|
Sets the control font to the default value (Courier, 8pt.). | |
Specifies the font for the control. | |
Miscellaneous Functions |
|
Sets first visible address in the control | |
Gets current visible address from the control | |
This function enables or disables the track mouse. | |
This function returns whether the track mouse is enabled | |
Selection Functions |
|
Sets the range of the selected block | |
Gets the range of the selected block. | |
Whether checks there is a specified address in the range of the selection | |
Enable to select data range | |
Checks may be data selected or not | |
Menu Functions |
|
Associates a menu to the control. | |
ToolTip Functions |
|
This function sets the format string of the text to show in the control tooltip. | |
This function enables or disables the button tooltip | |
This function gets pointer to the tooltip object |
PPDumpCtrl ();
Remarks
Constructs a CPPDumpCtrl object. The control styles, font and colors is initially set to default values (see , and ).
| |
BOOL Create(const RECT& rect, CWnd* pParentWnd, UINT nID, DWORD dwStyle = WS_CHILD | WS_BORDER | WS_TABSTOP | WS_VISIBLE);
Parameters
rect
- The size and position of the window, in client coordinates of pParentWnd.
pParentWnd
- The parent window.
nID
- The ID of the child window.
dwStyle
- Specifies the window style attributes. Return Value
Nonzero if successful; otherwise 0.
Remarks
Creates and initializes the child window associated with the CPPDumpCtrl
object.
| |
void SetPointerData (DWORD nLength, LPBYTE pNewData, LPBYTE pOldData /* = NULL */, BOOL bRedraw /* = TRUE */)
Parameters
nLength
- Length of data arrays
pNewData
- The pointer to the array with new data.
pOldData
- The pointer to the array with old data. If pOldData is NULL then the pointer to the array with old data will be same as the pointer to new data array.
bRedraw
- Specifies whether the control is to be redrawn. A nonzero value redraws the control. A 0 value does not redraw the control. The control is redrawn by default. Remarks
Sets the pointers to data arrays and sets the length of data arrays.
Example:
BYTE nNewData [1000]; BYTE nOldData [1000]; //Filling the arrays ... m_dump_ctrl.SetPointerData(1000, nNewData, nOldData);
| |
void SetOffsetViewAddress (DWORD nAddress /* = 0 */, BOOL bRedraw /* = TRUE */)
Parameters
nAddress
- The offset value for viewing address. For example, viewing address on screen start with 0 always. But if you have specified the offset address then viewing address will be start from it value.
bRedraw
- Specifies whether the control is to be redrawn. A nonzero value redraws the control. A 0 value does not redraw the control. The control is redrawn by default. Remarks
Sets offset for viewing address
| |
void SetDefaultStyles (BOOL bRedraw /* = TRUE */)
Parameters
bRedraw
- Specifies whether the control is to be redrawn. A nonzero value redraws the control. A 0 value does not redraw the control. The control is redrawn by default. Remarks
Sets all styles to a default value. The function set following to control:
PPDUMP_FIELD_ADDRESS| |
void SetStyles (DWORD nStyle, BOOL bRedraw /* = TRUE */)
Parameters
nStyle
- The new of the control.
bRedraw
- Specifies whether the control is to be redrawn. A nonzero value redraws the control. A 0 value does not redraw the control. The control is redrawn by default. Remarks
The function set the new styles for control
| |
void ModifyStyles (DWORD nAddStyle, DWORD nRemoveStyle, BOOL bRedraw /* = TRUE */)
Parameters
nAddStyle
- Added .
nRemoveStyle
- Removed .
bRedraw
- Specifies whether the control is to be redrawn. A nonzero value redraws the control. A 0 value does not redraw the control. The control is redrawn by default. Remarks
The function modifies styles of the control
| |
DWORD GetStyles ()
Return value
The current styles of the control.
Remarks
The function returns the current of the control
| |
void SetReadOnly(BOOL bReadOnly /* = TRUE */)
Parameters
bReadOnly
- Specifies whether to set or remove the read-only state of the control. A value of TRUE sets the state to read-only; a value of FALSE sets the state to read/write. Remarks
This method sets the read-only state of an control.
| |
BOOL IsReadOnly()
Return value
TRUE if the control is read-only.
Remarks
Call this member function to determine if the control is read-only. User can view the data, but cannot change it.
| |
void SetDefaultColors(BOOL bRedraw /* = TRUE */)
Parameters
bRedraw
- Specifies whether the control is to be redrawn. A nonzero value redraws the control. A 0 value does not redraw the control. The control is redrawn by default. Remarks
Use this function to reset the control colors to their default values.
| |
COLORREF SetColor(int nIndex, COLORREF crColor, BOOL bRedraw /* = TRUE */)
Parameters
nIndex
- Specifies the color to be set. This is one of the color values defined in the
crColor
- A COLORREF value specifying the color to set
bRedraw
- Specifies whether the control is to be redrawn. A nonzero value redraws the control. A 0 value does not redraw the control. The control is redrawn by default. Return value
The function returns previous color.
Remarks
Sets the color specified the nIndex.
| |
COLORREF GetColor(int nIndex)
Parameters
nIndex
- Specifies the color to be retrieved. This is one of the color values defined in the Return value
A pointer to a COLORREF value to be receive the requested color value
Remarks
The function return the color for the specified by .
| |
void SetNotify(BOOL bNotify = TRUE)
void SetNotify(HWND hWnd)
Parameters
bNotify
- If TRUE the control will be send the notification to parent window. Else the notification will not send
hWnd
- If non-NULL the control will be send the notification to specified window. Else the notification will not send Remarks
This function sets or removes the notification messages from the control.
| |
BOOL GetNotify()
Return value
TRUE if the control will be notified the specified window.
Remarks
This function determines will be send the notification messages from the control or not.
| |
void SetDefaultFont(BOOL bRedraw /* = TRUE */)
Parameters
bRedraw
- Specifies whether the control is to be redrawn. A nonzero value redraws the control. A 0 value does not redraw the control. The control is redrawn by default. Remarks
Sets the font to the default value (Courier, 8pt)
| |
BOOL SetFont(CFont & font, BOOL bRedraw /* = TRUE */)
BOOL SetFont(LOGFONT & lf, BOOL bRedraw /* = TRUE */)
BOOL SetFont(LPCTSTR lpszFaceName, int nSizePoints /* = 8 */, BOOL bUnderline /* = FALSE */, BOOL bBold /* = FALSE */,
BOOL bStrikeOut /* = FALSE */, BOOL bItalic /* = FALSE */,
BOOL bRedraw /* = TRUE */)
Parameters
font
- A CFont object allowing full control over the appearance of the font.
lf
- A LOGFONT structure allowing full control over the appearance of the font also.
lpszFaceName
- The font face name.
nSizePoints
- The font size in points. The default value is 8.
bUnderline
- Specifies whether the font is to be underlined. A nonzero value sets the font to be underlined. A 0 value sets the font not to be underlined. The font is not underlined by default.
bBold
- Specifies whether the font weight is to be bold or not. A nonzero value sets the font to be bold. A 0 value sets the font weight to be normal. The font weight is normal by default.
bStrikeOut
- Specifies whether the font is to be struck out or not. A nonzero value sets the font to be struck out. A 0 value sets the font not to be struck out. The font is not struck out by default.
bItalic
- Specifies whether the font style is to be italic or not. A nonzero value sets the font style to be italic. A 0 value sets the font style to be normal. The font style is normal by default.
bRedraw
- Specifies whether the control is to be redrawn. A nonzero value redraws the control. A 0 value does not redraw the control. The control is redrawn by default. Remarks
Sets the font for all elements of the control
Attention! You must set the font with fixed width (for example: Courier)
| |
void SetBeginAddress(int nAddress = 0, BOOL bRedraw = TRUE)
Parameters
nAddress
- The address which will be the first address on the screen.
bRedraw
- Specifies whether the control is to be redrawn. A nonzero value redraws the control. A 0 value does not redraw the control. The control is redrawn by default. Remarks
Sets the first visible address on the screen
| |
int GetBeginAddress()
Return value
The function retrives the first visible address on the screen.
Remarks
Gets the first visible address on the screen
| |
void SetTrackMouseMove(BOOL bTrack = TRUE, BOOL bRedraw = TRUE)
Parameters
bTrack
- If TRUE the track mouse will enable.
bRedraw
- Specifies whether the control is to be redrawn. A nonzero value redraws the control. A 0 value does not redraw the control. The control is redrawn by default. Remarks
This function enables or disables the track mouse.
| |
int IsTrackMouseMove()
Return value
Function returns TRUE if track mouse is enabled.
Remarks
This function returns whether the track mouse is enabled.
| |
void SetSelectRange (int nBegin = 0, int nEnd = -1, BOOL bVisible = TRUE)
Parameters
nBegin
- The address which will be the first selected address.
nEnd
- The address which will be the end selected address. If nEnd
is -1 then the end selected address will be equal with begin selected address.
bVisible
- Specifies whether the control is to be redrawn so that first address has been seen. A nonzero value redraws the control. A 0 value does not redraw the control. The control is redrawn by default. Remarks
Sets the range of the selected block.
| |
void GetSelectRange (LPINT nBegin, LPINT nEnd)
Return values
nBegin
- The address which will be the first selected address.
nEnd
- The address which will be the end selected address. Remarks
Gets the range of the selected block.
| |
BOOL IsAddressSelected (int nAddress)
Parameters
nAddress
- The address which will be tested. Return value
The function returns TRUE if nAddress
into the range of selected block. Else FALSE
Remarks
Whether checks there is a specified address in the range of the selection
| |
void EnableSelect(BOOL bEnable /* = TRUE */)
Parameters
bEnable
- If TRUE then user can select the block of the data. Remarks
Calls the function for enable select the data or disable it.
| |
BOOL IsEnableSelect()
Return value
TRUE if user can select the block of the data.
Remarks
Determines can user select the data or not.
| |
void SetSpecialCharView(TCHAR chSymbol = NULL, BOOL bRedraw = TRUE)
Parameters
chSymbol
- the character which will draw instead the special characters (0 - 31). If NULL the symbol will not changed.
bRedraw
- Specifies whether the control is to be redrawn. A nonzero value redraws the control. A 0 value does not redraw the control. The control is redrawn by default.. Remarks
Sets the character which will drawn instead special characters (0 - 31).
| |
BOOL SetMenu(UINT nMenu, BOOL bRedraw = TRUE)
Parameters
nMenu
- ID number of the menu resource. Pass NULL to remove any menu from the control.
bRedraw
- Specifies whether the control is to be redrawn. A nonzero value redraws the control. A 0 value does not redraw the control. The control is redrawn by default. Remarks
This function associates a menu to the control. The menu will be displayed clicking the data in the control.
| |
void SetTooltipText(int nText, BOOL bActivate)
void SetTooltipText(CString sFormatTip, BOOL bActivate)
Parameters
nText
- ID number of the string resource containing the of the text to show.
sFormatTip
- Pointer to a null-terminated string containing the of the text to show.
bActivate
- If TRUE the tooltip will be created active. Remarks
This function sets the format string of the text to show in the control tooltip.
Format string
The Format string can contain the any text, and also special symbols of substitution of the data.
Special symbols must be the following format:
<code>% [direction
] [length
] [type
]
direction
- specifies the order of an arrangement the multi bytes data
PPDUMP_DATA_LOW_HIGH
)
length
- specified how much byte in the alone data (0 - 4) or blank. Where 0 or blank then use default length specified in style (PPDUMP_WORD_DATA
= 2 byte or ~PPDUMP_WORD_DATA
= 1 byte).
type
- specified the type of the format:
Example:
CString str = _T("Address : %RH Hex : %2H"); //Format string m_hex_ctrl.SetTooltipText(str); //Sets format string
The result on the client area of the control:
| |
void ActivateTooltip(BOOL bActivate = TRUE)
Parameters
bActivate
- If TRUE the tooltip will be activated. Remarks
This function enables or disables the control tooltip..
| |
CToolTipCtrl * GetTooltip()
Return value
The pointer to the tooltip object.
Remarks
This function gets pointer to the tooltip object
| |
Fields of the data |
|
PPDUMP_FIELD_ADDRESS |
The address field of data is exist |
PPDUMP_FIELD_HEX |
The hex field of data is exist |
PPDUMP_FIELD_DEC |
The dec field of data is exist |
PPDUMP_FIELD_BIN |
The bin field of data is exist |
PPDUMP_FIELD_OCT |
The oct field of data is exist |
PPDUMP_FIELD_ASCII |
The ascii field of data is exist |
PPDUMP_FIELD_ALL |
All fields of data is exist |
Fields of the control bar |
|
PPDUMP_BAR_ADDRESS |
The address field of control bar is exist |
PPDUMP_BAR_HEX |
The hex field of control bar is exist |
PPDUMP_BAR_DEC |
The dec field of control bar is exist |
PPDUMP_BAR_BIN |
The bin field of control bar is exist |
PPDUMP_BAR_OCT |
The oct field of control bar is exist |
PPDUMP_BAR_ASCII |
The ascii field of control bar is exist |
PPDUMP_BAR_ALL |
All fields of control bar is exist |
Miscellaneous |
|
PPDUMP_SEPARATOR_LINES |
Draws the separators between the fileds of data |
PPDUMP_READ_ONLY |
The control for read only (The address field can be change all the same) |
PPDUMP_WORD_DATA |
Work with word data, else with byte |
PPDUMP_NAMED_FIELDS |
Draws the headers of the data fileds |
PPDUMP_SELECT_DATA |
User can select the range of the data |
PPDUMP_DATA_LOW_HIGH |
User can select the order of the multi-byte data . If it flag is set then first byte is a low byte, else high byte |
PPDUMP_TRACK_MOUSE_MOVE |
User can select the order of the multi-byte data . If it flag is set then first byte is a low byte, else high byte |
for data |
|
PPDUMP_COLOR_DATA_FG |
The foreground color of the equal data in nNewArray and nOldArray |
PPDUMP_COLOR_DATA_CHANGE_FG |
The foreground color of the different data in nNewArray and nOldArray |
PPDUMP_COLOR_DATA_BK |
The background color of the data |
for in-place edit |
|
PPDUMP_COLOR_EDIT_FG |
The foreground color of the editing data without error |
PPDUMP_COLOR_EDIT_BK |
The background color of the editing data without error |
PPDUMP_COLOR_EDIT_ERR_FG |
The foreground color of the editing data with error |
PPDUMP_COLOR_EDIT_ERR_BK |
The background color of the editing data with error |
miscellaneous |
|
PPDUMP_COLOR_ADDRESS_FG |
The foreground color of the address field |
PPDUMP_COLOR_CARET_BK |
The background color of the data under the caret |
PPDUMP_COLOR_TEXT_HEADER |
The foreground color of the header |
PPDUMP_COLOR_SEPARATORS |
The color of the separator lines |
PPDUMP_COLOR_MOUSE_TRACK |
The color of track rectangle mouse |
The control has the three messages. First two transfer the following structure as parameter:
typedef struct tagNM_PPDUMP_CTRL { NMHDR hdr; int iAddress; //The editing or beginig address (excepting the offset address) UINT iValue; //The changed value (for UDM_PPDUMPCTRL_CHANGE_DATA message only) } NM_PPDUMP_CTRL;
UDM_PPDUMPCTRL_BEGIN_ADDR - User has changed first address on the screen. New address was passed as parameter iAddress
. The iValue
member has no value.
UDM_PPDUMPCTRL_CHANGE_DATA - Sends to parent window when user tries to change value at any address. The address passes as parameter iAddress
, and new value passes as parameter iValue
. The control doesn't change data directly. It just notifies the parent on necessity of change. The parent should change data and redraw control itself.
Here example:
Add to the header file.
afx_msg void NotifyEditData(NMHDR * pNMHDR, LRESULT * result);
To the implement file.
ON_NOTIFY (UDM_PPDUMPCTRL_CHANGE_DATA, IDC_EDIT1, NotifyEditData)and
void CParentDlg::NotifyEditData(NMHDR * pNMHDR, LRESULT * result) { *result = 0; //Gets pointers to structure NM_PPDUMP_CTRL NM_PPDUMP_CTRL * pNotify = (NM_PPDUMP_CTRL*)pNMHDR //Really changing data ... SetNewValueData(pNotify->iAddress, pNotify->iValue); //Redraw the control m_dump_ctrl.RedrawWindow(); }
Third message UDM_PPDUMPCTRL_MENU_CALLBACK sends to window when the user tries to display the menu. This message transfer the following structure as parameter:
typedef struct tagNM_PPDUMP_MENU { NMHDR hdr; HMENU nMenu; //Handle to the menu int iArea; //The area of the field data under the mouse int iAddress; //The address (excepting the offset address) under the mouse } NM_PPDUMP_MENU;
Fourth message UDM_PPDUMPCTRL_SELECTION sends to window when the user finished selecting of the data. It isn't sends else selection is disabled or selection equal to alone data. This message transfer the following structure as parameter:
typedef struct tagNM_PPDUMP_SEL { NMHDR hdr; int iFirstAddr; //The first address of the selection int iLastAddr; //The last address of the selection } NM_PPDUMP_SEL;
This control has following hotkeys
Hotkey | Description |
Moving of the caret | |
LEFT | The caret moves on one address backward |
RIGHT | The caret moves on one address forward |
UP | The caret moves on one line up |
DOWN | The caret moves on one line down |
HOME | The caret moves to the beginning of a line |
END | The caret moves to the end of a line |
CTRL+HOME | The caret moves to first address |
CTRL+END | The caret moves to end address |
PAGE UP | The caret moves on one screen up |
PAGE DOWN | The caret moves on one screen down |
The beginning of editing ... | |
CTRL+H | as HEX, if the field is exist in the control bar and not set PPDUMP_READ_ONLY style |
CTRL+D | as DEC, if the field is exist in the control bar and not set PPDUMP_READ_ONLY style |
CTRL+B | as BIN, if the field is exist in the control bar and not set PPDUMP_READ_ONLY style |
CTRL+O | as OCT, if the field is exist in the control bar and not set PPDUMP_READ_ONLY style |
CTRL+A | as ASCII, if the field is exist in the control bar and not set PPDUMP_READ_ONLY style |
ENTER | in first field of the data |
Hotkey | Description |
Moving of the caret | |
CTRL+LEFT | The edit moves on one address backward |
CTRL+RIGHT | The edit moves on one address forward |
CTRL+UP | The edit moves on one line up |
CTRL+DOWN | The edit moves on one line down |
CTRL+HOME | The edit moves to the beginning of a line |
CTRL+END | The edit moves to the end of a line |
PAGE UP | The edit moves on one screen up |
PAGE DOWN | The edit moves on one screen down |
Continuation of editing ... | |
CTRL+H | as HEX, if the field is exist in the control bar and not set PPDUMP_READ_ONLY style |
CTRL+D | as DEC, if the field is exist in the control bar and not set PPDUMP_READ_ONLY style |
CTRL+B | as BIN, if the field is exist in the control bar and not set PPDUMP_READ_ONLY style |
CTRL+O | as OCT, if the field is exist in the control bar and not set PPDUMP_READ_ONLY style |
CTRL+A | as ASCII, if the field is exist in the control bar and not set PPDUMP_READ_ONLY style |
TAB | to the next field |
SHIFT+TAB | to the previous field |
End of editing | |
ENTER | OK |
ESC | Cancel |
07 Aug 2002 | First release |
13 Aug 2002 | Release version 1.1 - Added new style PPDUMP_DATA_LOW_HIGH - Added support tootip - Added new message UDM_PPDUMPCTRL_SELECTION and structure NM_DUMP_SEL - Added support mouse wheel (Thanks to Darren Schroeder) - Fixed problem with large arrays (Thanks to Bill Morrison - Rosinante Software) - Other minor fixed |
19 Aug 2002 |
Release version 1.2 |
CButtonST
in which decisions of some questions have been found.
CMemDC
.