home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 13
/
mediashare_13.zip
/
mediashare_13
/
ZIPPED
/
PROGRAM
/
WTJ9403.ZIP
/
WILDASS
/
SOURCE
/
MAINWND.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-14
|
12KB
|
418 lines
// mainwnd.cpp
//
// class behaviour of the main window class
//
// update: 1.00 28-Jul-93 tw
// 1.01 01-Aug-93 tw put in FakeCptn functionality
#include <afxwin.h>
#include <afxext.h>
#include <ctl3d.h>
#include "resource.h"
#include "mainwnd.h"
#include "iconbtn.h"
#include "app.h"
static UINT BASED_CODE arrTileButtons[] =
{
IDB_TILE1, IDB_TILE2, IDB_TILE3, IDB_TILE4
};
static UINT BASED_CODE arrWorkspaceButtons[] =
{
IDB_WSP1, IDB_WSP2, IDB_WSP3, IDB_WSP4
};
static UINT BASED_CODE arrOptionsButtons[] =
{
IDB_OPTS1, IDB_OPTS2, IDB_OPTS3, IDB_OPTS4
};
BEGIN_MESSAGE_MAP( CMainWnd, CFrameWnd )
ON_WM_CREATE()
ON_WM_NCHITTEST()
ON_WM_PAINT()
ON_WM_ERASEBKGND()
ON_WM_ACTIVATEAPP()
ON_WM_SYSCOMMAND()
ON_COMMAND( nBeginIdIconButtons, OnLaunchGrp1 )
ON_COMMAND( nBeginIdIconButtons+1, OnLaunchGrp2 )
ON_COMMAND( nBeginIdIconButtons+2, OnLaunchGrp3 )
ON_COMMAND( nBeginIdIconButtons+3, OnLaunchGrp4 )
ON_COMMAND( nBeginIdIconButtons+4, OnLaunchGrp5 )
ON_COMMAND( nBeginIdIconButtons+5, OnLaunchGrp6 )
ON_COMMAND( nBeginIdIconButtons+6, OnLaunchGrp7 )
ON_COMMAND( nBeginIdIconButtons+7, OnLaunchGrp8 )
ON_COMMAND( nBeginIdEditButtons, OnEditGrp1 )
ON_COMMAND( nBeginIdEditButtons+1, OnEditGrp2 )
ON_COMMAND( nBeginIdEditButtons+2, OnEditGrp3 )
ON_COMMAND( nBeginIdEditButtons+3, OnEditGrp4 )
ON_COMMAND( nBeginIdEditButtons+4, OnEditGrp5 )
ON_COMMAND( nBeginIdEditButtons+5, OnEditGrp6 )
ON_COMMAND( nBeginIdEditButtons+6, OnEditGrp7 )
ON_COMMAND( nBeginIdEditButtons+7, OnEditGrp8 )
END_MESSAGE_MAP()
CMainWnd::CMainWnd()
{
// calculate the fake captions size
int cyCaption = GetSystemMetrics( SM_CYCAPTION ) / 3;
// calculate the number of toolbar buttons
m_nToolBarButtons = sizeof( arrTileButtons ) / sizeof(UINT);
// calculate the 3 toolbars rects
int cxBar = m_nToolBarButtons * CMainWnd::cxBtnToolBar + 2 * CMainWnd::cxFrameToolBar;
m_rectTileBar = CRect( 0, cyCaption,
cxBar, cyCaption + CMainWnd::cyBtnToolBar + CMainWnd::cyFrameToolBar );
m_rectTileBar.OffsetRect( 0, 2 );
m_rectWorkspaceBar = m_rectTileBar;
m_rectWorkspaceBar.OffsetRect( CSize( 0, CMainWnd::cyBtnToolBar + CMainWnd::cyFrameToolBar ) );
m_rectOptionsBar = m_rectWorkspaceBar;
m_rectOptionsBar.OffsetRect( CSize( 0, CMainWnd::cyBtnToolBar + CMainWnd::cyFrameToolBar ) );
// calculate the windows size
m_rectWnd = CRect( 0, 0,
m_rectTileBar.Width()+ // tileBar width
nIconButtons*CIconButton::Width()+ // plus icon buttons width
CMainWnd::cxFrameToolBar- // frame toolbar width
nIconButtons, // icon buttons overlap by one pixel
m_rectOptionsBar.BottomRight().y+
CMainWnd::cyFrameToolBar );
// calculate the fake caption bar size
m_pRectCaption = new CRect( 0, 0, m_rectWnd.Width(), cyCaption);
ASSERT( m_pRectCaption );
// create it, using the base classes create fxn
VERIFY( CreateEx( WS_EX_TOPMOST, NULL, AfxGetAppName(),
WS_POPUP | WS_BORDER, m_rectWnd.TopLeft().x,
m_rectWnd.TopLeft().y, m_rectWnd.Width(),
m_rectWnd.Height(), NULL, NULL ));
}
CMainWnd::~CMainWnd()
{
// take care of the alloted objects
delete m_pRectCaption;
}
void
CMainWnd::DroppedFiles( HDROP hDrop, UINT nID )
{
// get number of files
UINT nFiles = DragQueryFile( hDrop, -1, NULL, 0 );
// calculate, which list is responsible for these files
if ( nID >= nBeginIdEditButtons ) nID-=100;
nID-=200; // id is now an index into the applist array
// for each file, query the file information
for ( UINT iFiles=0; iFiles<nFiles; iFiles++ )
{
UINT cbFileBuffer = DragQueryFile( hDrop, iFiles, NULL, 0 );
CString strFileName;
char * pFileName = strFileName.GetBuffer( cbFileBuffer+2 );
DragQueryFile( hDrop, iFiles, pFileName, cbFileBuffer+1 );
strFileName.ReleaseBuffer();
// add the filename to the appropriate Application list
// and take care of possible icon redraws
((CMyApp*)AfxGetApp())->AddToGroup( nID, strFileName );
m_arrIconButtons[nID].SetIcon( ((CMyApp*)AfxGetApp())->Icon( nID ));
}
// free the allocated dropfile memory
::DragFinish( hDrop );
}
void
CMainWnd::OnSysCommand( UINT nID, LPARAM lParam )
{
if ( nID == SC_CLOSE )
{
AfxMessageBox("You cannot close this application with that command."
"If you close down MoreSpace!, Windows will be terminated. "
"If you want to end your Windows session, use the Exit Windows button "
"from the task dialog." );
}
else
{
CWnd::OnSysCommand( nID, lParam );
}
}
int
CMainWnd::OnCreate( LPCREATESTRUCT lpCreateStruct )
{
// make sure base classes OnCreate works
if ( CFrameWnd::OnCreate( lpCreateStruct ) == -1 )
return -1;
// make the window to be of appropriate size
// but don`t show (repaint) it
MoveWindow( m_rectWnd, FALSE );
// create the toolbars
CreateToolBar( &m_wndTileBar,IDR_TILEBAR, arrTileButtons, &m_rectTileBar );
CreateToolBar( &m_wndWorkspaceBar,IDR_WORKSPACEBAR, arrWorkspaceButtons, &m_rectWorkspaceBar );
CreateToolBar( &m_wndOptionsBar,IDR_OPTIONSBAR, arrOptionsButtons, &m_rectOptionsBar );
// create the IconButtons and the editButtons
CPoint posIconButton( m_rectTileBar.Width()-1, m_rectTileBar.TopLeft().y+CMainWnd::cyFrameToolBar );
CRect rectWnd;
for ( UINT iIconButtons=0; iIconButtons < nIconButtons; ++iIconButtons )
{
m_arrIconButtons[iIconButtons].Create( this, posIconButton, nBeginIdIconButtons+iIconButtons );
// set the icon for this button by asking the app what icon
// the attached list is using
m_arrIconButtons[iIconButtons].SetIcon( ((CMyApp*)AfxGetApp())->Icon( iIconButtons ));
// tell windows this button will accept files
m_arrIconButtons[iIconButtons].DragAcceptFiles( TRUE );
// create the edit buttons
CRect rectWnd;
m_arrIconButtons[iIconButtons].GetWindowRect( &rectWnd );
ScreenToClient( &rectWnd );
CRect posEditButton( rectWnd.TopLeft().x,
rectWnd.BottomRight().y-1,
rectWnd.TopLeft().x+rectWnd.Width(),
m_rectOptionsBar.BottomRight().y );
m_arrEditButtons[iIconButtons].Create( "",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
posEditButton,
this,
nBeginIdEditButtons+iIconButtons );
// move pos so the next button is located someplace else
posIconButton.Offset( CIconButton::Width()-1, 0 );
m_arrEditButtons[iIconButtons].DragAcceptFiles( TRUE );
}
// retrun OK, in this case: 0
return 0;
}
void
CMainWnd::CreateToolBar( CToolBar * pBar, UINT nIdResource, const UINT * pArrBtns, CRect * pRect )
{
// create the toolbar
VERIFY( pBar->Create( this, WS_CHILD | WS_VISIBLE | CBRS_NOALIGN ));
VERIFY( pBar->LoadBitmap( nIdResource ));
VERIFY( pBar->SetButtons( pArrBtns, m_nToolBarButtons ));
pBar->SetSizes( CSize( CMainWnd::cxBtnToolBar, CMainWnd::cyBtnToolBar ),
CSize( CMainWnd::cxImageToolBar, CMainWnd::cyImageToolBar ));
// Move the bar were we want it to be
ScreenToClient( pRect );
pBar->MoveWindow( *pRect );
}
UINT
CMainWnd::OnNcHitTest( CPoint pnt )
{
// get the client coordinates of the point we`re testing
ScreenToClient( &pnt );
// if we`re in the fake caption bar, tell windows we`re in
// the actual caption bar
if ( m_pRectCaption->PtInRect( pnt ))
{
return HTCAPTION;
}
// base class will do the rest
return CFrameWnd::OnNcHitTest( pnt );
}
void
CMainWnd::OnPaint()
{
// select a color according to focus
COLORREF col = ( GetFocus() == this ) ? GetSysColor( COLOR_ACTIVECAPTION )
: GetSysColor( COLOR_INACTIVECAPTION );
// paint the caption
CBrush brushCaption;
VERIFY( brushCaption.CreateSolidBrush( col ));
CPaintDC dc( this );
dc.FillRect( *m_pRectCaption, &brushCaption );
CPen penBlack;
VERIFY( penBlack.CreatePen( PS_SOLID, 0, RGB( 0, 0, 0) ));
// paint the black separator line
CPen * pPenOrig;
VERIFY( pPenOrig = dc.SelectObject( &penBlack ));
dc.MoveTo( 0, m_pRectCaption->bottom );
VERIFY( dc.LineTo( m_pRectCaption->right, m_pRectCaption->bottom ));
dc.SelectObject( pPenOrig );
}
BOOL
CMainWnd::OnEraseBkgnd( CDC* pDC )
{
CRect rect;
GetClientRect( &rect );
CBrush brushGray( GetSysColor( COLOR_BTNFACE ) );
pDC->FillRect( &rect, &brushGray );
return FALSE;
}
void
CMainWnd::OnActivateApp( BOOL bActive, HTASK /*hTask*/ )
{
// if we are supposed to stay visible, we need to paint
// some stuff - in the other case, we only need to hide
// ourselves away
CMyApp * pApp = (CMyApp*)AfxGetApp();
// explicitly set focus so we are
// painted, even when activated via taskmanager
SetFocus();
if( pApp->Settings_StayVisible() )
{
// we only need to paint the fake caption bar
// in this case
InvalidateRect( *m_pRectCaption );
}
else
{
// we only need to do something
// about the hiding: in case we are
// _activated_ the mousehook will show
// us...
if ( ! bActive )
ShowWindow( SW_HIDE );
}
}
void
CMainWnd::OnLaunch( int nGrp )
{
((CMyApp*)AfxGetApp())->OnLaunchGroup( nGrp );
m_arrIconButtons[nGrp].SetIcon( ((CMyApp*)AfxGetApp())->Icon( nGrp ));
}
void
CMainWnd::OnEdit( int nGrp )
{
((CMyApp*)AfxGetApp())->OnEditGroup( nGrp );
m_arrIconButtons[nGrp].SetIcon( ((CMyApp*)AfxGetApp())->Icon( nGrp ));
}
void
CMainWnd::OnLaunchGrp1()
{
OnLaunch( 0 );
}
void
CMainWnd::OnLaunchGrp2()
{
OnLaunch( 1 );
}
void
CMainWnd::OnLaunchGrp3()
{
OnLaunch( 2 );
}
void
CMainWnd::OnLaunchGrp4()
{
OnLaunch( 3 );
}
void
CMainWnd::OnLaunchGrp5()
{
OnLaunch( 4 );
}
void
CMainWnd::OnLaunchGrp6()
{
OnLaunch( 5 );
}
void
CMainWnd::OnLaunchGrp7()
{
OnLaunch( 6 );
}
void
CMainWnd::OnLaunchGrp8()
{
OnLaunch( 7 );
}
void
CMainWnd::OnEditGrp1()
{
OnEdit( 0 );
}
void
CMainWnd::OnEditGrp2()
{
OnEdit( 1 );
}
void
CMainWnd::OnEditGrp3()
{
OnEdit( 2 );
}
void
CMainWnd::OnEditGrp4()
{
OnEdit( 3 );
}
void
CMainWnd::OnEditGrp5()
{
OnEdit( 4 );
}
void
CMainWnd::OnEditGrp6()
{
OnEdit( 5 );
}
void
CMainWnd::OnEditGrp7()
{
OnEdit( 6 );
}
void
CMainWnd::OnEditGrp8()
{
OnEdit( 7 );
}