00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "MyMessageBox.h"
00009
00010 #ifdef _DEBUG
00011 #define new DEBUG_NEW
00012 #undef THIS_FILE
00013 static char THIS_FILE[] = __FILE__;
00014 #endif
00015
00016 CMyMessageBox::CMyMessageBox(CWnd* pParent )
00017 : CDialog(CMyMessageBox::IDD, pParent)
00018 {
00019 m_hIcon = NULL;
00020 m_bChecked = false;
00021 }
00022
00023 void CMyMessageBox::DoDataExchange(CDataExchange* pDX)
00024 {
00025 CDialog::DoDataExchange(pDX);
00026
00027 DDX_Control(pDX, IDC_CHECK1, m_wndCheckbox);
00028 DDX_Control(pDX, IDC_BTN3, m_wndBtn3);
00029 DDX_Control(pDX, IDC_BTN2, m_wndBtn2);
00030 DDX_Control(pDX, IDC_BTN1, m_wndBtn1);
00031 DDX_Control(pDX, IDC__MSG, m_wndMsg);
00032 DDX_Control(pDX, IDC__ICON, m_wndIcon);
00033
00034 }
00035
00036 BEGIN_MESSAGE_MAP(CMyMessageBox, CDialog)
00037
00038 ON_BN_CLICKED(IDC_BTN1, OnBtn1)
00039 ON_BN_CLICKED(IDC_BTN2, OnBtn2)
00040 ON_BN_CLICKED(IDC_BTN3, OnBtn3)
00041
00042 END_MESSAGE_MAP()
00043
00044 BOOL CMyMessageBox::OnInitDialog()
00045 {
00046 CDialog::OnInitDialog();
00047
00048 const int DX = 10;
00049 const int DY = 10;
00050 const int BTN_DX = 3;
00051
00052 ASSERT (m_strBtn1Text != "");
00053 ASSERT (m_strText != "");
00054
00055 if (m_hIcon)
00056 m_wndIcon.SetIcon (m_hIcon);
00057
00058 CRect rcIcon;
00059 m_wndIcon.GetWindowRect (&rcIcon);
00060 ScreenToClient (&rcIcon);
00061
00062 CRect rcCheckbox;
00063 m_wndCheckbox.GetWindowRect (&rcCheckbox);
00064 ScreenToClient (&rcCheckbox);
00065
00066 CDC* dc = GetDC ();
00067
00068 dc->SelectObject (GetFont ());
00069
00070 CRect rcBtn, rcBtn1, rcBtn2 (0,0,0,0), rcBtn3 (0,0,0,0);
00071 m_wndBtn1.GetWindowRect (&rcBtn);
00072 ScreenToClient (&rcBtn);
00073 dc->DrawText (m_strBtn1Text, &rcBtn1, DT_CALCRECT);
00074 if (m_strBtn2Text != "")
00075 {
00076 dc->DrawText (m_strBtn2Text, &rcBtn2, DT_CALCRECT);
00077 if (m_strBtn3Text != "")
00078 dc->DrawText (m_strBtn3Text, &rcBtn3, DT_CALCRECT);
00079 }
00080 int w = max (rcBtn1.Width (), rcBtn2.Width ());
00081 w = max (w, rcBtn3.Width ());
00082 w += 10;
00083 if (w < 70)
00084 w = 70;
00085 rcBtn.right = rcBtn.left + w;
00086
00087 CRect rcText (0,0,0,0);
00088 dc->DrawText (m_strText, &rcText, DT_CALCRECT);
00089
00090 CRect rcCBText (0,0,0,0);
00091 dc->DrawText (m_strCheckBoxText, &rcCBText, DT_CALCRECT);
00092 rcCBText.right += 25;
00093 if (rcCBText.Width () > rcText.Width ())
00094 rcText.right = rcText.top + rcCBText.Width ();
00095
00096 ReleaseDC (dc);
00097
00098 CRect rcDlg;
00099 GetWindowRect (&rcDlg);
00100
00101 CRect rcMsg;
00102 m_wndMsg.GetWindowRect (&rcMsg);
00103 ScreenToClient (&rcMsg);
00104
00105 if (m_strCheckBoxText == "")
00106 rcDlg.bottom -= rcCheckbox.Height () + DX;
00107
00108 if (m_hIcon == NULL)
00109 rcDlg.right -= rcIcon.Width () + DX;
00110
00111 int dx = rcDlg.Width () - rcMsg.Width ();
00112 int dy = rcDlg.Height () - rcMsg.Height ();
00113
00114 int DLG_WIDTH = rcText.Width () + dx;
00115
00116 int FRAME_WIDTH = rcIcon.left;
00117
00118 int LEFT = m_hIcon ? rcIcon.right + DX : FRAME_WIDTH;
00119
00120 int BTNSW = rcBtn.Width () + LEFT + FRAME_WIDTH;
00121 if (m_strBtn3Text != "")
00122 BTNSW += (rcBtn.Width () + BTN_DX) * 2;
00123 else if (m_strBtn2Text != "")
00124 BTNSW += rcBtn.Width () + BTN_DX;
00125
00126 if (DLG_WIDTH < BTNSW)
00127 DLG_WIDTH = BTNSW;
00128
00129 SetWindowPos (NULL, 0, 0, DLG_WIDTH, rcText.Height () + dy, SWP_NOMOVE | SWP_NOZORDER);
00130
00131 m_wndMsg.MoveWindow (LEFT, rcMsg.top, rcText.Width (), rcText.Height ());
00132 m_wndMsg.SetWindowText (m_strText);
00133
00134 SetWindowText (m_strTitle);
00135
00136 int h = rcCheckbox.Height ();
00137 rcCheckbox.top = rcMsg.top + rcText.Height () + DY;
00138 rcCheckbox.bottom = rcCheckbox.top + h;
00139
00140 if (m_strCheckBoxText != "")
00141 {
00142 m_wndCheckbox.SetWindowText (m_strCheckBoxText);
00143 m_wndCheckbox.MoveWindow (LEFT, rcCheckbox.top, rcText.Width (), rcCheckbox.Height ());
00144 CheckDlgButton (IDC_CHECK1, m_bChecked ? BST_CHECKED : BST_UNCHECKED);
00145 }
00146 else
00147 m_wndCheckbox.ShowWindow (SW_HIDE);
00148
00149 if (m_strCheckBoxText != "")
00150 {
00151 int h = rcBtn.Height ();
00152 rcBtn.top = rcCheckbox.bottom + DY;
00153 rcBtn.bottom = rcBtn.top + h;
00154 }
00155 else
00156 {
00157 int h = rcBtn.Height ();
00158 rcBtn.top = rcCheckbox.top;
00159 rcBtn.bottom = rcBtn.top + h;
00160 }
00161
00162 CRect rc; GetClientRect (&rc);
00163 int BTN_X = (rc.Width () + (BTNSW - LEFT)) / 2 - rcBtn.Width ();
00164
00165 if (m_strBtn3Text != "")
00166 {
00167 m_wndBtn3.SetWindowText (m_strBtn3Text);
00168 m_wndBtn3.MoveWindow (BTN_X, rcBtn.top, rcBtn.Width (), rcBtn.Height ());
00169 BTN_X -= rcBtn.Width () + BTN_DX;
00170 }
00171 else
00172 m_wndBtn3.ShowWindow (SW_HIDE);
00173
00174 if (m_strBtn2Text != "")
00175 {
00176 m_wndBtn2.SetWindowText (m_strBtn2Text);
00177 m_wndBtn2.MoveWindow (BTN_X, rcBtn.top, rcBtn.Width (), rcBtn.Height ());
00178 BTN_X -= rcBtn.Width () + BTN_DX;
00179 }
00180 else
00181 m_wndBtn2.ShowWindow (SW_HIDE);
00182
00183 m_wndBtn1.SetWindowText (m_strBtn1Text);
00184 m_wndBtn1.MoveWindow (BTN_X, rcBtn.top, rcBtn.Width (), rcBtn.Height ());
00185
00186 if (m_strBtn2Text != "")
00187 m_wndBtn2.SetWindowText (m_strBtn2Text);
00188 else
00189 m_wndBtn2.ShowWindow (SW_HIDE);
00190
00191 if (m_hIcon == NULL)
00192 m_wndIcon.ShowWindow (SW_HIDE);
00193
00194 return TRUE;
00195 }
00196
00197 void CMyMessageBox::OnBtn1()
00198 {
00199 m_bChecked = IsDlgButtonChecked (IDC_CHECK1) == BST_CHECKED;
00200 EndDialog (IDC_BTN1);
00201 }
00202
00203 void CMyMessageBox::OnBtn2()
00204 {
00205 m_bChecked = IsDlgButtonChecked (IDC_CHECK1) == BST_CHECKED;
00206 EndDialog (IDC_BTN2);
00207 }
00208
00209 void CMyMessageBox::OnBtn3()
00210 {
00211 m_bChecked = IsDlgButtonChecked (IDC_CHECK1) == BST_CHECKED;
00212 EndDialog (IDC_BTN3);
00213 }
00214
00215 void CMyMessageBox::OnCancel()
00216 {
00217 if (m_strBtn2Text == "")
00218 OnBtn1 ();
00219
00220
00221 }