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

  1. // appdlg.cpp : implementation file
  2. //
  3.  
  4. //#include "stdafx.h"
  5. //#include "morespac.h"
  6. #include <afxwin.h>
  7. #include <afxext.h> 
  8. #include <ctl3d.h>
  9.                     
  10. #include "resource.h"                    
  11. #include "appdlg.h" 
  12. #include "grpdlg.h"
  13. #include "appinfo.h"
  14. #include "xfiledlg.h"
  15.  
  16. #ifdef _DEBUG
  17. #undef THIS_FILE
  18. static char BASED_CODE THIS_FILE[] = __FILE__;
  19. #define new DEBUG_NEW
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CAppDlg dialog
  24.  
  25. CAppDlg::CAppDlg(CWnd* pParent /*=NULL*/)
  26.    : CDialog(CAppDlg::IDD, pParent)
  27. {
  28.    //{{AFX_DATA_INIT(CAppDlg)
  29.    m_strAppArgs = "";
  30.    m_strAppDir = "";
  31.    m_strAppPath = "";
  32.    m_strAppTitle = "";
  33.    m_nRunState = 2;
  34.    //}}AFX_DATA_INIT
  35. }
  36.  
  37. void CAppDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39.    CDialog::DoDataExchange(pDX);
  40.    //{{AFX_DATA_MAP(CAppDlg)
  41.    DDX_Control(pDX, IDC_ICONPOS, m_Icon);
  42.    DDX_Text(pDX, IDC_APP_ARGS, m_strAppArgs);
  43.    DDV_MaxChars(pDX, m_strAppArgs, 128);
  44.    DDX_Text(pDX, IDC_APP_DIR, m_strAppDir);
  45.    DDV_MaxChars(pDX, m_strAppDir, 255);
  46.    DDX_Text(pDX, IDC_APP_PATH, m_strAppPath);
  47.    DDV_MaxChars(pDX, m_strAppPath, 255);
  48.    DDX_Text(pDX, IDC_APP_TITLE, m_strAppTitle);
  49.    DDV_MaxChars(pDX, m_strAppTitle, 128);
  50.    DDX_Radio(pDX, IDC_MAXIMIZED, m_nRunState);
  51.    //}}AFX_DATA_MAP
  52. }
  53.  
  54. BEGIN_MESSAGE_MAP(CAppDlg, CDialog)
  55.    //{{AFX_MSG_MAP(CAppDlg)
  56.    ON_BN_CLICKED(IDC_BUTTON1, OnClickedButton1)
  57.    ON_BN_CLICKED(IDC_BUTTON2, OnClickedButton2)
  58.    ON_EN_KILLFOCUS(IDC_APP_PATH, OnKillfocusAppPath)
  59.    ON_BN_CLICKED(IDC_HELP, OnClickedHelp)
  60.    //}}AFX_MSG_MAP
  61. END_MESSAGE_MAP()
  62.  
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CAppDlg message handlers
  65.  
  66. BOOL CAppDlg::OnInitDialog()
  67. {
  68.    // TODO: Add extra initialization here
  69.    // CenterWindow();
  70.    
  71.    // get a pointer to the CApplication to display
  72.    CAppGrpDlg * pParent = (CAppGrpDlg*)GetParent();
  73.    const CApplication * pApp = pParent->CurrentApplication();
  74.    
  75.    // set the values to the member vars
  76.    m_strAppArgs = pApp->Args();
  77.    m_strAppDir = pApp->InitialDir();
  78.    m_strAppPath = pApp->Path();
  79.    m_strAppTitle = pApp->Title();
  80.    m_nRunState = pApp->RunState();
  81.    
  82.    // if we have a path, set the icon
  83.    if ( ! m_strAppPath.IsEmpty() )
  84.    {
  85.       // try to get an icon
  86.       HICON hIcon = ExtractIcon( AfxGetInstanceHandle(), m_strAppPath, 0 );
  87.       if ( hIcon!=NULL )
  88.          m_Icon.SetIcon( hIcon );
  89.    }
  90.       
  91.    // do the original initialization (incudling ddx)
  92.    CDialog::OnInitDialog();
  93.    
  94.    return TRUE;  // return TRUE  unless you set the focus to a control
  95. }
  96.  
  97. void CAppDlg::OnClickedButton1()
  98. {
  99.    // TODO: Add your control notification handler code here
  100.    XFileDialog dlg("Select a tool", TRUE, "*.exe", 
  101.                 NULL, OFN_HIDEREADONLY, 
  102.                 "executables(*.exe)|*.exe|"
  103.                 "cp/m model files(*.com)|"
  104.                 "*.com|program information files(*.pif)|*.pif|"
  105.                 "all files(*.*)|*.*||", this  );
  106.                    
  107.    if ( dlg.DoModal() == IDOK )
  108.    {
  109.       m_strAppPath = dlg.GetPathName();
  110.       
  111.       // great. now we have a file to extract an icon from
  112.       // further, if no title is set yet, lets set this programs name
  113.       // as a title
  114.                
  115.       // try to get an icon
  116.       HICON hIcon = ExtractIcon( AfxGetInstanceHandle(), m_strAppPath, 0 );
  117.       
  118.       if ( hIcon!=NULL )
  119.          m_Icon.SetIcon( hIcon );
  120.  
  121.       if ( m_strAppTitle.IsEmpty() )
  122.       {  
  123.          char drive[_MAX_DRIVE];
  124.          char dir[_MAX_DIR];
  125.          char fname[_MAX_FNAME];
  126.          char ext[_MAX_EXT];
  127.          _splitpath( m_strAppPath, drive, dir, fname, ext );
  128.          m_strAppTitle = fname;
  129.       }
  130.       UpdateData( FALSE );
  131.    }
  132. }
  133.  
  134. void CAppDlg::OnClickedButton2()
  135. {
  136.    // TODO: Add your control notification handler code here
  137.    XDirectoryDialog dlg( "Select Initial Directory" );
  138.    if ( dlg.DoModal() == IDOK )
  139.    {
  140.       m_strAppDir = dlg.GetPathName();
  141.       UpdateData( FALSE );
  142.    }
  143. }
  144.  
  145. void CAppDlg::OnKillfocusAppPath()
  146. {
  147.    // TODO: Add your control notification handler code here
  148.    UpdateData();             
  149.              
  150.    // if title is empty, need to set title
  151.    if ( m_strAppTitle.IsEmpty() )
  152.    {  
  153.       char drive[_MAX_DRIVE];
  154.       char dir[_MAX_DIR];
  155.       char fname[_MAX_FNAME];
  156.       char ext[_MAX_EXT];
  157.       _splitpath( m_strAppPath, drive, dir, fname, ext );
  158.       m_strAppTitle = fname;
  159.    }
  160.    
  161.    // try to get an icon
  162.    HICON hIcon = ExtractIcon( AfxGetInstanceHandle(), m_strAppPath, 0 );
  163.       
  164.    if ( hIcon!=NULL )
  165.       m_Icon.SetIcon( hIcon );
  166.    
  167.    UpdateData( FALSE );
  168. }
  169.  
  170. void CAppDlg::OnClickedHelp()
  171. {
  172.    AfxGetApp()->WinHelp( 0L, HELP_CONTENTS );
  173. }
  174.  
  175.  
  176. void CAppDlg::OnOK()
  177. {
  178.    // TODO: Add extra validation here
  179.    if ( m_strAppPath.IsEmpty() )
  180.    {
  181.       AfxMessageBox( "You need to at least specify a program path.\n"
  182.                      "To just discard the dialog, use the cancel button." );
  183.       return;                     
  184.    }
  185.    
  186.    CDialog::OnOK();
  187. }
  188.