home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / WTJ9403.ZIP / WILDASS / SOURCE / TASKDLG.CPP < prev    next >
C/C++ Source or Header  |  1993-08-14  |  5KB  |  195 lines

  1. // taskdlg.cpp : implementation file
  2. //
  3.  
  4. // #include "stdafx.h"
  5.  
  6. #include <afxwin.h>
  7. #include <afxext.h> 
  8. #include <ctl3d.h>
  9.                       
  10. #include "resource.h"                      
  11. #include "tasks.h"
  12. #include "taskdlg.h" 
  13. #include "taskinfo.h"
  14.  
  15. #include "desktop.h"
  16. #include "app.h"
  17.  
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char BASED_CODE THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CTaskDlg dialog
  25.  
  26. CTaskDlg::CTaskDlg(CWnd* pParent /*=NULL*/)
  27.    : CDialog(CTaskDlg::IDD, pParent)
  28. {
  29.    //{{AFX_DATA_INIT(CTaskDlg)
  30.       // NOTE: the ClassWizard will add member initialization here
  31.    //}}AFX_DATA_INIT
  32. }
  33.  
  34. void CTaskDlg::DoDataExchange(CDataExchange* pDX)
  35. {
  36.    CDialog::DoDataExchange(pDX);
  37.    //{{AFX_DATA_MAP(CTaskDlg)
  38.       // NOTE: the ClassWizard will add DDX and DDV calls here
  39.    //}}AFX_DATA_MAP
  40. }
  41.  
  42. BEGIN_MESSAGE_MAP(CTaskDlg, CDialog)
  43.    //{{AFX_MSG_MAP(CTaskDlg)
  44.    ON_BN_CLICKED(IDC_KILLTASK, OnClickedKilltask)
  45.    ON_BN_CLICKED(IDC_CLOSETASK, OnClickedClosetask)
  46.    ON_BN_CLICKED(IDC_REFRESHTASK, OnClickedRefreshtask)
  47.    ON_BN_CLICKED(IDC_TASKINFO, OnClickedTaskinfo)
  48.    ON_BN_CLICKED(IDC_EXIT_WINDOWS, OnClickedExitWindows)
  49.    ON_BN_CLICKED(IDC_HELP, OnClickedHelp)
  50.    //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52.  
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CTaskDlg message handlers
  55.  
  56. BOOL CTaskDlg::OnInitDialog()
  57. {
  58.    CDialog::OnInitDialog();
  59.    
  60.    // center to parent
  61.    CenterWindow();
  62.  
  63.    // clear&reset the listbox
  64.    CListBox * pLst = (CListBox*)GetDlgItem( IDC_LSTTASKS );      
  65.    pLst->SetTabStops( 60 );
  66.  
  67.    // populate the task list from the m_lstTaks member
  68.    ListTasks();
  69.    
  70.    return TRUE;  
  71. }
  72.  
  73. void CTaskDlg::OnClickedRefreshtask()
  74. {
  75.    // build a new task list from scratch   
  76.    m_lstTasks.Rebuild();
  77.    
  78.    // populate the task list
  79.    ListTasks();                    
  80. }
  81.  
  82. void
  83. CTaskDlg::ListTasks()
  84. {   
  85.    // clear&reset the listbox
  86.    CListBox * pLst = (CListBox*)GetDlgItem( IDC_LSTTASKS );      
  87.    pLst->ResetContent();   
  88.    
  89.    // build a new tasklist
  90.    // do a new tasklist                       
  91.    for ( POSITION pos = m_lstTasks.GetHeadPosition(); pos!= NULL; )
  92.    {                 
  93.       CTask * pTask = m_lstTasks.GetNext( pos );
  94.       int index = pLst->AddString( CString( pTask->ModuleName()) + "\t[" +  CString( pTask->ExeName()) +"]" );
  95.       
  96.       // add a pointer to this task for later retrival
  97.       pLst->SetItemDataPtr( index, (void*)pTask );
  98.    }
  99. }
  100.  
  101.  
  102. void CTaskDlg::OnClickedKilltask()
  103. {
  104.    // TODO: Add your control notification handler code here
  105.    CTask * pTask = GetSelectedTask();
  106.  
  107.    // if nothing was selected, skip the rest
  108.    if ( pTask )
  109.    {
  110.       // let the task die; the CTask::Die fxn takes care _not_
  111.       // to kill the task if its no longer valid
  112.       m_lstTasks.CloseDirty( pTask );
  113.       
  114.       // take care of listbox refreshing      
  115.       ListTasks();
  116.    }      
  117. }
  118.  
  119. void CTaskDlg::OnClickedClosetask()
  120. {
  121.    // TODO: Add your control notification handler code here
  122.    CTask * pTask = GetSelectedTask();
  123.     
  124.    if ( pTask )
  125.    { 
  126.       m_lstTasks.CloseClean( pTask );
  127.       
  128.       // just in case this tasks _can`t_ be closed this way, take
  129.       // care the correct task list is displayed
  130.       m_lstTasks.Rebuild();
  131.  
  132.       // take care of listbox refreshing      
  133.       ListTasks();
  134.    }      
  135. }
  136.  
  137. void CTaskDlg::OnClickedTaskinfo()
  138. {
  139.    // TODO: Add your control notification handler code here
  140.    if ( ! GetSelectedTask() )
  141.       return;
  142.       
  143.    CTaskInfoDlg dlg( this );
  144.    dlg.DoModal();
  145. }
  146.  
  147. CTask * 
  148. CTaskDlg::GetSelectedTask() 
  149. {
  150.    CListBox * pLst = (CListBox*)GetDlgItem( IDC_LSTTASKS );
  151.    int index = pLst->GetCurSel();
  152.    
  153.    if ( index == LB_ERR )
  154.    {
  155.       AfxMessageBox( "No Task selected" );
  156.       return 0;
  157.    }
  158.    
  159.    CTask * pTask = (CTask*)pLst->GetItemDataPtr( index );
  160.           
  161.    if ( ! pTask->IsTask() )
  162.    {
  163.       AfxMessageBox("Selected Task is no longer running\nRefreshing Tasklist ...");
  164.       
  165.       // remove the task from the list and repaint the listbox
  166.       m_lstTasks.Remove( pTask );
  167.       
  168.       ListTasks();
  169.       
  170.       return 0;
  171.    }
  172.    
  173.    return pTask;
  174. }
  175.  
  176.  
  177. void CTaskDlg::OnClickedExitWindows()
  178. {
  179.    // store the current desktop to the profile
  180.    CDesktop desktop("DesktopOnExit");
  181.    desktop.Snapshot();
  182.    
  183.    // store our current configuration
  184.    ((CMyApp*)AfxGetApp())->WriteApplicationInfo();
  185.    
  186.    // quit windows
  187.    ExitWindows( 0, 0 );
  188. }
  189.  
  190.  
  191. void CTaskDlg::OnClickedHelp()
  192. {
  193.    AfxGetApp()->WinHelp( 0L, HELP_CONTENTS );
  194. }
  195.