home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 13
/
mediashare_13.zip
/
mediashare_13
/
ZIPPED
/
PROGRAM
/
WTJ9403.ZIP
/
WILDASS
/
SOURCE
/
GRPDLG.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-14
|
9KB
|
341 lines
// grpdlg.cpp : implementation file
//
#include <afxwin.h>
#include <afxext.h>
#include <ctl3d.h>
//#include "stdafx.h"
//#include "morespac.h"
#include "resource.h"
#include "grpdlg.h"
#include "appdlg.h"
#include "appinfo.h"
#include "app.h"
#include "icondlg.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#define new DEBUG_NEW
#endif
/////////////////////////////////////////////////////////////////////////////
// CAppGrpDlg dialog
CAppGrpDlg::CAppGrpDlg(CWnd* pParent /*=NULL*/)
: CDialog(CAppGrpDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAppGrpDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_pCurrent = 0;
}
void CAppGrpDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAppGrpDlg)
DDX_Control(pDX, IDC_GROUPICON, m_Icon);
DDX_Control(pDX, IDC_LISTAPPS, m_lstApps);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAppGrpDlg, CDialog)
//{{AFX_MSG_MAP(CAppGrpDlg)
ON_BN_CLICKED(IDC_CHANGEICON, OnClickedChangeicon)
ON_BN_CLICKED(IDC_HELP1, OnClickedHelp1)
ON_BN_CLICKED(IDC_EDIT, OnClickedEdit)
ON_BN_CLICKED(IDC_ADD, OnClickedAdd)
ON_BN_CLICKED(IDC_REMOVE, OnClickedRemove)
ON_BN_CLICKED(IDC_LAUNCH, OnClickedLaunch)
ON_LBN_DBLCLK(IDC_LISTAPPS, OnDblclkListapps)
ON_BN_CLICKED(IDC_REMOVEALL, OnClickedRemoveAll)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAppGrpDlg message handlers
BOOL CAppGrpDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
// CenterWindow();
// get a pointer to the current AppList
// and insert the CApplications from this list
// to the Listbox
CMyApp * pApp = (CMyApp*)AfxGetApp();
const CApplicationList * pList = pApp->CurrentApplicationList();
// check for the icon to use for this group
// this is either IDI_GROUPEMTY or whatever
// icon was set in other ways and stored to this
// group
m_strIconFile = pList->IconFile();
m_nIcon = pList->IconID();
for ( POSITION pos=pList->GetHeadPosition(); pos!=NULL; )
{
const CApplication * pApp = pList->GetNext(pos);
CApplication * pCopy = new CApplication( *pApp );
int index = m_lstApps.AddString( pCopy->Title() );
m_lstApps.SetItemDataPtr( index, (void*)pCopy );
}
// make the first item the currently selected one
if ( m_lstApps.GetCount() )
m_lstApps.SetCurSel( 0 );
HandleIcon();
return TRUE; // return TRUE unless you set the focus to a control
}
void
CAppGrpDlg::HandleIcon()
{
// if an icon is specified via file and number,
// use this one
HICON hIcon = ExtractIcon( AfxGetInstanceHandle(), m_strIconFile, m_nIcon );
if ( hIcon!=NULL && hIcon != (HICON)1 )
{
m_Icon.SetIcon( hIcon );
return;
}
// if there is no item in this group
// use the IDI_GROUPEMPTY icon
if ( m_lstApps.GetCount() == 0 )
{
m_Icon.SetIcon( ((CMyApp*)AfxGetApp())->LoadIcon( IDI_GROUPEMPTY ) );
return;
}
// if there is only one icon in this group,
// use it`s first icon
// if it has none, use the ordinary group icon
if ( m_lstApps.GetCount()==1 )
{
CApplication * pApp = (CApplication*)m_lstApps.GetItemDataPtr( 0 );
HICON hIcon = ExtractIcon( AfxGetInstanceHandle(), pApp->Path(), 0 );
if ( hIcon )
{
m_Icon.SetIcon( hIcon );
return;
}
}
// in all other cases, use the group icon
m_Icon.SetIcon( ((CMyApp*)AfxGetApp())->LoadIcon( IDI_GROUP ));
}
const CApplication *
CAppGrpDlg::CurrentApplication() const
{
ASSERT( m_pCurrent != 0 );
return m_pCurrent;
}
void CAppGrpDlg::OnClickedChangeicon()
{
// TODO: Add your control notification handler code here
CIconDlg dlg;
if ( dlg.DoModal()==IDOK )
{
m_strIconFile = dlg.m_strIconFile;
m_nIcon = dlg.m_nIcon;
HandleIcon();
}
}
void CAppGrpDlg::OnClickedHelp1()
{
AfxGetApp()->WinHelp( 0L, HELP_CONTENTS );
}
void CAppGrpDlg::OnClickedEdit()
{
// TODO: Add your control notification handler code here
// Get the currently selected item
int index = m_lstApps.GetCurSel();
if ( index == LB_ERR )
{
AfxMessageBox("You need to select an item from the listbox to edit one");
return;
}
// if there is a selected item,
// get its attached CApplication and
// set m_pCurrent so that the
// edit dialog will be able to
// retrieve the needed information
m_pCurrent = (CApplication*)m_lstApps.GetItemDataPtr( index );
CAppDlg dlg;
if ( dlg.DoModal() == IDOK )
{
// seems we have some changed values here
m_pCurrent->Description(
dlg.m_strAppPath,
dlg.m_strAppTitle,
dlg.m_strAppArgs,
dlg.m_strAppDir,
dlg.m_nRunState
);
// change the apps title in the listbox
m_lstApps.DeleteString( index );
m_lstApps.InsertString( index, m_pCurrent->Title() );
m_lstApps.SetItemDataPtr( index, (void*)m_pCurrent );
// make it the currently selected item,
m_lstApps.SetCurSel( index );
// handle the icon display
HandleIcon();
}
m_pCurrent = 0;
}
void CAppGrpDlg::OnClickedAdd()
{
// TODO: Add your control notification handler code here
// add a new application
m_pCurrent = new CApplication();
CAppDlg dlg;
if ( dlg.DoModal() == IDOK )
{
// seems we have a new application
// we might want to launch
m_pCurrent->Description(
dlg.m_strAppPath,
dlg.m_strAppTitle,
dlg.m_strAppArgs,
dlg.m_strAppDir,
dlg.m_nRunState
);
// add the apps title to the listbox
int index = m_lstApps.AddString( m_pCurrent->Title() );
m_lstApps.SetItemDataPtr( index, (void*)m_pCurrent );
// make it the currently selected item,
m_lstApps.SetCurSel( index );
// handle the icon display
HandleIcon();
}
else
{
delete m_pCurrent;
}
m_pCurrent = 0;
}
void CAppGrpDlg::OnClickedRemove()
{
// Get the currently selected item
int index = m_lstApps.GetCurSel();
if ( index == LB_ERR )
{
AfxMessageBox("You need to select an item from the listbox to delete one");
return;
}
// remove the CApplication attached to this item
delete (CApplication*)m_lstApps.GetItemDataPtr( index );
// remove the string
m_lstApps.DeleteString( index );
// handle icon display
HandleIcon();
}
void CAppGrpDlg::OnClickedLaunch()
{
// TODO: Add your control notification handler code here
// Get the currently selected item
int index = m_lstApps.GetCurSel();
if ( index == LB_ERR )
{
AfxMessageBox("You need to select an item from the listbox to launch one");
return;
}
// run the CApplication attached to this item
CApplication * pApp = (CApplication*)m_lstApps.GetItemDataPtr( index );
pApp->Run();
// fade
OnOK();
}
void CAppGrpDlg::OnDblclkListapps()
{
// TODO: Add your control notification handler code here
OnClickedLaunch();
}
void CAppGrpDlg::OnOK()
{
// TODO: Add extra validation here
// store the icon info for later usage
m_ApplicationList.Icon( m_strIconFile, m_nIcon );
// copy the CApplist fromt eh item data ptrs to the
// m_ApplicationList so the calling
// function can retrieve the data
int nItems = m_lstApps.GetCount();
for ( int iItems=0; iItems<nItems; ++iItems )
{
m_ApplicationList.AddTail( new CApplication ( *(CApplication*)m_lstApps.GetItemDataPtr(iItems)) );
}
// free the item data ptrs
FreeItemData();
CDialog::OnOK();
}
void
CAppGrpDlg::FreeItemData()
{
int nItems = m_lstApps.GetCount();
for ( int iItems=0; iItems<nItems; ++iItems )
{
delete (CApplication*)m_lstApps.GetItemDataPtr(iItems);
}
}
void CAppGrpDlg::OnCancel()
{
// TODO: Add extra cleanup here
FreeItemData();
CDialog::OnCancel();
}
void CAppGrpDlg::OnClickedRemoveAll()
{
// TODO: Add your control notification handler code here
FreeItemData();
m_lstApps.ResetContent();
m_strIconFile="";
m_nIcon=0;
HandleIcon();
}