MessageBoxDlg.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. // MessageBoxDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ipos.h"
  5. #include "MessageBoxDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CMessageBoxDlg dialog
  13. CMessageBoxDlg::CMessageBoxDlg(CWnd* pParent /*=NULL*/)
  14. : CDialog(CMessageBoxDlg::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CMessageBoxDlg)
  17. m_strMessage = _T("");
  18. //}}AFX_DATA_INIT
  19. nDelaySecond = 5;
  20. bOk = false;
  21. bShowOkBtn = false;
  22. }
  23. void CMessageBoxDlg::DoDataExchange(CDataExchange* pDX)
  24. {
  25. CDialog::DoDataExchange(pDX);
  26. //{{AFX_DATA_MAP(CMessageBoxDlg)
  27. DDX_Control(pDX, ID_MYOK, m_OkBtn);
  28. DDX_Control(pDX, IDCANCEL, m_ExitBtn);
  29. DDX_Text(pDX, IDC_MESSAGE, m_strMessage);
  30. //}}AFX_DATA_MAP
  31. }
  32. BEGIN_MESSAGE_MAP(CMessageBoxDlg, CDialog)
  33. //{{AFX_MSG_MAP(CMessageBoxDlg)
  34. ON_WM_ERASEBKGND()
  35. ON_WM_CTLCOLOR()
  36. ON_WM_TIMER()
  37. ON_BN_CLICKED(ID_MYOK, OnMyok)
  38. //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CMessageBoxDlg message handlers
  42. void CMessageBoxDlg::OnOK()
  43. {
  44. // TODO: Add extra validation here
  45. // CDialog::OnOK();
  46. }
  47. void CMessageBoxDlg::OnCancel()
  48. {
  49. // TODO: Add extra cleanup here
  50. CDialog::OnCancel();
  51. }
  52. HBRUSH CMessageBoxDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  53. {
  54. HBRUSH hbr = (HBRUSH)::GetStockObject( NULL_BRUSH );
  55. //是对话框上各控件对背景色透明
  56. if( pWnd->GetDlgCtrlID() == IDC_MESSAGE )
  57. {
  58. pDC->SetBkMode(TRANSPARENT);
  59. hbr=(HBRUSH)::GetStockObject( NULL_BRUSH );
  60. pDC->SetTextColor( RGB( 0, 0, 0 ) );
  61. }
  62. return hbr;
  63. }
  64. BOOL CMessageBoxDlg::OnInitDialog()
  65. {
  66. CDialog::OnInitDialog();
  67. CFont* ptf=GetDlgItem( IDC_MESSAGE )->GetFont(); // 得到原来的字体
  68. LOGFONT lf;
  69. ptf->GetLogFont(&lf);
  70. lf.lfHeight = 24; // 改变字体高度
  71. //strcpy (lf.lfFaceName, "Arial Black"); // 改变字体名称
  72. strcpy (lf.lfFaceName, "Arial"); // 改变字体名称
  73. lf.lfCharSet = DEFAULT_CHARSET; //DEFAULT_CHARSET ANSI_CHARSET GB2312_CHARSET
  74. lf.lfWeight = 700;
  75. m_Font.CreateFontIndirect(&lf);
  76. GetDlgItem( IDC_MESSAGE )->SetFont(&m_Font); // 设置新字体
  77. //m_ExitBtn.SetIcon( CloseBtn ); // 32x32 icon SettingBtn
  78. //m_ExitBtn.SetInactiveBgColor( RGB( 87, 91, 92 ) );
  79. //m_ExitBtn.SetActiveBgColor( RGB( 87, 91, 92 ) );
  80. m_ExitBtn.LoadBitmaps(_T("exitbtn_up"), _T("exitbtn_down"), _T("exitbtn_up"), _T("exitbtn_gray") );
  81. m_OkBtn.LoadBitmaps(_T("Miniok_up"), _T("Miniok_down"), _T("Miniok_up"), _T("Miniok_gray") );
  82. CDC* pDC = GetDC();
  83. CFont *pOldFont = pDC->SelectObject( &m_Font );
  84. SIZE StrSize;
  85. GetTextExtentPoint32( pDC->m_hDC, m_strMessage, m_strMessage.GetLength(), &StrSize );
  86. StrSize.cx += 20;
  87. if( StrSize.cx < 200 )
  88. StrSize.cx = 200;
  89. pDC->SelectObject( pOldFont );
  90. ReleaseDC( pDC );
  91. CRect BtnClientRect;
  92. GetDlgItem( ID_MYOK )->GetClientRect( &BtnClientRect );
  93. int nBtnWidth = BtnClientRect.Width();
  94. int nLeftBlk = 5;
  95. int nAllWidth = StrSize.cx+nBtnWidth+2*nLeftBlk;
  96. CRect ClientRect;
  97. GetClientRect( &ClientRect );
  98. MoveWindow( ( 1280 - nAllWidth )/2, ( 1024 - ClientRect.Height() )/2, nAllWidth, ClientRect.Height(), true );
  99. CRect ItemRect;
  100. GetDlgItem( IDCANCEL )->GetClientRect( &ItemRect );
  101. GetDlgItem( IDCANCEL )->MoveWindow( nAllWidth - ItemRect.Width()-4, 2, ItemRect.Width(), ItemRect.Height() );
  102. GetDlgItem( ID_MYOK )->MoveWindow( nAllWidth - BtnClientRect.Width() - nLeftBlk, ItemRect.Height()+(ClientRect.Height()-ItemRect.Height()-BtnClientRect.Height())/2, BtnClientRect.Width(), BtnClientRect.Height() );
  103. GetDlgItem( IDC_MESSAGE )->GetClientRect( &ItemRect );
  104. GetDlgItem( IDC_MESSAGE )->ClientToScreen( &ItemRect );
  105. ScreenToClient( &ItemRect );
  106. GetDlgItem( IDC_MESSAGE )->MoveWindow( 15, ItemRect.top, StrSize.cx, ItemRect.Height() );
  107. if( bShowOkBtn )
  108. GetDlgItem( ID_MYOK )->ShowWindow( SW_SHOW );
  109. else
  110. GetDlgItem( ID_MYOK )->ShowWindow( SW_HIDE );
  111. if( nDelaySecond > 0 )
  112. SetTimer( 1, nDelaySecond*1000, NULL );
  113. return TRUE;
  114. }
  115. BOOL CMessageBoxDlg::OnEraseBkgnd(CDC* pDC)
  116. {
  117. CBitmap bmp;
  118. CBitmap *ptrBmpOld;
  119. CDC dcMemory;
  120. BITMAP bm;
  121. CRect rect;
  122. int i, j;
  123. int nHor, nVer;
  124. bmp.LoadBitmap( IDB_MSGBOX_BK );
  125. bmp.GetBitmap(&bm);
  126. GetClientRect(rect);
  127. nHor=rect.Width()/bm.bmWidth+1;
  128. nVer=rect.Height()/bm.bmHeight+1;
  129. dcMemory.CreateCompatibleDC(pDC);
  130. ptrBmpOld=dcMemory.SelectObject(&bmp);
  131. for(i=0; i<nHor; i++)
  132. {
  133. for(j=0; j<nVer; j++)
  134. {
  135. pDC->BitBlt
  136. (
  137. i*bm.bmWidth,
  138. j*bm.bmHeight,
  139. bm.bmWidth,
  140. bm.bmHeight,
  141. &dcMemory,
  142. 0,
  143. 0,
  144. SRCCOPY
  145. );
  146. }
  147. }
  148. dcMemory.SelectObject(ptrBmpOld);
  149. dcMemory.DeleteDC();
  150. bmp.DeleteObject();
  151. return true;
  152. }
  153. void CMessageBoxDlg::OnTimer(UINT nIDEvent)
  154. {
  155. OnCancel();
  156. CDialog::OnTimer(nIDEvent);
  157. }
  158. void CMessageBoxDlg::OnMyok()
  159. {
  160. bOk = true;
  161. OnCancel();
  162. }