]> git.saurik.com Git - wxWidgets.git/blame - src/msw/msgdlg.cpp
Added wxWindowBase::CentreOnParent to allow top level windows to be
[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
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 <stdio.h>
25#include "wx/defs.h"
26#include "wx/utils.h"
27#include "wx/dialog.h"
28#include "wx/msgdlg.h"
29#endif
30
31#include "wx/msw/private.h"
32
33#include <math.h>
34#include <stdlib.h>
35#include <string.h>
36
37#define wxDIALOG_DEFAULT_X 300
38#define wxDIALOG_DEFAULT_Y 300
39
40#if !USE_SHARED_LIBRARY
41IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
42#endif
43
44wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption,
45 long style, const wxPoint& pos)
46{
47 m_caption = caption;
48 m_message = message;
49 m_dialogStyle = style;
50 m_parent = parent;
51}
52
53int wxMessageDialog::ShowModal(void)
54{
55 HWND hWnd = 0;
56 if (m_parent) hWnd = (HWND) m_parent->GetHWND();
57 unsigned int msStyle = MB_OK;
58 if (m_dialogStyle & wxYES_NO)
59 {
60 if (m_dialogStyle & wxCANCEL)
61 msStyle = MB_YESNOCANCEL;
62 else
63 msStyle = MB_YESNO;
64 }
65 if (m_dialogStyle & wxOK)
66 {
67 if (m_dialogStyle & wxCANCEL)
68 msStyle = MB_OKCANCEL;
69 else
70 msStyle = MB_OK;
71 }
72 if (m_dialogStyle & wxICON_EXCLAMATION)
73 msStyle |= MB_ICONEXCLAMATION;
74 else if (m_dialogStyle & wxICON_HAND)
75 msStyle |= MB_ICONHAND;
76 else if (m_dialogStyle & wxICON_INFORMATION)
77 msStyle |= MB_ICONINFORMATION;
78 else if (m_dialogStyle & wxICON_QUESTION)
79 msStyle |= MB_ICONQUESTION;
80
81 if (hWnd)
82 msStyle |= MB_APPLMODAL;
83 else
84 msStyle |= MB_TASKMODAL;
85
86 int msAns = MessageBox(hWnd, (LPCSTR)(const char *)m_message, (LPCSTR)(const char *)m_caption, msStyle);
87 int ans = wxOK;
88 switch (msAns)
89 {
90 case IDCANCEL:
91 ans = wxID_CANCEL;
92 break;
93 case IDOK:
94 ans = wxID_OK;
95 break;
96 case IDYES:
97 ans = wxID_YES;
98 break;
99 case IDNO:
100 ans = wxID_NO;
101 break;
102 }
103 return ans;
104}
105