forked from chrisoldwood/DDEQuery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppDlg.hpp
237 lines (196 loc) · 4.77 KB
/
AppDlg.hpp
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/******************************************************************************
** (C) Chris Oldwood
**
** MODULE: APPDLG.HPP
** COMPONENT: The Application.
** DESCRIPTION: The CAppDlg class declaration.
**
*******************************************************************************
*/
// Check for previous inclusion
#ifndef APPDLG_HPP
#define APPDLG_HPP
#if _MSC_VER > 1000
#pragma once
#endif
#include <WCL/MainDlg.hpp>
#include <WCL/Buffer.hpp>
#include <WCL/DateTime.hpp>
#include <map>
#include <WCL/CommonUI.hpp>
// Forward declarations.
class CDDELink;
/******************************************************************************
**
** This is the main application dialog.
**
*******************************************************************************
*/
class CAppDlg : public CMainDlg
{
public:
//
// Constructors/Destructor.
//
CAppDlg();
//
// Methods.
//
CString GetItemName();
CString GetItemValue();
uint GetSelFormat();
void SetItemName(const CString& strName);
void SetItemValue(const CBuffer& oBuffer, uint nFormat);
void SetItemFocus();
void SetFormatFocus();
void AddLink(CDDELink* pLink);
void UpdateLink(CDDELink* pLink, const CBuffer& oValue, bool bIsAdvise);
void RemoveLink(size_t nItem);
void RemoveAllLinks();
bool IsLinkSelected();
bool IsLinkUnadvised(CDDELink* pLink);
CBuffer GetLinkLastValue(CDDELink* pLink);
CDDELink* GetFirstSelLink();
CDDELink* GetLink(size_t nItem);
size_t GetAllSelLinks(CListView::Items& vItems);
void EnableUI(bool bEnable);
protected:
/**************************************************************************
** Structure used to hold link and last advise details.
*/
struct LinkData
{
//
// Methods.
//
LinkData(CDDELink* pLink);
void SetCurrentValue(const CBuffer& oValue);
void SetLastAdvise(const CBuffer& oValue);
//
// Members.
//
CDDELink* m_pLink; // The link.
DWORD m_dwLastAdvise; // Tick count at last advise.
CDateTime m_dtLastAdvise; // The time of last advise.
CBuffer m_oLastAdvise; // The last advise value.
uint m_nAdviseCount; // The number of advises.
};
// Template shorthands.
typedef std::map<CDDELink*, LinkData*> CLinksData;
//
// Members.
//
int m_nSortCol;
bool m_bSortAsc;
CLinksData m_oLinksData;
CString m_strLastItem;
CBuffer m_oLastValue;
uint m_nLastFormat;
CFont m_font; //!< The font to use for the controls.
//
// Controls.
//
CLabel m_txItem;
CComboBox m_cbFormat;
CEditBox m_ebItem;
CEditBox m_ebValue;
CButton m_btnValue;
CLabel m_txLinks;
CListView m_lvLinks;
//
// Constants.
//
static const uint TIMER_ID = 1; // ID of "flash" timer.
static const uint TIMER_FREQ = 100; // Frequency of "flash" timer.
enum Column
{
ITEM_NAME = 0,
LAST_VALUE = 1,
ADVISE_TIME = 2,
ADVISE_COUNT = 3,
};
enum LinkImage
{
IMG_BLANK = 0,
IMG_FLASH = 1,
};
//
// Message processors.
//
virtual void OnInitDialog();
virtual void OnDestroy();
virtual void OnTimer(uint nTimerID);
LRESULT OnLinksSelchange(NMHDR& oHdr);
LRESULT OnLinksClickColumn(NMHDR& rMsgHdr);
LRESULT OnLinksRightClick(NMHDR& oHdr);
LRESULT OnLinksDoubleClick(NMHDR& oHdr);
void OnItemChanged();
void OnValueChanged();
void OnFullValue();
// Sort function.
static int CALLBACK Compare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
//
// Internal methods.
//
void UpdateTitle();
void EnableFullValue(bool bEnable);
};
/******************************************************************************
**
** Implementation of inline functions.
**
*******************************************************************************
*/
inline CString CAppDlg::GetItemName()
{
return m_ebItem.Text();
}
inline CString CAppDlg::GetItemValue()
{
return m_ebValue.Text();
}
inline void CAppDlg::SetItemName(const CString& strName)
{
m_ebItem.Text(strName);
}
inline void CAppDlg::SetItemFocus()
{
m_ebItem.Focus();
}
inline void CAppDlg::SetFormatFocus()
{
m_cbFormat.Focus();
}
inline bool CAppDlg::IsLinkSelected()
{
return m_lvLinks.IsSelection();
}
inline size_t CAppDlg::GetAllSelLinks(CListView::Items& vItems)
{
return m_lvLinks.Selections(vItems);
}
inline CDDELink* CAppDlg::GetLink(size_t nItem)
{
ASSERT(nItem != LB_ERR);
return static_cast<CDDELink*>(m_lvLinks.ItemPtr(nItem));
}
inline CAppDlg::LinkData::LinkData(CDDELink* pLink)
: m_pLink(pLink)
, m_dwLastAdvise(::GetTickCount())
, m_nAdviseCount(0)
{
}
inline void CAppDlg::LinkData::SetCurrentValue(const CBuffer& oValue)
{
m_dwLastAdvise = ::GetTickCount();
m_dtLastAdvise = CDateTime::Current();
m_oLastAdvise = oValue;
}
inline void CAppDlg::LinkData::SetLastAdvise(const CBuffer& oValue)
{
m_dwLastAdvise = ::GetTickCount();
m_dtLastAdvise = CDateTime::Current();
m_oLastAdvise = oValue;
m_nAdviseCount++;
}
#endif //APPDLG_HPP