[4dc6db]: GeneralMsgBox.h  Maximize  Restore  History

Download this file

182 lines (143 with data), 5.6 kB

  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
/*
* Copyright (c) 2003-2007 Rony Shapiro <ronys@users.sourceforge.net>.
* All rights reserved. Use of the code is allowed under the
* Artistic License 2.0 terms, as specified in the LICENSE file
* distributed with this code, or available from
* http://www.opensource.org/licenses/artistic-license-2.0.php
*/
/*
* GeneralMsgBox.h
*
* Defines a extended Message Box class with fancy features as:
* - HTML Format support
* - Customizable buttons
* - Customizable icon
*
* This is a cut down version of TcxMsgBox by Thales P. Carvalho but then
* significantly enhanced to support text with HTML formatting and links.
* instead of a RTF string.
* See www.codeproject.com for the original code
*/
#pragma once
#include <algorithm>
#include <vector>
#include <string>
#include <bitset>
/////////////////////////////////////////////////////////////////////////////
// CGeneralMsgBox
class CGeneralMsgBox : private CDialog
{
// Basic
public:
// Constructor
CGeneralMsgBox(CWnd* pParentWnd = NULL);
// Destructor
virtual ~CGeneralMsgBox();
// Execute
int DoModal();
// Buttons operations
void AddButton(UINT uIDC, LPCTSTR pszText,
BOOL bIsDefault = FALSE,
BOOL bIsEscape = FALSE);
void AddButton(UINT uIDC, UINT uIdText = (UINT)-1,
BOOL bIsDefault = FALSE,
BOOL bIsEscape = FALSE);
// Title operations
void SetTitle(LPCTSTR pszTitle);
void SetTitle(UINT uIdTitle);
// Message operations
BOOL SetMsg(UINT uMsgId);
BOOL SetMsg(LPCTSTR pszMsg);
// Icon operations
void SetIcon(HICON hIcon);
void SetIcon(UINT uIcon);
void SetStandardIcon(LPCTSTR pszIconName);
void SetStandardIcon(UINT uIcon);
// Metric enumerators (see SetMetric and GetMetric)
enum {CX_LEFT_BORDER, CX_RIGHT_BORDER,
CY_TOP_BORDER, CY_BOTTOM_BORDER,
CX_ICON_MSG_SPACE, CY_BTNS_MSG_SPACE,
CX_BTN_BORDER, CY_BTN_BORDER,
CX_BTNS_SPACE, CX_MIN_BTN,
NUM_OF_METRICS
};
// Set a metric (in dialog units)
void SetMetric(int iMetric, int xy);
// Get a metric (in dialog units)
int GetMetric(int iMetric);
private:
// HTML formatting functiond
CString GetTextFormatting(CString csHTML, int &iError);
COLORREF ConvertColourToColorRef(CString &csValue);
int ConvertSizeToPoints(CString &csValue, int &iCurrentSize);
int ConvertPointsToSize(const int iCurrentPoints);
enum {FACENAMECHANGED = 0, SIZECHANGED, COLOURCHANGED};
enum EntryType {Bold, Italic, Underline, Font, Colour, Size, Name, Link};
// Formating for Bold, Italic, Underline, Colour, Font Size & Font Name
struct st_format {
int iStart;
int iEnd;
enum EntryType entrytype;
COLORREF cr; // Only valid if entrytype = Colour
int iSize; // Only valid if entrytype = Size
TCHAR tcszFACENAME[LF_FACESIZE]; // Only valid if entrytype = Name
};
// URL for friendly name in text
struct ALink {
int iStart;
int iEnd;
TCHAR tcszURL[_MAX_PATH];
};
// Vectors of format changes to be applied to the text string
std::vector<st_format> m_vFormat;
std::vector<ALink> m_vALink;
static bool iStartCompare(st_format elem1, st_format elem2);
// Graphical attributes
int m_aMetrics[NUM_OF_METRICS]; // basic metrics (dialog units)
CSize m_dimMsg; // message dimension (pixels)
CSize m_dimBtn; // button dimension (pixels)
CSize m_dimIcon; // icon dimension (pixels)
// Dialog unit base: dimensions used in d.u. <-> pixel conversion
enum {CX_DLGUNIT_BASE = 1000, CY_DLGUNIT_BASE = 1000};
// Pixel dimensions of the dialog unit base
CSize m_dimDlgUnit;
// Controls' attributes
UINT m_uDefCmdId; // default command ID: <Return>
UINT m_uEscCmdId; // escape command ID: <ESC> or box close
CStatic m_stIconCtrl; // the icon control
CRichEditCtrl m_edCtrl; // the RTF control
// Button's attributes
struct BTNDATA {
UINT uIDC; // button ID
CString strBtn; // button Text
};
CArray<BTNDATA,const BTNDATA&> m_aBtns; // buttons' attributes
// Message attributes
HICON m_hIcon; // icon handle
CString m_strMsg; // the message
CString m_strTitle; // the title
// Overrides
virtual BOOL OnInitDialog();
virtual BOOL OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult);
virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
virtual BOOL PreTranslateMessage(MSG* pMsg);
// Utility - creating the nested controls
void CreateRtfCtrl();
void CreateBtns();
void CreateIcon();
void UpdateLayout();
int FromDlgX(int x);
int FromDlgY(int y);
};
/////////////////////////////////////////////////////////////////////////////
// CGeneralMsgBox - inlined member functions
inline void CGeneralMsgBox::SetTitle(LPCTSTR pszTitle)
{ m_strTitle = pszTitle; }
inline void CGeneralMsgBox::SetTitle(UINT uIdTitle)
{ VERIFY(m_strTitle.LoadString(uIdTitle)); }
inline void CGeneralMsgBox::SetMetric(int iMetric, int nValue)
{ ASSERT(0 <= iMetric && iMetric < NUM_OF_METRICS);
m_aMetrics[iMetric] = nValue; }
inline int CGeneralMsgBox::GetMetric(int iMetric)
{ ASSERT(0 <= iMetric && iMetric < NUM_OF_METRICS);
return m_aMetrics[iMetric]; }

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks