-
Notifications
You must be signed in to change notification settings - Fork 77
/
DlgDataEditor.cpp
176 lines (143 loc) · 5.12 KB
/
DlgDataEditor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*****************************************************************************/
/* DlgDataEditor.cpp Copyright (c) Ladislav Zezula 2014 */
/*---------------------------------------------------------------------------*/
/* Description: Common module for a few simple dialogs */
/*---------------------------------------------------------------------------*/
/* Date Ver Who Comment */
/* -------- ---- --- ------- */
/* 19.03.14 1.00 Lad Created */
/*****************************************************************************/
#include "FileTest.h"
#include "resource.h"
//-----------------------------------------------------------------------------
// Local structures
struct TDialogData
{
TAnchors * pAnchors;
ULONGLONG BaseAddress;
LPBYTE pbFileData;
size_t cbFileData;
HWND hDlg;
};
//-----------------------------------------------------------------------------
// Message handlers
static void OnInitDialog(HWND hDlg, LPARAM lParam)
{
TDialogData * pData = (TDialogData *)lParam;
TAnchors * pAnchors;
HWND hWndChild;
// Initialize dialog data
SetDialogIcon(hDlg, IDI_FILE_TEST);
SetDialogData(hDlg, pData);
pData->hDlg = hDlg;
// Center the dialog to parent
CenterWindowToParent(hDlg);
// Configure the anchors
pData->pAnchors = pAnchors = new TAnchors();
if(pAnchors != NULL)
{
pAnchors->AddAnchor(hDlg, IDC_FILE_DATA, akAll);
pAnchors->AddAnchor(hDlg, IDC_INFORMATION, akLeft | akRight | akBottom);
pAnchors->AddAnchor(hDlg, IDOK, akRight | akBottom);
}
// Configure the data viewer
hWndChild = GetDlgItem(hDlg, IDC_FILE_DATA);
if(hWndChild != NULL)
{
DataEditor_SetDataFormat(hWndChild, PtrPlatformSpecific, 0x10);
DataEditor_SetData(hWndChild, (ULONGLONG)pData->BaseAddress, pData->pbFileData, pData->cbFileData);
}
}
static void OnSize(HWND hDlg)
{
TDialogData * pData = ((TDialogData *)GetWindowLongPtr(hDlg, DWLP_USER));
if(pData != NULL && pData->pAnchors != NULL)
pData->pAnchors->OnSize();
}
static void OnGetMinMaxInfo(HWND hDlg, LPARAM lParam)
{
TDialogData * pData = ((TDialogData *)GetWindowLongPtr(hDlg, DWLP_USER));
if(pData != NULL && pData->pAnchors != NULL)
pData->pAnchors->OnGetMinMaxInfo(lParam);
}
static void OnNotify(HWND hDlg, NMHDR * pNMHDR)
{
if(pNMHDR->code == DEN_EXCEPTION)
{
PDTE_EXCEPTION_DATA pExceptionData = (PDTE_EXCEPTION_DATA)pNMHDR;
HWND hWndChild = GetDlgItem(hDlg, IDC_INFORMATION);
if(hWndChild != NULL)
{
SetWindowTextRc(hWndChild, IDS_DATA_EXCEPTION,
pExceptionData->WriteOperation ? _T("writing") : _T("reading"),
pExceptionData->ExceptionAddress);
}
}
}
static void OnDestroy(HWND hDlg)
{
TDialogData * pData = ((TDialogData *)GetWindowLongPtr(hDlg, DWLP_USER));
if(pData != NULL)
{
if(pData->pAnchors != NULL)
delete pData->pAnchors;
pData->pAnchors = NULL;
}
}
static int OnFlushViewOfFileClick(HWND hDlg)
{
TDialogData* pData = ((TDialogData*)GetWindowLongPtr(hDlg, DWLP_USER));
FlushViewOfFile(pData->pbFileData, pData->cbFileData);
return TRUE;
}
static INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
UINT nIDCtrl;
UINT nIDNotify;
// Dialog initialization
switch(uMsg)
{
case WM_INITDIALOG:
OnInitDialog(hDlg, lParam);
return TRUE;
case WM_SIZE:
OnSize(hDlg);
break;
case WM_GETMINMAXINFO:
OnGetMinMaxInfo(hDlg, lParam);
break;
case WM_NOTIFY:
OnNotify(hDlg, (NMHDR *)lParam);
break;
case WM_COMMAND:
nIDNotify = HIWORD(wParam);
nIDCtrl = LOWORD(wParam);
if (nIDNotify == BN_CLICKED)
{
switch (nIDCtrl)
{
case IDC_FLUSH_VIEW:
OnFlushViewOfFileClick(hDlg);
break;
default:
EndDialog(hDlg, nIDCtrl);
}
}
break;
case WM_DESTROY:
OnDestroy(hDlg);
break;
}
return FALSE;
}
//-----------------------------------------------------------------------------
// Dialog functions
INT_PTR DataEditorDialog(HWND hParent, LPVOID BaseAddress, size_t ViewSize)
{
TDialogData Data;
ZeroMemory(&Data, sizeof(TDialogData));
Data.BaseAddress = (ULONGLONG)BaseAddress;
Data.pbFileData = (LPBYTE)BaseAddress;
Data.cbFileData = ViewSize;
return DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_DATA_EDITOR), hParent, DialogProc, (LPARAM)&Data);
}