| 1 |
26 |
unneback |
//####COPYRIGHTBEGIN####
|
| 2 |
|
|
//
|
| 3 |
|
|
// ----------------------------------------------------------------------------
|
| 4 |
|
|
// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
|
| 5 |
|
|
//
|
| 6 |
|
|
// This program is part of the eCos host tools.
|
| 7 |
|
|
//
|
| 8 |
|
|
// This program is free software; you can redistribute it and/or modify it
|
| 9 |
|
|
// under the terms of the GNU General Public License as published by the Free
|
| 10 |
|
|
// Software Foundation; either version 2 of the License, or (at your option)
|
| 11 |
|
|
// any later version.
|
| 12 |
|
|
//
|
| 13 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
| 14 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 15 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
| 16 |
|
|
// more details.
|
| 17 |
|
|
//
|
| 18 |
|
|
// You should have received a copy of the GNU General Public License along with
|
| 19 |
|
|
// this program; if not, write to the Free Software Foundation, Inc.,
|
| 20 |
|
|
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 21 |
|
|
//
|
| 22 |
|
|
// ----------------------------------------------------------------------------
|
| 23 |
|
|
//
|
| 24 |
|
|
//####COPYRIGHTEND####
|
| 25 |
|
|
//===========================================================================
|
| 26 |
|
|
//===========================================================================
|
| 27 |
|
|
//#####DESCRIPTIONBEGIN####
|
| 28 |
|
|
//
|
| 29 |
|
|
// Author(s): sdf
|
| 30 |
|
|
// Contact(s): sdf
|
| 31 |
|
|
// Date: 1998/10/06
|
| 32 |
|
|
// Version: 0.01
|
| 33 |
|
|
// Purpose:
|
| 34 |
|
|
// Description: This is the interface of the messagebox class
|
| 35 |
|
|
// Requires:
|
| 36 |
|
|
// Provides:
|
| 37 |
|
|
// See also:
|
| 38 |
|
|
// Known bugs:
|
| 39 |
|
|
// Usage:
|
| 40 |
|
|
//
|
| 41 |
|
|
//####DESCRIPTIONEND####
|
| 42 |
|
|
//
|
| 43 |
|
|
//===========================================================================
|
| 44 |
|
|
#if !defined(AFX_MessageBox_H__A7F011B1_4736_11D2_B377_444553540000__INCLUDED_)
|
| 45 |
|
|
#define AFX_MessageBox_H__A7F011B1_4736_11D2_B377_444553540000__INCLUDED_
|
| 46 |
|
|
|
| 47 |
|
|
#if _MSC_VER >= 1000
|
| 48 |
|
|
#pragma once
|
| 49 |
|
|
#endif // _MSC_VER >= 1000
|
| 50 |
|
|
|
| 51 |
|
|
/////////////////////////////////////////////////////////////////////////////
|
| 52 |
|
|
//
|
| 53 |
|
|
// CMessageBox dialog
|
| 54 |
|
|
// Simon FitzMaurice, October 1998
|
| 55 |
|
|
//
|
| 56 |
|
|
// CMessageBox replicates the functionality of CWnd::MessageBox(), but also
|
| 57 |
|
|
// allows the creation of custom and modeless messageboxes.
|
| 58 |
|
|
//
|
| 59 |
|
|
// Use the 3-parameter constructor and DoModal() to obtain the usual results.
|
| 60 |
|
|
// [Create() may be used to invoke a modeless dialog]
|
| 61 |
|
|
// All flags described in "Message-Box Styles" are supported with the
|
| 62 |
|
|
// exception of MB_TASKMODAL (not useful within an MFC app).
|
| 63 |
|
|
// In addition, two new styles are available: MB_YESNOALL and MB_YESNOALLCANCEL. These
|
| 64 |
|
|
// add "Yes All" and "No All" buttons to the normal MB_YESNO and MB_YESNOCANCEL,
|
| 65 |
|
|
// respectively (with ids of IDYESALL and IDNOALL). The MB_DEFBUTTON(n) macro
|
| 66 |
|
|
// may be used to extend extend the series MB_DEFBUTTON1, MB_DEFBUTTON2,
|
| 67 |
|
|
// MB_DEFBUTTON3 ...
|
| 68 |
|
|
//
|
| 69 |
|
|
// Use the parameterless constructor to customize the messagebox. Buttons must
|
| 70 |
|
|
// be added [using AddButton()] and other attributes changed before calling
|
| 71 |
|
|
// DoModal() or Create().
|
| 72 |
|
|
//
|
| 73 |
|
|
// In the case of Create(), the CMessageBox object must be allocated on the heap;
|
| 74 |
|
|
// it deletes itself when the dialog is dismissed. The parameters of Create()
|
| 75 |
|
|
// may be used to specify that the parent be sent a notification message when
|
| 76 |
|
|
// this happens.
|
| 77 |
|
|
//
|
| 78 |
|
|
/////////////////////////////////////////////////////////////////////////////
|
| 79 |
|
|
|
| 80 |
|
|
#define MB_YESNOALL 13
|
| 81 |
|
|
#define MB_YESNOALLCANCEL 14
|
| 82 |
|
|
|
| 83 |
|
|
// Extend the series MB_DEFBUTTON1, MB_DEFBUTTON2, MB_DEFBUTTON3 ...
|
| 84 |
|
|
#define MB_DEFBUTTON(n) ((n<<8)&MB_DEFMASK)
|
| 85 |
|
|
|
| 86 |
|
|
#define IDYESALL 14
|
| 87 |
|
|
#define IDNOALL 15
|
| 88 |
|
|
|
| 89 |
|
|
#include <afxtempl.h>
|
| 90 |
|
|
|
| 91 |
|
|
class CMessageBox : public CDialog
|
| 92 |
|
|
{
|
| 93 |
|
|
// Construction
|
| 94 |
|
|
public:
|
| 95 |
|
|
|
| 96 |
|
|
// Ctor to build standard messagebox:
|
| 97 |
|
|
CMessageBox(const CString &strText,const CString &strCaption=_T("Error"),UINT Flag=MB_OK); // standard constructor
|
| 98 |
|
|
|
| 99 |
|
|
// Use this ctor if using custom buttons:
|
| 100 |
|
|
CMessageBox();
|
| 101 |
|
|
|
| 102 |
|
|
virtual ~CMessageBox();
|
| 103 |
|
|
|
| 104 |
|
|
// Run the messagebox as a modeless dialog. If msg is non-zero, post pWnd
|
| 105 |
|
|
// msg when the dialog is dismissed. The loword of wParam of msg will
|
| 106 |
|
|
// contain the id of the button clicked and the hiword wParamHigh. By
|
| 107 |
|
|
// specifying msg as WM_COMMAND and wParamHigh as BN_CLICKED (the default
|
| 108 |
|
|
// values), ON_BN_CLICKED handlers may be used.
|
| 109 |
|
|
BOOL Create(CWnd *pWnd=NULL,UINT msg=0,WORD wParamHigh=BN_CLICKED);
|
| 110 |
|
|
|
| 111 |
|
|
// Set the caption
|
| 112 |
|
|
void SetCaption (const CString &strCaption);
|
| 113 |
|
|
|
| 114 |
|
|
// Set static text color (this function does not affect the color of button text)
|
| 115 |
|
|
void SetTextColor(COLORREF cr){m_crText=cr;}
|
| 116 |
|
|
|
| 117 |
|
|
// Make the messagebox topmost
|
| 118 |
|
|
void SetTopMost() { m_bTopMost=true; }
|
| 119 |
|
|
|
| 120 |
|
|
// Set the static text
|
| 121 |
|
|
void SetText (const CString &str){m_strText=str;}
|
| 122 |
|
|
|
| 123 |
|
|
// This member is public to allow the caller to manipulate it directly
|
| 124 |
|
|
// (e.g. by means of CString::Format):
|
| 125 |
|
|
CString m_strText;
|
| 126 |
|
|
|
| 127 |
|
|
// Set the font (for static text and buttons)
|
| 128 |
|
|
void SetFont (CFont *pFont){m_pFont=pFont;}
|
| 129 |
|
|
|
| 130 |
|
|
// Justify text left, center or right
|
| 131 |
|
|
void SetTextJustification (UINT n) { ASSERT(SS_LEFT==n||SS_CENTER==n||SS_RIGHT==n); m_nJustify=n; }
|
| 132 |
|
|
|
| 133 |
|
|
// Add a button with given caption, id and whether enabled:
|
| 134 |
|
|
void AddButton (const CString &strCaption,UINT id, bool bEnabled=true);
|
| 135 |
|
|
|
| 136 |
|
|
// Set the nth button as default
|
| 137 |
|
|
void SetDefaultButton (UINT nIndex);
|
| 138 |
|
|
|
| 139 |
|
|
// Count of buttons created
|
| 140 |
|
|
UINT ButtonCount() const { return (UINT)m_arBInfo.GetSize(); }
|
| 141 |
|
|
|
| 142 |
|
|
// Look up a button by its id. If the button is not found, -1 is returned.
|
| 143 |
|
|
int IndexOf (UINT id);
|
| 144 |
|
|
|
| 145 |
|
|
// Overrides
|
| 146 |
|
|
// ClassWizard generated virtual function overrides
|
| 147 |
|
|
//{{AFX_VIRTUAL(CMessageBox)
|
| 148 |
|
|
public:
|
| 149 |
|
|
virtual BOOL PreTranslateMessage(MSG* pMsg);
|
| 150 |
|
|
protected:
|
| 151 |
|
|
virtual void PostNcDestroy();
|
| 152 |
|
|
//}}AFX_VIRTUAL
|
| 153 |
|
|
|
| 154 |
|
|
// Implementation
|
| 155 |
|
|
protected:
|
| 156 |
|
|
bool m_bDialogCreated;
|
| 157 |
|
|
CWnd *m_pParentNotify; // Window to tell about dismissal
|
| 158 |
|
|
UINT m_nParentNotifcationMessage; // Message to send
|
| 159 |
|
|
WORD m_nParentNotifcationwParamHigh; // hi of wParam
|
| 160 |
|
|
bool m_bModeless;
|
| 161 |
|
|
COLORREF m_crText; // Text and button color
|
| 162 |
|
|
|
| 163 |
|
|
void Init();
|
| 164 |
|
|
|
| 165 |
|
|
// Dialog Data
|
| 166 |
|
|
typedef struct {
|
| 167 |
|
|
DLGTEMPLATE tmpl;
|
| 168 |
|
|
short wMenu[1];
|
| 169 |
|
|
short wClass[1];
|
| 170 |
|
|
short wTitle[1];
|
| 171 |
|
|
} DLGDATA;
|
| 172 |
|
|
static DLGDATA DlgData;
|
| 173 |
|
|
|
| 174 |
|
|
// Per-button information
|
| 175 |
|
|
struct CButtonInfo {
|
| 176 |
|
|
UINT m_id;
|
| 177 |
|
|
bool m_bEnabled;
|
| 178 |
|
|
CString m_strCaption;
|
| 179 |
|
|
CButton *m_pWnd;
|
| 180 |
|
|
public:
|
| 181 |
|
|
CButtonInfo (UINT id=0,bool bEnabled=false,const CString &strCaption=_T("")):
|
| 182 |
|
|
m_id(id),
|
| 183 |
|
|
m_bEnabled(bEnabled),
|
| 184 |
|
|
m_strCaption(strCaption),
|
| 185 |
|
|
m_pWnd(NULL)
|
| 186 |
|
|
{}
|
| 187 |
|
|
};
|
| 188 |
|
|
CArray<CButtonInfo,CButtonInfo&> m_arBInfo;
|
| 189 |
|
|
|
| 190 |
|
|
int m_nEscapeButton;
|
| 191 |
|
|
int m_nJustify; // SS_LEFT,SS_CENTER or SS_RIGHT
|
| 192 |
|
|
CButton &Button(int nIndex) const{return *(m_arBInfo[nIndex].m_pWnd);}
|
| 193 |
|
|
HICON m_hIcon;
|
| 194 |
|
|
bool m_bTopMost;
|
| 195 |
|
|
CString m_strCaption;
|
| 196 |
|
|
int m_nFocusButton;
|
| 197 |
|
|
UINT m_nDefaultButton;
|
| 198 |
|
|
|
| 199 |
|
|
CStatic * m_pStaticText;
|
| 200 |
|
|
CStatic * m_pStaticIcon;
|
| 201 |
|
|
|
| 202 |
|
|
CFont * m_pFont;
|
| 203 |
|
|
|
| 204 |
|
|
// Generated message map functions
|
| 205 |
|
|
//{{AFX_MSG(CMessageBox)
|
| 206 |
|
|
virtual BOOL OnInitDialog();
|
| 207 |
|
|
afx_msg void OnFontChange();
|
| 208 |
|
|
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
|
| 209 |
|
|
afx_msg void OnClose();
|
| 210 |
|
|
//}}AFX_MSG
|
| 211 |
|
|
afx_msg void OnButton(UINT);
|
| 212 |
|
|
DECLARE_MESSAGE_MAP()
|
| 213 |
|
|
};
|
| 214 |
|
|
|
| 215 |
|
|
int MessageBoxEx (const CString &strText,const CString &strCaption,UINT Flag);
|
| 216 |
|
|
|
| 217 |
|
|
//{{AFX_INSERT_LOCATION}}
|
| 218 |
|
|
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
|
| 219 |
|
|
|
| 220 |
|
|
#endif // !defined(AFX_MessageBox_H__A7F011B1_4736_11D2_B377_444553540000__INCLUDED_)
|