123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- // MessageBoxDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ipos.h"
- #include "MessageBoxDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMessageBoxDlg dialog
- CMessageBoxDlg::CMessageBoxDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CMessageBoxDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CMessageBoxDlg)
- m_strMessage = _T("");
- //}}AFX_DATA_INIT
- nDelaySecond = 5;
- bOk = false;
- bShowOkBtn = false;
- }
- void CMessageBoxDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMessageBoxDlg)
- DDX_Control(pDX, ID_MYOK, m_OkBtn);
- DDX_Control(pDX, IDCANCEL, m_ExitBtn);
- DDX_Text(pDX, IDC_MESSAGE, m_strMessage);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CMessageBoxDlg, CDialog)
- //{{AFX_MSG_MAP(CMessageBoxDlg)
- ON_WM_ERASEBKGND()
- ON_WM_CTLCOLOR()
- ON_WM_TIMER()
- ON_BN_CLICKED(ID_MYOK, OnMyok)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMessageBoxDlg message handlers
- void CMessageBoxDlg::OnOK()
- {
- // TODO: Add extra validation here
-
- // CDialog::OnOK();
- }
- void CMessageBoxDlg::OnCancel()
- {
- // TODO: Add extra cleanup here
-
- CDialog::OnCancel();
- }
- HBRUSH CMessageBoxDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- HBRUSH hbr = (HBRUSH)::GetStockObject( NULL_BRUSH );
- //是对话框上各控件对背景色透明
- if( pWnd->GetDlgCtrlID() == IDC_MESSAGE )
- {
- pDC->SetBkMode(TRANSPARENT);
- hbr=(HBRUSH)::GetStockObject( NULL_BRUSH );
- pDC->SetTextColor( RGB( 0, 0, 0 ) );
- }
-
- return hbr;
- }
- BOOL CMessageBoxDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- CFont* ptf=GetDlgItem( IDC_MESSAGE )->GetFont(); // 得到原来的字体
- LOGFONT lf;
- ptf->GetLogFont(&lf);
- lf.lfHeight = 24; // 改变字体高度
- //strcpy (lf.lfFaceName, "Arial Black"); // 改变字体名称
- strcpy (lf.lfFaceName, "Arial"); // 改变字体名称
- lf.lfCharSet = DEFAULT_CHARSET; //DEFAULT_CHARSET ANSI_CHARSET GB2312_CHARSET
- lf.lfWeight = 700;
- m_Font.CreateFontIndirect(&lf);
- GetDlgItem( IDC_MESSAGE )->SetFont(&m_Font); // 设置新字体
- //m_ExitBtn.SetIcon( CloseBtn ); // 32x32 icon SettingBtn
- //m_ExitBtn.SetInactiveBgColor( RGB( 87, 91, 92 ) );
- //m_ExitBtn.SetActiveBgColor( RGB( 87, 91, 92 ) );
- m_ExitBtn.LoadBitmaps(_T("exitbtn_up"), _T("exitbtn_down"), _T("exitbtn_up"), _T("exitbtn_gray") );
- m_OkBtn.LoadBitmaps(_T("Miniok_up"), _T("Miniok_down"), _T("Miniok_up"), _T("Miniok_gray") );
- CDC* pDC = GetDC();
- CFont *pOldFont = pDC->SelectObject( &m_Font );
- SIZE StrSize;
- GetTextExtentPoint32( pDC->m_hDC, m_strMessage, m_strMessage.GetLength(), &StrSize );
- StrSize.cx += 20;
- if( StrSize.cx < 200 )
- StrSize.cx = 200;
-
- pDC->SelectObject( pOldFont );
- ReleaseDC( pDC );
- CRect BtnClientRect;
- GetDlgItem( ID_MYOK )->GetClientRect( &BtnClientRect );
- int nBtnWidth = BtnClientRect.Width();
- int nLeftBlk = 5;
- int nAllWidth = StrSize.cx+nBtnWidth+2*nLeftBlk;
- CRect ClientRect;
- GetClientRect( &ClientRect );
- MoveWindow( ( 1280 - nAllWidth )/2, ( 1024 - ClientRect.Height() )/2, nAllWidth, ClientRect.Height(), true );
- CRect ItemRect;
- GetDlgItem( IDCANCEL )->GetClientRect( &ItemRect );
- GetDlgItem( IDCANCEL )->MoveWindow( nAllWidth - ItemRect.Width()-4, 2, ItemRect.Width(), ItemRect.Height() );
- GetDlgItem( ID_MYOK )->MoveWindow( nAllWidth - BtnClientRect.Width() - nLeftBlk, ItemRect.Height()+(ClientRect.Height()-ItemRect.Height()-BtnClientRect.Height())/2, BtnClientRect.Width(), BtnClientRect.Height() );
- GetDlgItem( IDC_MESSAGE )->GetClientRect( &ItemRect );
- GetDlgItem( IDC_MESSAGE )->ClientToScreen( &ItemRect );
- ScreenToClient( &ItemRect );
- GetDlgItem( IDC_MESSAGE )->MoveWindow( 15, ItemRect.top, StrSize.cx, ItemRect.Height() );
- if( bShowOkBtn )
- GetDlgItem( ID_MYOK )->ShowWindow( SW_SHOW );
- else
- GetDlgItem( ID_MYOK )->ShowWindow( SW_HIDE );
- if( nDelaySecond > 0 )
- SetTimer( 1, nDelaySecond*1000, NULL );
- return TRUE;
- }
- BOOL CMessageBoxDlg::OnEraseBkgnd(CDC* pDC)
- {
- CBitmap bmp;
- CBitmap *ptrBmpOld;
- CDC dcMemory;
- BITMAP bm;
- CRect rect;
- int i, j;
- int nHor, nVer;
- bmp.LoadBitmap( IDB_MSGBOX_BK );
- bmp.GetBitmap(&bm);
- GetClientRect(rect);
- nHor=rect.Width()/bm.bmWidth+1;
- nVer=rect.Height()/bm.bmHeight+1;
- dcMemory.CreateCompatibleDC(pDC);
- ptrBmpOld=dcMemory.SelectObject(&bmp);
- for(i=0; i<nHor; i++)
- {
- for(j=0; j<nVer; j++)
- {
- pDC->BitBlt
- (
- i*bm.bmWidth,
- j*bm.bmHeight,
- bm.bmWidth,
- bm.bmHeight,
- &dcMemory,
- 0,
- 0,
- SRCCOPY
- );
- }
- }
- dcMemory.SelectObject(ptrBmpOld);
- dcMemory.DeleteDC();
- bmp.DeleteObject();
- return true;
- }
- void CMessageBoxDlg::OnTimer(UINT nIDEvent)
- {
- OnCancel();
-
- CDialog::OnTimer(nIDEvent);
- }
- void CMessageBoxDlg::OnMyok()
- {
- bOk = true;
- OnCancel();
- }
|