1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
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)
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
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.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
25 //===========================================================================
26 //===========================================================================
27 //#####DESCRIPTIONBEGIN####
34 // Description: This is the interface of the messagebox class
41 //####DESCRIPTIONEND####
43 //===========================================================================
44 #if !defined(AFX_MessageBox_H__A7F011B1_4736_11D2_B377_444553540000__INCLUDED_)
45 #define AFX_MessageBox_H__A7F011B1_4736_11D2_B377_444553540000__INCLUDED_
49 #endif // _MSC_VER >= 1000
51 /////////////////////////////////////////////////////////////////////////////
54 // Simon FitzMaurice, October 1998
56 // CMessageBox replicates the functionality of CWnd::MessageBox(), but also
57 // allows the creation of custom and modeless messageboxes.
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,
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().
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
78 /////////////////////////////////////////////////////////////////////////////
80 #define MB_YESNOALL 13
81 #define MB_YESNOALLCANCEL 14
83 // Extend the series MB_DEFBUTTON1, MB_DEFBUTTON2, MB_DEFBUTTON3 ...
84 #define MB_DEFBUTTON(n) ((n<<8)&MB_DEFMASK)
91 class CMessageBox : public CDialog
96 // Ctor to build standard messagebox:
97 CMessageBox(const CString &strText,const CString &strCaption=_T("Error"),UINT Flag=MB_OK); // standard constructor
99 // Use this ctor if using custom buttons:
102 virtual ~CMessageBox();
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);
112 void SetCaption (const CString &strCaption);
114 // Set static text color (this function does not affect the color of button text)
115 void SetTextColor(COLORREF cr){m_crText=cr;}
117 // Make the messagebox topmost
118 void SetTopMost() { m_bTopMost=true; }
120 // Set the static text
121 void SetText (const CString &str){m_strText=str;}
123 // This member is public to allow the caller to manipulate it directly
124 // (e.g. by means of CString::Format):
127 // Set the font (for static text and buttons)
128 void SetFont (CFont *pFont){m_pFont=pFont;}
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; }
133 // Add a button with given caption, id and whether enabled:
134 void AddButton (const CString &strCaption,UINT id, bool bEnabled=true);
136 // Set the nth button as default
137 void SetDefaultButton (UINT nIndex);
139 // Count of buttons created
140 UINT ButtonCount() const { return (UINT)m_arBInfo.GetSize(); }
142 // Look up a button by its id. If the button is not found, -1 is returned.
143 int IndexOf (UINT id);
146 // ClassWizard generated virtual function overrides
147 //{{AFX_VIRTUAL(CMessageBox)
149 virtual BOOL PreTranslateMessage(MSG* pMsg);
151 virtual void PostNcDestroy();
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
161 COLORREF m_crText; // Text and button color
172 static DLGDATA DlgData;
174 // Per-button information
178 CString m_strCaption;
181 CButtonInfo (UINT id=0,bool bEnabled=false,const CString &strCaption=_T("")):
183 m_bEnabled(bEnabled),
184 m_strCaption(strCaption),
188 CArray<CButtonInfo,CButtonInfo&> m_arBInfo;
191 int m_nJustify; // SS_LEFT,SS_CENTER or SS_RIGHT
192 CButton &Button(int nIndex) const{return *(m_arBInfo[nIndex].m_pWnd);}
195 CString m_strCaption;
197 UINT m_nDefaultButton;
199 CStatic * m_pStaticText;
200 CStatic * m_pStaticIcon;
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();
211 afx_msg void OnButton(UINT);
212 DECLARE_MESSAGE_MAP()
215 int MessageBoxEx (const CString &strText,const CString &strCaption,UINT Flag);
217 //{{AFX_INSERT_LOCATION}}
218 // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
220 #endif // !defined(AFX_MessageBox_H__A7F011B1_4736_11D2_B377_444553540000__INCLUDED_)