home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 13
/
mediashare_13.zip
/
mediashare_13
/
ZIPPED
/
PROGRAM
/
WTJ9403.ZIP
/
WILDASS
/
SOURCE
/
PROGMGR.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-14
|
8KB
|
278 lines
// progmgr.cpp : implementation file
//
//#include "stdafx.h"
//#include "morespac.h"
#include <afxwin.h>
#include <afxext.h>
#include <ctl3d.h>
#include "resource.h"
#include "progmgr.h"
#include "grpfile.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CProgMgrDlg dialog
CProgMgrDlg::CProgMgrDlg(CWnd* pParent /*=NULL*/)
: CDialog(CProgMgrDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CProgMgrDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CProgMgrDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CProgMgrDlg)
DDX_Control(pDX, IDC_LIST_APPS, m_lstItems);
DDX_Control(pDX, IDC_LIST_GROUPS, m_lstGroups);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CProgMgrDlg, CDialog)
//{{AFX_MSG_MAP(CProgMgrDlg)
ON_LBN_SELCHANGE(IDC_LIST_GROUPS, OnSelchangeListGroups)
ON_LBN_DBLCLK(IDC_LIST_APPS, OnDblclkListApps)
ON_BN_CLICKED(IDC_HELP, OnClickedHelp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CProgMgrDlg message handlers
BOOL CProgMgrDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
// CenterWindow();
// find all group files
int iGroups=0;
while ( TRUE )
{
iGroups++;
CString strGroup("Group");
char szBuf[10];
itoa( iGroups, szBuf, 10 );
strGroup+=szBuf;
char szReturnBuffer[255];
GetPrivateProfileString( "Groups",
strGroup,
"none",
szReturnBuffer,
255,
"progman.ini" );
if ( CString( szReturnBuffer ) == CString("none") )
break;
// ok, have a group file
ProgramMgrGroup * pGrp = new ProgramMgrGroup( szReturnBuffer );
// store the pointer to the group file in the
// datat ptr section of the listbox
// and fill the boxes
int index = m_lstGroups.AddString( pGrp->Name() );
m_lstGroups.SetItemDataPtr( index, (void*)pGrp );
}
// make the first group the selected one
m_lstGroups.SetCurSel( 0 );
// display its items
OnSelchangeListGroups();
return TRUE; // return TRUE unless you set the focus to a control
}
#if 0
if ((fhGroupFile = OpenFile (lpszGroupFileName, &OpenBuff, OF_READ)) == NULL)
return FALSE;
// ******************************************************************
// Find out how much memory to allocate to hold the group file by
// seeking to the end of the file. This gives us the number of
// bytes that we have to allocate in the call to GlobalAlloc.
// ******************************************************************
cbGroup = (WORD) _llseek (fhGroupFile, 0L, 2);
_llseek (fhGroupFile, 0L, 0);
*ghMemGroupFileData = GlobalAlloc (GMEM_MOVEABLE, cbGroup);
lpGroupFileData = GlobalLock (*ghMemGroupFileData);
if (!lpGroupFileData)
{
_lclose (fhGroupFile);
return FALSE;
}
if (!_lread (fhGroupFile, lpGroupFileData, cbGroup))
{
_lclose (fhGroupFile);
if (GlobalUnlock (*ghMemGroupFileData))
GlobalFree (*ghMemGroupFileData);
return FALSE;
}
_lclose (fhGroupFile);
return TRUE;
#endif
#if 0
// ----------------------------------------------
//**************************************************************
// The rgiItems array in the group file may not have valid
// information in it because it doesn't get updated fully
// when the the user deletes an item from the group file. That
// is, the array doesn't get closed up to only include valid
// offsets. Instead, Windows puts 0 in the offset for the
// deleted item. So, what we're doing here is looking down the
// for non-zero entries in the array to get a true count (cItems)
// of items in it. In this way, we can use cItems as a limit in
// the while loop below.
//**************************************************************
_fmemcpy (&PMGroupHeader, lpGroupFileData, sizeof (PMGROUPHEADER));
rgiItems = (WORD FAR *) &lpGroupFileData [sizeof (PMGROUPHEADER)];
i = cItems = 0;
while (i++ < PMGroupHeader.cItems)
{
if (*rgiItems)
cItems++;
rgiItems++;
}
i = 0;
rgiItems = (WORD FAR *) &lpGroupFileData [sizeof (PMGROUPHEADER)];
// **************************************************************
// Now that we have the count of valid items in the group file,
// we cand go through and add the strings to the item list box.
// **************************************************************
while (i < cItems)
{
if (*rgiItems)
{
i++;
// Get the item structure filled in
_fmemcpy (&PMItemData,
&lpGroupFileData [*rgiItems],
sizeof (PMITEMDATA));
// Get the item name filled in
szTemp = szItemName;
do
*szTemp = lpGroupFileData [PMItemData.pName++];
while (*(szTemp++));
// Do the item command
szTemp = szCommand;
do
*szTemp = lpGroupFileData [PMItemData.pCommand++];
while (*(szTemp++));
// Fill in the icon path
szTemp = szIconPath;
do
*szTemp = lpGroupFileData [PMItemData.pIconPath++];
while (*(szTemp++));
// Add the information to the list box.
wsprintf ((LPSTR) UserMsg, (LPSTR) "%.30s \t%.30s \t%.22s",
(LPSTR) szItemName,
(LPSTR) szIconPath,
(LPSTR) szCommand);
SendMessage (hWndList, LB_ADDSTRING, 0, (LONG) (LPSTR) UserMsg);
}
rgiItems++;
}
// ------------
while (i++ < PMGroupHeader->cItems)
{
if (*rgiItems) // If there is an offset,
cItems++; // bump the count
rgiItems++;
}
wsprintf ((LPSTR) szUserMsg, (LPSTR) "%.30s \t%.30s \t%d",
(LPSTR) szFileName,
(LPSTR) &lpGroupFileData [PMGroupHeader->pName],
cItems);
SendMessage (hWndListBox, LB_ADDSTRING, 0, (LONG) (LPSTR) szUserMsg);
lpszGroupNames += lstrlen (lpszGroupNames) + 1;
#endif
void CProgMgrDlg::OnSelchangeListGroups()
{
// retrieve the program mgr group
int index = m_lstGroups.GetCurSel();
ASSERT( index!=LB_ERR );
ProgramMgrGroup * pGrp = (ProgramMgrGroup *)m_lstGroups.GetItemDataPtr( index );
// reset the item-listbox
m_lstItems.ResetContent();
// fill it
for ( POSITION pos=pGrp->GetHeadPosition(); pos!=NULL; )
{
ProgramMgrItem * pItem = pGrp->GetNext( pos );
int index = m_lstItems.AddString( pItem->Name() );
m_lstItems.SetItemDataPtr( index, pItem );
}
}
void CProgMgrDlg::OnOK()
{
// free the alloted memory
int nEntries = m_lstGroups.GetCount();
for ( int iEntries = 0; iEntries < nEntries; iEntries++ )
{
ProgramMgrGroup * pGrp = (ProgramMgrGroup *)m_lstGroups.GetItemDataPtr( iEntries );
delete pGrp;
}
CDialog::OnOK();
}
void CProgMgrDlg::OnDblclkListApps()
{
// Get the selecetd item
int index = m_lstItems.GetCurSel();
ASSERT( index != LB_ERR );
// get the item
ProgramMgrItem * pItem = (ProgramMgrItem * )m_lstItems.GetItemDataPtr( index );
// run the command
WinExec( pItem->Path(), SW_SHOWNORMAL );
// fade ....
OnOK();
}
void CProgMgrDlg::OnClickedHelp()
{
AfxGetApp()->WinHelp( 0L, HELP_CONTENTS );
}