//####COPYRIGHTBEGIN####
|
//####COPYRIGHTBEGIN####
|
//
|
//
|
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
|
// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
|
//
|
//
|
// This program is part of the eCos host tools.
|
// This program is part of the eCos host tools.
|
//
|
//
|
// This program is free software; you can redistribute it and/or modify it
|
// This program is free software; you can redistribute it and/or modify it
|
// under the terms of the GNU General Public License as published by the Free
|
// under the terms of the GNU General Public License as published by the Free
|
// Software Foundation; either version 2 of the License, or (at your option)
|
// Software Foundation; either version 2 of the License, or (at your option)
|
// any later version.
|
// any later version.
|
//
|
//
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
// more details.
|
// more details.
|
//
|
//
|
// You should have received a copy of the GNU General Public License along with
|
// You should have received a copy of the GNU General Public License along with
|
// this program; if not, write to the Free Software Foundation, Inc.,
|
// this program; if not, write to the Free Software Foundation, Inc.,
|
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
//
|
//
|
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
//
|
//
|
//####COPYRIGHTEND####
|
//####COPYRIGHTEND####
|
// MessageBox.cpp : implementation file
|
// MessageBox.cpp : implementation file
|
//
|
//
|
//
|
//
|
//===========================================================================
|
//===========================================================================
|
//#####DESCRIPTIONBEGIN####
|
//#####DESCRIPTIONBEGIN####
|
//
|
//
|
// Author(s): sdf
|
// Author(s): sdf
|
// Contact(s): sdf
|
// Contact(s): sdf
|
// Date: 1998/10/06
|
// Date: 1998/10/06
|
// Version: 0.01
|
// Version: 0.01
|
// Purpose:
|
// Purpose:
|
// Description: This is the implementation of the messagebox class
|
// Description: This is the implementation of the messagebox class
|
// Requires:
|
// Requires:
|
// Provides:
|
// Provides:
|
// See also:
|
// See also:
|
// Known bugs:
|
// Known bugs:
|
// Usage:
|
// Usage:
|
//
|
//
|
//####DESCRIPTIONEND####
|
//####DESCRIPTIONEND####
|
//
|
//
|
//===========================================================================
|
//===========================================================================
|
|
|
//
|
//
|
|
|
#include "stdafx.h"
|
#include "stdafx.h"
|
#include "MessageBox.h"
|
#include "MessageBox.h"
|
|
|
#ifdef _DEBUG
|
#ifdef _DEBUG
|
#define new DEBUG_NEW
|
#define new DEBUG_NEW
|
#undef THIS_FILE
|
#undef THIS_FILE
|
static char THIS_FILE[] = __FILE__;
|
static char THIS_FILE[] = __FILE__;
|
#endif
|
#endif
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
// CMessageBox dialog
|
// CMessageBox dialog
|
|
|
// Must be global because InitModalIndirect saves the pointer
|
// Must be global because InitModalIndirect saves the pointer
|
CMessageBox::DLGDATA CMessageBox::DlgData = {
|
CMessageBox::DLGDATA CMessageBox::DlgData = {
|
{ DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU,
|
{ DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU,
|
0, // No controls yet
|
0, // No controls yet
|
0,0,0,0}, // Fix up size and position later
|
0,0,0,0}, // Fix up size and position later
|
0,0,0}; // Default menu, class and title
|
0,0,0}; // Default menu, class and title
|
|
|
void CMessageBox::Init()
|
void CMessageBox::Init()
|
{
|
{
|
m_pFont=CFont::FromHandle(HFONT(GetStockObject(DEFAULT_GUI_FONT)));
|
m_pFont=CFont::FromHandle(HFONT(GetStockObject(DEFAULT_GUI_FONT)));
|
m_nFocusButton=-1;
|
m_nFocusButton=-1;
|
m_nEscapeButton=-1;
|
m_nEscapeButton=-1;
|
m_nJustify=SS_LEFT;
|
m_nJustify=SS_LEFT;
|
m_nDefaultButton=0;
|
m_nDefaultButton=0;
|
m_hIcon=NULL;
|
m_hIcon=NULL;
|
m_pStaticText=NULL;
|
m_pStaticText=NULL;
|
m_pStaticIcon=NULL;
|
m_pStaticIcon=NULL;
|
m_bTopMost=false;
|
m_bTopMost=false;
|
m_bModeless=false;
|
m_bModeless=false;
|
m_bDialogCreated=false;
|
m_bDialogCreated=false;
|
m_pParentNotify=NULL;
|
m_pParentNotify=NULL;
|
m_crText=GetSysColor(COLOR_BTNTEXT);
|
m_crText=GetSysColor(COLOR_BTNTEXT);
|
InitModalIndirect (&DlgData.tmpl,NULL);
|
InitModalIndirect (&DlgData.tmpl,NULL);
|
}
|
}
|
|
|
CMessageBox::CMessageBox()
|
CMessageBox::CMessageBox()
|
: CDialog()
|
: CDialog()
|
{
|
{
|
Init();
|
Init();
|
m_strCaption=_T("Error");
|
m_strCaption=_T("Error");
|
}
|
}
|
|
|
CMessageBox::CMessageBox(const CString &strText,const CString &strCaption/*=_T("Error")*/,UINT Flag/*=MB_OK*/)
|
CMessageBox::CMessageBox(const CString &strText,const CString &strCaption/*=_T("Error")*/,UINT Flag/*=MB_OK*/)
|
: CDialog()
|
: CDialog()
|
{
|
{
|
Init();
|
Init();
|
|
|
m_strText=strText;
|
m_strText=strText;
|
m_strCaption=strCaption;
|
m_strCaption=strCaption;
|
m_nDefaultButton=((Flag&MB_DEFMASK)>>8);
|
m_nDefaultButton=((Flag&MB_DEFMASK)>>8);
|
m_bTopMost=(0!=(Flag&MB_SYSTEMMODAL));
|
m_bTopMost=(0!=(Flag&MB_SYSTEMMODAL));
|
// Use flag to select from amongst standard combinations and
|
// Use flag to select from amongst standard combinations and
|
// to select icon.
|
// to select icon.
|
|
|
switch(Flag&MB_TYPEMASK){
|
switch(Flag&MB_TYPEMASK){
|
case MB_OK:
|
case MB_OK:
|
AddButton(_T("OK"),IDOK);
|
AddButton(_T("OK"),IDOK);
|
break;
|
break;
|
case MB_OKCANCEL:
|
case MB_OKCANCEL:
|
AddButton(_T("OK"),IDOK);
|
AddButton(_T("OK"),IDOK);
|
AddButton(_T("Cancel"),IDCANCEL);
|
AddButton(_T("Cancel"),IDCANCEL);
|
break;
|
break;
|
case MB_ABORTRETRYIGNORE:
|
case MB_ABORTRETRYIGNORE:
|
AddButton(_T("&Abort"),IDABORT);
|
AddButton(_T("&Abort"),IDABORT);
|
AddButton(_T("&Retry"),IDRETRY);
|
AddButton(_T("&Retry"),IDRETRY);
|
AddButton(_T("&Ignore"),IDIGNORE);
|
AddButton(_T("&Ignore"),IDIGNORE);
|
break;
|
break;
|
case MB_YESNOCANCEL:
|
case MB_YESNOCANCEL:
|
AddButton(_T("&Yes"),IDYES);
|
AddButton(_T("&Yes"),IDYES);
|
AddButton(_T("&No"),IDNO);
|
AddButton(_T("&No"),IDNO);
|
AddButton(_T("Cancel"),IDCANCEL);
|
AddButton(_T("Cancel"),IDCANCEL);
|
break;
|
break;
|
case MB_YESNO:
|
case MB_YESNO:
|
AddButton(_T("&Yes"),IDYES);
|
AddButton(_T("&Yes"),IDYES);
|
AddButton(_T("&No"),IDNO);
|
AddButton(_T("&No"),IDNO);
|
break;
|
break;
|
case MB_RETRYCANCEL:
|
case MB_RETRYCANCEL:
|
AddButton(_T("&Retry"),IDRETRY);
|
AddButton(_T("&Retry"),IDRETRY);
|
AddButton(_T("Cancel"),IDCANCEL);
|
AddButton(_T("Cancel"),IDCANCEL);
|
break;
|
break;
|
case MB_YESNOALL: //13
|
case MB_YESNOALL: //13
|
AddButton(_T("&Yes"),IDYES);
|
AddButton(_T("&Yes"),IDYES);
|
AddButton(_T("&No"),IDNO);
|
AddButton(_T("&No"),IDNO);
|
AddButton(_T("Yes &All"),IDYESALL);
|
AddButton(_T("Yes &All"),IDYESALL);
|
AddButton(_T("No A&ll"),IDNOALL);
|
AddButton(_T("No A&ll"),IDNOALL);
|
break;
|
break;
|
case MB_YESNOALLCANCEL: //14
|
case MB_YESNOALLCANCEL: //14
|
AddButton(_T("&Yes"),IDYES);
|
AddButton(_T("&Yes"),IDYES);
|
AddButton(_T("&No"),IDNO);
|
AddButton(_T("&No"),IDNO);
|
AddButton(_T("Yes &All"),IDYESALL);
|
AddButton(_T("Yes &All"),IDYESALL);
|
AddButton(_T("No A&ll"),IDNOALL);
|
AddButton(_T("No A&ll"),IDNOALL);
|
AddButton(_T("Cancel"),IDCANCEL);
|
AddButton(_T("Cancel"),IDCANCEL);
|
break;
|
break;
|
default:
|
default:
|
ASSERT(FALSE);
|
ASSERT(FALSE);
|
}
|
}
|
|
|
if(Flag&MB_HELP){
|
if(Flag&MB_HELP){
|
AddButton(_T("&Help"),IDHELP);
|
AddButton(_T("&Help"),IDHELP);
|
}
|
}
|
|
|
switch(Flag&MB_ICONMASK){
|
switch(Flag&MB_ICONMASK){
|
case MB_ICONHAND:
|
case MB_ICONHAND:
|
m_hIcon=AfxGetApp()->LoadStandardIcon(IDI_HAND);
|
m_hIcon=AfxGetApp()->LoadStandardIcon(IDI_HAND);
|
break;
|
break;
|
case MB_ICONQUESTION:
|
case MB_ICONQUESTION:
|
m_hIcon=AfxGetApp()->LoadStandardIcon(IDI_QUESTION);
|
m_hIcon=AfxGetApp()->LoadStandardIcon(IDI_QUESTION);
|
break;
|
break;
|
case MB_ICONEXCLAMATION:
|
case MB_ICONEXCLAMATION:
|
m_hIcon=AfxGetApp()->LoadStandardIcon(IDI_EXCLAMATION);
|
m_hIcon=AfxGetApp()->LoadStandardIcon(IDI_EXCLAMATION);
|
break;
|
break;
|
case MB_ICONASTERISK:
|
case MB_ICONASTERISK:
|
m_hIcon=AfxGetApp()->LoadStandardIcon(IDI_ASTERISK);
|
m_hIcon=AfxGetApp()->LoadStandardIcon(IDI_ASTERISK);
|
break;
|
break;
|
case 0:
|
case 0:
|
break;
|
break;
|
default:
|
default:
|
ASSERT(FALSE);
|
ASSERT(FALSE);
|
break;
|
break;
|
}
|
}
|
}
|
}
|
|
|
BEGIN_MESSAGE_MAP(CMessageBox, CDialog)
|
BEGIN_MESSAGE_MAP(CMessageBox, CDialog)
|
//{{AFX_MSG_MAP(CMessageBox)
|
//{{AFX_MSG_MAP(CMessageBox)
|
ON_WM_FONTCHANGE()
|
ON_WM_FONTCHANGE()
|
ON_WM_CTLCOLOR()
|
ON_WM_CTLCOLOR()
|
ON_WM_CLOSE()
|
ON_WM_CLOSE()
|
//}}AFX_MSG_MAP
|
//}}AFX_MSG_MAP
|
ON_CONTROL_RANGE(BN_CLICKED, 1, 0xFFFF, OnButton)
|
ON_CONTROL_RANGE(BN_CLICKED, 1, 0xFFFF, OnButton)
|
END_MESSAGE_MAP()
|
END_MESSAGE_MAP()
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
// CMessageBox message handlers
|
// CMessageBox message handlers
|
|
|
BOOL CMessageBox::OnInitDialog()
|
BOOL CMessageBox::OnInitDialog()
|
{
|
{
|
// Create buttons as required
|
// Create buttons as required
|
ASSERT(ButtonCount()>0);
|
ASSERT(ButtonCount()>0);
|
|
|
SetWindowText(m_strCaption);
|
SetWindowText(m_strCaption);
|
|
|
if(-1==m_nEscapeButton||IDCANCEL!=m_arBInfo[m_nEscapeButton].m_id){
|
if(-1==m_nEscapeButton||IDCANCEL!=m_arBInfo[m_nEscapeButton].m_id){
|
// No cancel button
|
// No cancel button
|
CMenu *pMenu=GetSystemMenu(FALSE);
|
CMenu *pMenu=GetSystemMenu(FALSE);
|
pMenu->RemoveMenu(SC_CLOSE,MF_BYCOMMAND);
|
pMenu->RemoveMenu(SC_CLOSE,MF_BYCOMMAND);
|
}
|
}
|
|
|
CDialog::OnInitDialog();
|
CDialog::OnInitDialog();
|
CDC *pDC=GetDC();
|
CDC *pDC=GetDC();
|
CFont *pOldFont=pDC->SelectObject(m_pFont);
|
CFont *pOldFont=pDC->SelectObject(m_pFont);
|
TEXTMETRIC tm;
|
TEXTMETRIC tm;
|
pDC->GetTextMetrics(&tm);
|
pDC->GetTextMetrics(&tm);
|
|
|
int cxDLU=tm.tmAveCharWidth;
|
int cxDLU=tm.tmAveCharWidth;
|
int cyDLU=tm.tmHeight;
|
int cyDLU=tm.tmHeight;
|
int nButtonWidth= (60*cxDLU)/4; // width of a button
|
int nButtonWidth= (60*cxDLU)/4; // width of a button
|
int nButtonHeight=(14*cyDLU)/8; // height of a button
|
int nButtonHeight=(14*cyDLU)/8; // height of a button
|
int cxButtonSep= (4*cxDLU)/4; // horizontal button separation
|
int cxButtonSep= (4*cxDLU)/4; // horizontal button separation
|
int cxTextButtonSep=(10*cxDLU)/4; // horizontal separation between text and icon
|
int cxTextButtonSep=(10*cxDLU)/4; // horizontal separation between text and icon
|
int cyTextButtonSep=(10*cyDLU)/8; // vertical separation between text and buttons
|
int cyTextButtonSep=(10*cyDLU)/8; // vertical separation between text and buttons
|
int cxBorder= (7*cxDLU)/4; // horizontal separation between buttons and border
|
int cxBorder= (7*cxDLU)/4; // horizontal separation between buttons and border
|
int cyBorder= (7*cyDLU)/8; // vertical separation between buttons and border
|
int cyBorder= (7*cyDLU)/8; // vertical separation between buttons and border
|
int cxIcon=GetSystemMetrics(SM_CXICON); // width of an icon
|
int cxIcon=GetSystemMetrics(SM_CXICON); // width of an icon
|
int cyIcon=GetSystemMetrics(SM_CYICON); // height of an icon
|
int cyIcon=GetSystemMetrics(SM_CYICON); // height of an icon
|
int nTotalButtonWidth=(ButtonCount()*nButtonWidth)+(ButtonCount()-1)*cxButtonSep;
|
int nTotalButtonWidth=(ButtonCount()*nButtonWidth)+(ButtonCount()-1)*cxButtonSep;
|
int cxText=max(50,nTotalButtonWidth-(m_hIcon?(cxIcon+cxTextButtonSep):0));
|
int cxText=max(50,nTotalButtonWidth-(m_hIcon?(cxIcon+cxTextButtonSep):0));
|
int cyText=0;
|
int cyText=0;
|
|
|
// Size the text control according to the maximum line length
|
// Size the text control according to the maximum line length
|
LPCTSTR c=m_strText;
|
LPCTSTR c=m_strText;
|
while(*c){
|
while(*c){
|
PTCHAR d=_tcsstr(c,_T("\r\n"));
|
PTCHAR d=_tcsstr(c,_T("\r\n"));
|
int nCount;
|
int nCount;
|
if(d){
|
if(d){
|
*d=_TCHAR('\0');
|
*d=_TCHAR('\0');
|
nCount=d-c;
|
nCount=d-c;
|
} else {\
|
} else {\
|
nCount=_tcslen(c);
|
nCount=_tcslen(c);
|
}
|
}
|
cxText=max(cxText,pDC->GetTextExtent(c,nCount).cx);
|
cxText=max(cxText,pDC->GetTextExtent(c,nCount).cx);
|
cyText+=tm.tmHeight;
|
cyText+=tm.tmHeight;
|
if(d){
|
if(d){
|
*d=_TCHAR('\r');
|
*d=_TCHAR('\r');
|
c=d+2;
|
c=d+2;
|
} else {
|
} else {
|
break;
|
break;
|
}
|
}
|
}
|
}
|
|
|
// If vertical extent of text is less than that of the icon, difference between the two
|
// If vertical extent of text is less than that of the icon, difference between the two
|
int cyTextExtra= (m_hIcon && cyText<cyIcon)?cyIcon-cyText:0;
|
int cyTextExtra= (m_hIcon && cyText<cyIcon)?cyIcon-cyText:0;
|
|
|
pDC->SelectObject(pOldFont);
|
pDC->SelectObject(pOldFont);
|
ReleaseDC(pDC);
|
ReleaseDC(pDC);
|
|
|
// Set dialog box size
|
// Set dialog box size
|
{
|
{
|
int cx=(2*cxBorder)+cxText+cxButtonSep+2*GetSystemMetrics(SM_CXDLGFRAME);
|
int cx=(2*cxBorder)+cxText+cxButtonSep+2*GetSystemMetrics(SM_CXDLGFRAME);
|
if(m_hIcon){
|
if(m_hIcon){
|
cx+=cxIcon+cxTextButtonSep;
|
cx+=cxIcon+cxTextButtonSep;
|
}
|
}
|
int cy=(2*cyBorder)+cyText+cyTextExtra+cyTextButtonSep+nButtonHeight+
|
int cy=(2*cyBorder)+cyText+cyTextExtra+cyTextButtonSep+nButtonHeight+
|
GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYDLGFRAME);
|
GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYDLGFRAME);
|
UINT flags=SWP_NOMOVE;
|
UINT flags=SWP_NOMOVE;
|
if(!m_bTopMost){
|
if(!m_bTopMost){
|
flags|=SWP_NOZORDER;
|
flags|=SWP_NOZORDER;
|
}
|
}
|
SetWindowPos(&wndTopMost,0,0,cx,cy,flags);
|
SetWindowPos(&wndTopMost,0,0,cx,cy,flags);
|
}
|
}
|
|
|
// Create a static control for the icon
|
// Create a static control for the icon
|
if(m_hIcon){
|
if(m_hIcon){
|
m_pStaticIcon=new CStatic;
|
m_pStaticIcon=new CStatic;
|
m_pStaticIcon->Create(NULL,WS_CHILD|WS_VISIBLE|SS_ICON,
|
m_pStaticIcon->Create(NULL,WS_CHILD|WS_VISIBLE|SS_ICON,
|
CRect(cxBorder,cyBorder,cxBorder+cxIcon,cyBorder+cyIcon), this);
|
CRect(cxBorder,cyBorder,cxBorder+cxIcon,cyBorder+cyIcon), this);
|
m_pStaticIcon->SetIcon(m_hIcon);
|
m_pStaticIcon->SetIcon(m_hIcon);
|
}
|
}
|
|
|
// Create a static control for the text
|
// Create a static control for the text
|
{
|
{
|
int cx=m_hIcon?cxIcon+cxTextButtonSep:0;
|
int cx=m_hIcon?cxIcon+cxTextButtonSep:0;
|
m_pStaticText=new CStatic;
|
m_pStaticText=new CStatic;
|
m_pStaticText->Create(m_strText,WS_CHILD|WS_VISIBLE|m_nJustify|SS_NOPREFIX,
|
m_pStaticText->Create(m_strText,WS_CHILD|WS_VISIBLE|m_nJustify|SS_NOPREFIX,
|
CRect(cxBorder+cx,cyBorder+cyTextExtra/2,cxBorder+cx+cxText,cyBorder+cyText+cyTextExtra/2), this);
|
CRect(cxBorder+cx,cyBorder+cyTextExtra/2,cxBorder+cx+cxText,cyBorder+cyText+cyTextExtra/2), this);
|
m_pStaticText->SetFont(m_pFont);
|
m_pStaticText->SetFont(m_pFont);
|
}
|
}
|
|
|
// Create the buttons
|
// Create the buttons
|
CRect rcClient;
|
CRect rcClient;
|
GetClientRect(rcClient);
|
GetClientRect(rcClient);
|
CRect rect;
|
CRect rect;
|
rect.left=(rcClient.Width()-nTotalButtonWidth)/2;
|
rect.left=(rcClient.Width()-nTotalButtonWidth)/2;
|
rect.right=rect.left+nButtonWidth;
|
rect.right=rect.left+nButtonWidth;
|
rect.bottom=rcClient.bottom-cyBorder;
|
rect.bottom=rcClient.bottom-cyBorder;
|
rect.top=rect.bottom-nButtonHeight;
|
rect.top=rect.bottom-nButtonHeight;
|
|
|
ASSERT(m_nDefaultButton<ButtonCount());
|
ASSERT(m_nDefaultButton<ButtonCount());
|
|
|
for(unsigned i=0;i<ButtonCount();i++){
|
for(unsigned i=0;i<ButtonCount();i++){
|
CButton *pWnd=new CButton;
|
CButton *pWnd=new CButton;
|
m_arBInfo[i].m_pWnd=pWnd;
|
m_arBInfo[i].m_pWnd=pWnd;
|
UINT id=m_arBInfo[i].m_id;
|
UINT id=m_arBInfo[i].m_id;
|
UINT style=WS_CHILD|WS_VISIBLE|WS_TABSTOP;
|
UINT style=WS_CHILD|WS_VISIBLE|WS_TABSTOP;
|
if(!m_arBInfo[i].m_bEnabled){
|
if(!m_arBInfo[i].m_bEnabled){
|
style|=WS_DISABLED;
|
style|=WS_DISABLED;
|
}
|
}
|
if(0==i){
|
if(0==i){
|
style|=WS_GROUP;
|
style|=WS_GROUP;
|
}
|
}
|
style|=(m_nDefaultButton==i)?BS_DEFPUSHBUTTON:BS_PUSHBUTTON;
|
style|=(m_nDefaultButton==i)?BS_DEFPUSHBUTTON:BS_PUSHBUTTON;
|
|
|
pWnd->Create(m_arBInfo[i].m_strCaption,style,rect,this,id);
|
pWnd->Create(m_arBInfo[i].m_strCaption,style,rect,this,id);
|
pWnd->SetFont(m_pFont);
|
pWnd->SetFont(m_pFont);
|
if(m_nDefaultButton==i){
|
if(m_nDefaultButton==i){
|
pWnd->SetFocus();
|
pWnd->SetFocus();
|
}
|
}
|
rect.left+=nButtonWidth+cxButtonSep;
|
rect.left+=nButtonWidth+cxButtonSep;
|
rect.right+=nButtonWidth+cxButtonSep;
|
rect.right+=nButtonWidth+cxButtonSep;
|
}
|
}
|
|
|
m_nFocusButton=m_nDefaultButton;
|
m_nFocusButton=m_nDefaultButton;
|
m_bDialogCreated=true;
|
m_bDialogCreated=true;
|
return FALSE;
|
return FALSE;
|
}
|
}
|
|
|
void CMessageBox::OnButton(UINT id)
|
void CMessageBox::OnButton(UINT id)
|
{
|
{
|
if(-1!=IndexOf(id)){
|
if(-1!=IndexOf(id)){
|
if(m_bModeless){
|
if(m_bModeless){
|
if(NULL!=m_pParentNotify){
|
if(NULL!=m_pParentNotify){
|
m_pParentNotify->PostMessage(m_nParentNotifcationMessage,MAKEWPARAM(id,m_nParentNotifcationwParamHigh),0);
|
m_pParentNotify->PostMessage(m_nParentNotifcationMessage,MAKEWPARAM(id,m_nParentNotifcationwParamHigh),0);
|
DestroyWindow();
|
DestroyWindow();
|
}
|
}
|
} else {
|
} else {
|
EndDialog(id);
|
EndDialog(id);
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
BOOL CMessageBox::PreTranslateMessage(MSG* pMsg)
|
BOOL CMessageBox::PreTranslateMessage(MSG* pMsg)
|
{
|
{
|
if(pMsg->message==WM_KEYDOWN){
|
if(pMsg->message==WM_KEYDOWN){
|
switch(pMsg->wParam){
|
switch(pMsg->wParam){
|
case VK_ESCAPE:
|
case VK_ESCAPE:
|
if(-1!=m_nEscapeButton){
|
if(-1!=m_nEscapeButton){
|
OnButton(m_arBInfo[m_nEscapeButton].m_id);
|
OnButton(m_arBInfo[m_nEscapeButton].m_id);
|
}
|
}
|
return TRUE;
|
return TRUE;
|
default:
|
default:
|
break;
|
break;
|
}
|
}
|
}
|
}
|
if( IsDialogMessage( pMsg ) )
|
if( IsDialogMessage( pMsg ) )
|
return TRUE;
|
return TRUE;
|
else
|
else
|
return CDialog::PreTranslateMessage( pMsg );
|
return CDialog::PreTranslateMessage( pMsg );
|
}
|
}
|
|
|
void CMessageBox::AddButton(const CString & strCaption, UINT id, bool bEnabled/*=true*/)
|
void CMessageBox::AddButton(const CString & strCaption, UINT id, bool bEnabled/*=true*/)
|
{
|
{
|
#ifdef _DEBUG
|
#ifdef _DEBUG
|
ASSERT(-1==IndexOf(id));
|
ASSERT(-1==IndexOf(id));
|
for(unsigned int i=0;i<ButtonCount();i++){
|
for(unsigned int i=0;i<ButtonCount();i++){
|
if(0==m_arBInfo[i].m_strCaption.Compare(strCaption)){
|
if(0==m_arBInfo[i].m_strCaption.Compare(strCaption)){
|
ASSERT(FALSE);
|
ASSERT(FALSE);
|
}
|
}
|
}
|
}
|
#endif
|
#endif
|
if(bEnabled){
|
if(bEnabled){
|
if(IDCANCEL==id || (IDOK==id && -1==m_nEscapeButton)){
|
if(IDCANCEL==id || (IDOK==id && -1==m_nEscapeButton)){
|
m_nEscapeButton=ButtonCount();
|
m_nEscapeButton=ButtonCount();
|
}
|
}
|
}
|
}
|
CButtonInfo info(id,bEnabled,strCaption);
|
CButtonInfo info(id,bEnabled,strCaption);
|
m_arBInfo.Add(info);
|
m_arBInfo.Add(info);
|
}
|
}
|
|
|
CMessageBox::~CMessageBox()
|
CMessageBox::~CMessageBox()
|
{
|
{
|
for(unsigned int i=0;i<ButtonCount();i++){
|
for(unsigned int i=0;i<ButtonCount();i++){
|
deleteZ(m_arBInfo[i].m_pWnd);
|
deleteZ(m_arBInfo[i].m_pWnd);
|
}
|
}
|
deleteZ(m_pStaticText);
|
deleteZ(m_pStaticText);
|
deleteZ(m_pStaticIcon);
|
deleteZ(m_pStaticIcon);
|
}
|
}
|
|
|
void CMessageBox::SetDefaultButton(UINT nIndex)
|
void CMessageBox::SetDefaultButton(UINT nIndex)
|
{
|
{
|
ASSERT(nIndex<ButtonCount());
|
ASSERT(nIndex<ButtonCount());
|
m_nDefaultButton=nIndex;
|
m_nDefaultButton=nIndex;
|
}
|
}
|
|
|
void CMessageBox::OnFontChange()
|
void CMessageBox::OnFontChange()
|
{
|
{
|
CDialog::OnFontChange();
|
CDialog::OnFontChange();
|
|
|
m_pFont=CFont::FromHandle(HFONT(GetStockObject(DEFAULT_GUI_FONT)));
|
m_pFont=CFont::FromHandle(HFONT(GetStockObject(DEFAULT_GUI_FONT)));
|
for(unsigned int i=0;i<ButtonCount();i++){
|
for(unsigned int i=0;i<ButtonCount();i++){
|
Button(i).SetFont(m_pFont);
|
Button(i).SetFont(m_pFont);
|
}
|
}
|
m_pStaticText->SetFont(m_pFont);
|
m_pStaticText->SetFont(m_pFont);
|
}
|
}
|
|
|
|
|
|
|
HBRUSH CMessageBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
|
HBRUSH CMessageBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
|
{
|
{
|
HBRUSH hbr=CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
|
HBRUSH hbr=CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
|
switch(nCtlColor){
|
switch(nCtlColor){
|
case CTLCOLOR_STATIC:
|
case CTLCOLOR_STATIC:
|
pDC->SetTextColor(m_crText);
|
pDC->SetTextColor(m_crText);
|
break;
|
break;
|
default:
|
default:
|
break;
|
break;
|
}
|
}
|
return hbr;
|
return hbr;
|
}
|
}
|
|
|
|
|
BOOL CMessageBox::Create(CWnd *pWnd,UINT msg,WORD wParamHigh)
|
BOOL CMessageBox::Create(CWnd *pWnd,UINT msg,WORD wParamHigh)
|
{
|
{
|
m_bModeless=true;
|
m_bModeless=true;
|
if(0!=msg){
|
if(0!=msg){
|
ASSERT(NULL!=pWnd);
|
ASSERT(NULL!=pWnd);
|
m_pParentNotify=pWnd;
|
m_pParentNotify=pWnd;
|
m_nParentNotifcationMessage=msg;
|
m_nParentNotifcationMessage=msg;
|
m_nParentNotifcationwParamHigh=wParamHigh;
|
m_nParentNotifcationwParamHigh=wParamHigh;
|
}
|
}
|
return CreateIndirect (&DlgData.tmpl,pWnd);
|
return CreateIndirect (&DlgData.tmpl,pWnd);
|
}
|
}
|
|
|
int CMessageBox::IndexOf(UINT id)
|
int CMessageBox::IndexOf(UINT id)
|
{
|
{
|
for(unsigned int i=0;i<ButtonCount();i++){
|
for(unsigned int i=0;i<ButtonCount();i++){
|
if(m_arBInfo[i].m_id==id){
|
if(m_arBInfo[i].m_id==id){
|
return (signed)i;
|
return (signed)i;
|
}
|
}
|
}
|
}
|
return -1;
|
return -1;
|
}
|
}
|
|
|
void CMessageBox::PostNcDestroy()
|
void CMessageBox::PostNcDestroy()
|
{
|
{
|
if(m_bModeless){
|
if(m_bModeless){
|
delete this;
|
delete this;
|
} else {
|
} else {
|
CDialog::PostNcDestroy();
|
CDialog::PostNcDestroy();
|
}
|
}
|
}
|
}
|
|
|
void CMessageBox::OnClose()
|
void CMessageBox::OnClose()
|
{
|
{
|
OnButton(IDCANCEL);
|
OnButton(IDCANCEL);
|
}
|
}
|
|
|
void CMessageBox::SetCaption (const CString &strCaption)
|
void CMessageBox::SetCaption (const CString &strCaption)
|
{
|
{
|
m_strCaption=strCaption;
|
m_strCaption=strCaption;
|
if(m_bDialogCreated){
|
if(m_bDialogCreated){
|
SetWindowText(strCaption);
|
SetWindowText(strCaption);
|
}
|
}
|
}
|
}
|
|
|