]> git.saurik.com Git - wxWidgets.git/blob - src/msw/msgdlg.cpp
added some utils (tex2rtf, helpgen, makegen) to make system
[wxWidgets.git] / src / msw / msgdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msgdlg.cpp
3 // Purpose: wxMessageDialog
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "msgdlg.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/defs.h"
25 #include "wx/utils.h"
26 #include "wx/dialog.h"
27 #include "wx/msgdlg.h"
28 #endif
29
30 #include "wx/msw/private.h"
31
32 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
33
34 wxMessageDialog::wxMessageDialog(wxWindow *parent,
35 const wxString& message,
36 const wxString& caption,
37 long style,
38 const wxPoint& WXUNUSED(pos))
39 {
40 m_caption = caption;
41 m_message = message;
42 m_dialogStyle = style;
43 m_parent = parent;
44 }
45
46 int wxMessageDialog::ShowModal()
47 {
48 if ( !wxTheApp->GetTopWindow() )
49 {
50 // when the message box is shown from wxApp::OnInit() (i.e. before the
51 // message loop is entered), this must be done or the next message box
52 // will never be shown - just try putting 2 calls to wxMessageBox() in
53 // OnInit() to see it
54 while ( wxTheApp->Pending() )
55 wxTheApp->Dispatch();
56 }
57
58 HWND hWnd = 0;
59 if (m_parent) hWnd = (HWND) m_parent->GetHWND();
60 unsigned int msStyle = MB_OK;
61 if (m_dialogStyle & wxYES_NO)
62 {
63 if (m_dialogStyle & wxCANCEL)
64 msStyle = MB_YESNOCANCEL;
65 else
66 msStyle = MB_YESNO;
67
68 if (m_dialogStyle & wxNO_DEFAULT)
69 msStyle |= MB_DEFBUTTON2;
70 }
71
72 if (m_dialogStyle & wxOK)
73 {
74 if (m_dialogStyle & wxCANCEL)
75 msStyle = MB_OKCANCEL;
76 else
77 msStyle = MB_OK;
78 }
79 if (m_dialogStyle & wxICON_EXCLAMATION)
80 msStyle |= MB_ICONEXCLAMATION;
81 else if (m_dialogStyle & wxICON_HAND)
82 msStyle |= MB_ICONHAND;
83 else if (m_dialogStyle & wxICON_INFORMATION)
84 msStyle |= MB_ICONINFORMATION;
85 else if (m_dialogStyle & wxICON_QUESTION)
86 msStyle |= MB_ICONQUESTION;
87
88 if (hWnd)
89 msStyle |= MB_APPLMODAL;
90 else
91 msStyle |= MB_TASKMODAL;
92
93 int msAns = MessageBox(hWnd, (LPCTSTR)m_message.c_str(),
94 (LPCTSTR)m_caption.c_str(), msStyle);
95 int ans = wxOK;
96 switch (msAns)
97 {
98 case IDCANCEL:
99 ans = wxID_CANCEL;
100 break;
101 case IDOK:
102 ans = wxID_OK;
103 break;
104 case IDYES:
105 ans = wxID_YES;
106 break;
107 case IDNO:
108 ans = wxID_NO;
109 break;
110 }
111 return ans;
112 }
113