]> git.saurik.com Git - wxWidgets.git/blame - src/msw/msgdlg.cpp
Added chapter on collection and container classes to contents
[wxWidgets.git] / src / msw / msgdlg.cpp
CommitLineData
2bda0e17
KB
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
0d7ea902 9// Licence: wxWindows license
2bda0e17
KB
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
35bc781e 24 #include "wx/app.h"
0d7ea902
VZ
25 #include "wx/defs.h"
26 #include "wx/utils.h"
27 #include "wx/dialog.h"
28 #include "wx/msgdlg.h"
2bda0e17
KB
29#endif
30
31#include "wx/msw/private.h"
32
2bda0e17 33IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
2bda0e17 34
0d7ea902
VZ
35wxMessageDialog::wxMessageDialog(wxWindow *parent,
36 const wxString& message,
37 const wxString& caption,
38 long style,
39 const wxPoint& WXUNUSED(pos))
2bda0e17
KB
40{
41 m_caption = caption;
42 m_message = message;
43 m_dialogStyle = style;
44 m_parent = parent;
45}
46
0d7ea902 47int wxMessageDialog::ShowModal()
2bda0e17 48{
0d7ea902
VZ
49 if ( !wxTheApp->GetTopWindow() )
50 {
51 // when the message box is shown from wxApp::OnInit() (i.e. before the
52 // message loop is entered), this must be done or the next message box
53 // will never be shown - just try putting 2 calls to wxMessageBox() in
54 // OnInit() to see it
55 while ( wxTheApp->Pending() )
56 wxTheApp->Dispatch();
57 }
93c95e18 58
0d7ea902
VZ
59 HWND hWnd = 0;
60 if (m_parent) hWnd = (HWND) m_parent->GetHWND();
61 unsigned int msStyle = MB_OK;
62 if (m_dialogStyle & wxYES_NO)
63 {
64 if (m_dialogStyle & wxCANCEL)
65 msStyle = MB_YESNOCANCEL;
66 else
67 msStyle = MB_YESNO;
93c95e18 68
0d7ea902
VZ
69 if (m_dialogStyle & wxNO_DEFAULT)
70 msStyle |= MB_DEFBUTTON2;
71 }
72
73 if (m_dialogStyle & wxOK)
74 {
75 if (m_dialogStyle & wxCANCEL)
76 msStyle = MB_OKCANCEL;
77 else
78 msStyle = MB_OK;
79 }
80 if (m_dialogStyle & wxICON_EXCLAMATION)
81 msStyle |= MB_ICONEXCLAMATION;
82 else if (m_dialogStyle & wxICON_HAND)
83 msStyle |= MB_ICONHAND;
84 else if (m_dialogStyle & wxICON_INFORMATION)
85 msStyle |= MB_ICONINFORMATION;
86 else if (m_dialogStyle & wxICON_QUESTION)
87 msStyle |= MB_ICONQUESTION;
2bda0e17 88
0d7ea902
VZ
89 if (hWnd)
90 msStyle |= MB_APPLMODAL;
91 else
92 msStyle |= MB_TASKMODAL;
93c95e18 93
0d7ea902
VZ
94 int msAns = MessageBox(hWnd, (LPCTSTR)m_message.c_str(),
95 (LPCTSTR)m_caption.c_str(), msStyle);
96 int ans = wxOK;
97 switch (msAns)
98 {
99 case IDCANCEL:
100 ans = wxID_CANCEL;
101 break;
102 case IDOK:
103 ans = wxID_OK;
104 break;
105 case IDYES:
106 ans = wxID_YES;
107 break;
108 case IDNO:
109 ans = wxID_NO;
110 break;
111 }
112 return ans;
2bda0e17
KB
113}
114