|
|
//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright � 2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 08/10/2003
// PROJECT:
// SUBSYSTEM:
// FILE: MessageBox.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of MessageBox.cpp
//----------------------------------------------------------------------------
// MessageBox.cpp: implementation of the CMessageBox class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "..\LgLib\Version.h"
#include "Resource.h"
#include "MessageBox.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMessageBox::CMessageBox( LPCTSTR pTemplateName ) : CDialog( pTemplateName ){ m_pText = ""; m_pCaption = ""; m_uType = 0;
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CMessageBox::CMessageBox" );}
CMessageBox::~CMessageBox(){ LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CMessageBox::~CMessageBox" );}
BOOL CMessageBox::DialogProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ){ switch( uMsg ) { case WM_INITDIALOG: return OnInitDialog( hWnd, wParam, lParam );
case WM_COMMAND: return OnCommand( hWnd, wParam, lParam ); } return FALSE;}
BOOL CMessageBox::OnInitDialog( HWND hWnd, WPARAM wParam, LPARAM lParam ){ ::SetWindowText( hWnd, m_pCaption ); ::SendDlgItemMessage( hWnd, IDC_STATIC_TEXT, WM_SETTEXT, 0, (LPARAM)m_pText );
enum { BT_OK = 0, BT_YES = 1, BT_NO = 2, BT_CANCEL = 3 }; HWND hButton[4] = { ::GetDlgItem( hWnd, IDOK ), ::GetDlgItem( hWnd, IDYES ), ::GetDlgItem( hWnd, IDNO ), ::GetDlgItem( hWnd, IDCANCEL ) }; BOOL bShow[4] = { FALSE, FALSE, FALSE, FALSE };
if( m_uType & MB_OK ) { bShow[ BT_OK ] = TRUE; } else if( m_uType & MB_OKCANCEL ) { bShow[ BT_OK ] = TRUE; bShow[ BT_CANCEL ] = TRUE; } else if( m_uType & MB_YESNO ) { bShow[ BT_YES ] = TRUE; bShow[ BT_NO ] = TRUE; } else if( m_uType & MB_YESNOCANCEL ) { bShow[ BT_YES ] = TRUE; bShow[ BT_NO ] = TRUE; bShow[ BT_CANCEL ] = TRUE; } else { bShow[ BT_OK ] = TRUE; }
int nCountButton = 0; for( int i = BT_OK; i <= BT_CANCEL; i++ ) { if( bShow[i] ) { ::ShowWindow( hButton[i], SW_SHOW ); nCountButton++; } else ::ShowWindow( hButton[i], SW_HIDE ); }
RECT rectButton; ::GetWindowRect( hButton[0], &rectButton ); ::OffsetRect( &rectButton, -rectButton.left, -rectButton.top );
RECT rectWindow; ::GetClientRect( hWnd, &rectWindow );
int nWidthWindow = rectWindow.right - rectWindow.left; int nHeightWindow = rectWindow.bottom - rectWindow.top;
int nWidthButton = rectButton.right - rectButton.left; int nHeightButton = rectButton.bottom - rectButton.top;
const int spaceBetweenButtons = 5;
int nButtonLeft = ( nWidthWindow - ( nWidthButton * nCountButton + spaceBetweenButtons * ( nCountButton - 1 ) ) ) / 2; int nButtonTop = ( nHeightWindow - spaceBetweenButtons - nHeightButton );
::OffsetRect( &rectButton, nButtonLeft, nButtonTop );
for( i = BT_OK; i <= BT_CANCEL; i++ ) { if( bShow[i] ) { ::MoveWindow( hButton[i], rectButton.left, rectButton.top, nWidthButton, nHeightButton, TRUE ); ::OffsetRect( &rectButton, nWidthButton + spaceBetweenButtons, 0 ); } }
return FALSE;}
BOOL CMessageBox::OnCommand( HWND hWnd, WPARAM wParam, LPARAM lParam){ switch( LOWORD( wParam ) ) { case IDOK: case IDYES: case IDNO: case IDCANCEL: ::EndDialog( hWnd, LOWORD( wParam ) ); break; } return FALSE;}
|