|
|
//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright � 2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 08/10/2003
// PROJECT:
// SUBSYSTEM:
// FILE: PanelWnd.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of PanelWnd.cpp
//----------------------------------------------------------------------------
#include "stdafx.h"
#include "chicago.h"
#include "PanelWnd.h"
#include "..\..\LgLib\LgAux.h"
#include "..\..\LgLib\Version.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;#endif
CPanelWnd::CPanelWnd(){ m_pChildWnd = NULL; m_dAspect = 1.0; m_nMode = PN_NONE;
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CPanelWnd::CPanelWnd") );}
CPanelWnd::~CPanelWnd(){ LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CPanelWnd::~CPanelWnd") );}
BEGIN_MESSAGE_MAP(CPanelWnd, CWnd) //{{AFX_MSG_MAP(CPanelWnd)
ON_WM_SIZE() ON_WM_SIZING() ON_WM_TIMER() ON_WM_MOUSEMOVE() ON_WM_LBUTTONDOWN() ON_WM_GETMINMAXINFO() //}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CPanelWnd::Create(CWnd *pParentWnd, int x, int y, int nWidth, int nHeight){ return Create( pParentWnd, &CRect( x, y, x + nWidth, y + nHeight ) );}
BOOL CPanelWnd::Create( CWnd *pParentWnd, CRect *pRect ){ DestroyWindow();
CString strClassName = ::AfxRegisterWndClass( CS_HREDRAW | CS_VREDRAW, ::LoadCursor( NULL, IDC_ARROW ), GetSysColorBrush( COLOR_BTNFACE ), NULL );
if( !CWnd::Create( strClassName, "", WS_CHILD | WS_DLGFRAME | WS_CLIPSIBLINGS, *pRect, pParentWnd, 0 ) ) return FALSE;/*
if( !CWnd::CreateEx( 0, strClassName, NULL, WS_POPUP | WS_DLGFRAME | WS_CLIPSIBLINGS, *pRect, pParentWnd, 0 ) ) return FALSE;
// Set WS_EX_LAYERED on this window
BOOL bSet = SetWindowLong( GetSafeHwnd(), GWL_EXSTYLE, GetWindowLong( GetSafeHwnd(), GWL_EXSTYLE) | WS_EX_LAYERED );
DWORD dwError = GetLastError();
// Make this window 70% alpha
bSet = SetLayeredWindowAttributes(GetSafeHwnd(), 0, (255 * 50) / 100, LWA_ALPHA);
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CPanelWnd::CPanelWnd"), _T("Succeeded") );
SetTimer( 1, 500, NULL );*/ return TRUE;}
BOOL CPanelWnd::DestroyWindow() { m_pChildWnd = NULL; m_dAspect = 1.0; m_nMode = PN_NONE; return CWnd::DestroyWindow();}
BOOL CPanelWnd::PlaceChild( CWnd *pChildWnd ){ if( !pChildWnd ) return FALSE;
m_nMode = PM_SCALE;
m_pChildWnd = pChildWnd;
m_pChildWnd->SetParent( this );
ScaleChildWindow();
m_pChildWnd->ShowWindow( SW_SHOW );
return TRUE;}
BOOL CPanelWnd::PlaceChildCenter( CWnd *pChildWnd ){ if( !pChildWnd ) return FALSE;
m_nMode = PM_CENTER;
m_pChildWnd = pChildWnd;
m_pChildWnd->SetParent( this );
CenterChildWindow();
m_pChildWnd->ShowWindow( SW_SHOW );
return TRUE;}
BOOL CPanelWnd::PlaceChildFit( CWnd *pChildWnd, double dAspect ){ if( !pChildWnd ) return FALSE;
if( dAspect <= 0.0 ) return FALSE;
m_nMode = PM_FIT;
m_pChildWnd = pChildWnd; m_dAspect = dAspect;
m_pChildWnd->SetParent( this );
FitChildWindow();
m_pChildWnd->ShowWindow( SW_SHOW );
return TRUE;}
/*
DWORD m_dwTime = GetTickCount();BOOL m_bWindowCompact = FALSE;CRect m_FullRect;*/
void CPanelWnd::OnSize(UINT nType, int cx, int cy) { LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CPanelWnd::OnSize"), _T("Started...") );
CWnd::OnSize(nType, cx, cy);
switch( m_nMode ) { case PM_FIT: FitChildWindow(); break; case PM_SCALE: ScaleChildWindow(); break; case PM_CENTER: CenterChildWindow(); break; }/*
if( m_bWindowCompact ) { m_bWindowCompact = FALSE;
GetWindowRect( &m_FullRect );
if( m_pChildWnd ) m_pChildWnd->ShowWindow( SW_SHOW ); }*/ LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CPanelWnd::OnSize"), _T("Done") );}
void CPanelWnd::OnSizing(UINT fwSide, LPRECT pRect) { CWnd::OnSizing(fwSide, pRect); if( m_nMode != PM_CENTER ) return;
CRect ChildRect; m_pChildWnd->GetWindowRect( &ChildRect ); ChildRect -= ChildRect.TopLeft();
CRect SizeRect( pRect ); SizeRect -= SizeRect.TopLeft();
CSize Diff( SizeRect.Width() - ChildRect.Width(), SizeRect.Height() - ChildRect.Height() );
switch( fwSide ) { case WMSZ_TOPLEFT: if( Diff.cy < 0 ) pRect->top = pRect->bottom - ChildRect.Height(); case WMSZ_LEFT: if( Diff.cx < 0 ) pRect->left = pRect->right - ChildRect.Width(); break; case WMSZ_BOTTOMRIGHT: if( Diff.cy < 0 ) pRect->bottom = pRect->top + ChildRect.Height(); case WMSZ_RIGHT: if( Diff.cx < 0 ) pRect->right = pRect->left + ChildRect.Width(); break; case WMSZ_TOPRIGHT: if( Diff.cx < 0 ) pRect->right = pRect->left + ChildRect.Width(); case WMSZ_TOP: if( Diff.cy < 0 ) pRect->top = pRect->bottom - ChildRect.Height(); break; case WMSZ_BOTTOMLEFT: if( Diff.cx < 0 ) pRect->left = pRect->right - ChildRect.Width(); case WMSZ_BOTTOM: if( Diff.cy < 0 ) pRect->bottom = pRect->top + ChildRect.Height(); break; }}
void CPanelWnd::FitChildWindow(){ if( !m_pChildWnd ) return;
CRect WholeRect; GetClientRect( &WholeRect );
CRect FitRect; ::FitRectWithAspect( &WholeRect, &FitRect, m_dAspect );
m_pChildWnd->MoveWindow( &FitRect );}
void CPanelWnd::CenterChildWindow(){ if( !m_pChildWnd ) return;
CRect ChildRect; m_pChildWnd->GetWindowRect( &ChildRect ); ChildRect -= ChildRect.TopLeft();
CRect WholeRect; GetClientRect( &WholeRect );
int xShift = ( WholeRect.Width() - ChildRect.Width() ) >> 1; int yShift = ( WholeRect.Height() - ChildRect.Height() ) >> 1;
ChildRect += CPoint( xShift, yShift );
m_pChildWnd->MoveWindow( &ChildRect );}
void CPanelWnd::ScaleChildWindow(){ if( !m_pChildWnd ) return;
CRect WholeRect; GetClientRect( &WholeRect );
m_pChildWnd->MoveWindow( &WholeRect );}
void CPanelWnd::OnTimer(UINT nIDEvent) {/*
CPoint point; GetCursorPos( &point );
CRect rect; GetWindowRect( &rect );
if( rect.PtInRect( point ) ) { m_dwTime = GetTickCount();
if( m_bWindowCompact ) { m_bWindowCompact = FALSE; if( m_pChildWnd ) m_pChildWnd->ShowWindow( SW_SHOW );
MoveWindow( &m_FullRect ); }
}
if( m_bWindowCompact ) { } else { if( (GetTickCount() - m_dwTime) > 1000 ) { m_FullRect = rect;
rect.left = rect.right - 10; MoveWindow( &rect );
if( m_pChildWnd ) m_pChildWnd->ShowWindow( SW_HIDE );
m_bWindowCompact = TRUE; } }*/ CWnd::OnTimer(nIDEvent);}
void CPanelWnd::OnGetMinMaxInfo( MINMAXINFO FAR* lpMMI ) {// lpMMI->ptMinTrackSize.x = 1;
// lpMMI->ptMinTrackSize.y = 1;
CWnd::OnGetMinMaxInfo(lpMMI);}
|