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

  1. // icondlg.cpp : implementation file
  2. //
  3.  
  4. #include <afxwin.h>
  5. #include <afxext.h> 
  6. #include <ctl3d.h>
  7.  
  8. #include "resource.h"
  9. //#include "stdafx.h"
  10. //#include "morespac.h"
  11. #include "icondlg.h"
  12. #include "xfiledlg.h"
  13.  
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char BASED_CODE THIS_FILE[] = __FILE__;
  17. #define new DEBUG_NEW
  18. #endif
  19.  
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CIconDlg dialog
  22.  
  23. CIconDlg::CIconDlg(CWnd* pParent /*=NULL*/)
  24.    : CDialog(CIconDlg::IDD, pParent)
  25. {
  26.    //{{AFX_DATA_INIT(CIconDlg)
  27.    m_strIconFile = "(none)";
  28.    //}}AFX_DATA_INIT
  29.    
  30.    // m_nIcon;  // only used for the transfer down
  31. }
  32.  
  33. void CIconDlg::DoDataExchange(CDataExchange* pDX)
  34. {
  35.    CDialog::DoDataExchange(pDX);
  36.    //{{AFX_DATA_MAP(CIconDlg)
  37.    DDX_Control(pDX, IDC_THE_ICON, m_Icon);
  38.    DDX_Text(pDX, IDC_ICONFILE, m_strIconFile);
  39.    DDV_MaxChars(pDX, m_strIconFile, 256);
  40.    //}}AFX_DATA_MAP
  41. }
  42.  
  43. BEGIN_MESSAGE_MAP(CIconDlg, CDialog)
  44.    //{{AFX_MSG_MAP(CIconDlg)
  45.    ON_BN_CLICKED(IDC_BUTTONLEFT, OnClickedButtonleft)
  46.    ON_BN_CLICKED(IDC_BROWSE, OnClickedBrowse)
  47.    ON_BN_CLICKED(IDC_BUTTONRIGHT, OnClickedButtonright)
  48.    ON_BN_CLICKED(IDC_HELP, OnClickedHelp)
  49.    //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51.  
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CIconDlg message handlers
  54.  
  55. BOOL CIconDlg::OnInitDialog()
  56. {
  57.    CDialog::OnInitDialog();
  58.    
  59.    // TODO: Add extra initialization here 
  60.    // CenterWindow();
  61.    
  62.    return TRUE;  // return TRUE  unless you set the focus to a control
  63. }
  64.  
  65. void CIconDlg::OnClickedButtonleft()
  66. {
  67.    // TODO: Add your control notification handler code here
  68.    UINT nIcon = GetDlgItemInt( IDC_ICON_NUMBER );
  69.    if ( nIcon )
  70.    nIcon--;
  71.    HICON hIcon = ExtractIcon( AfxGetInstanceHandle(), m_strIconFile, nIcon );
  72.    
  73.    if ( hIcon!=NULL && hIcon!=(HICON)1  )
  74.    {
  75.       m_Icon.SetIcon( hIcon );               
  76.       SetDlgItemInt( IDC_ICON_NUMBER, nIcon );
  77.    }
  78. }
  79.  
  80. void CIconDlg::OnClickedBrowse()
  81. {
  82.    // TODO: Add your control notification handler code here
  83.    XFileDialog dlg( "Select a file to load an icon from", TRUE, "*.exe;*.dll", 
  84.                 NULL, OFN_HIDEREADONLY, 
  85.                 "executables(*.exe)|*.exe|"
  86.                 "dynamic link libraries(*.dll)|*.dll|"
  87.                 "all files(*.*)|*.*||", this  );
  88.                    
  89.    if ( dlg.DoModal() == IDOK )
  90.    {
  91.       m_strIconFile = dlg.GetPathName();
  92.       
  93.       // try to get an icon
  94.       HICON hIcon = ExtractIcon( AfxGetInstanceHandle(), m_strIconFile, 0 );
  95.       
  96.       if ( hIcon==NULL || hIcon==(HICON)1 )
  97.       {
  98.          AfxMessageBox("There is no icon in this file");
  99.          m_Icon.SetIcon( AfxGetApp()->LoadIcon( IDI_NOAPPLICATION ) );
  100.       }
  101.       else
  102.       {         
  103.          m_Icon.SetIcon( hIcon );               
  104.       }   
  105.       SetDlgItemInt( IDC_ICON_NUMBER, 0 );
  106.       
  107.       UpdateData( FALSE );
  108.    }
  109. }
  110.  
  111. void CIconDlg::OnClickedButtonright()
  112. {
  113.    // TODO: Add your control notification handler code here
  114.    UINT nIcon = GetDlgItemInt( IDC_ICON_NUMBER );
  115.    nIcon++;
  116.    HICON hIcon = ExtractIcon( AfxGetInstanceHandle(), m_strIconFile, nIcon );
  117.    
  118.    if ( hIcon!=NULL && hIcon!=(HICON)1 )
  119.    {
  120.       m_Icon.SetIcon( hIcon );               
  121.       SetDlgItemInt( IDC_ICON_NUMBER, nIcon );
  122.    }
  123. }
  124.  
  125. void CIconDlg::OnOK()
  126. {
  127.    // TODO: Add extra validation here
  128.    m_nIcon = GetDlgItemInt( IDC_ICON_NUMBER );
  129.  
  130.    // make sure this is a vliad file/icon
  131.    HICON hIcon = ExtractIcon( AfxGetInstanceHandle(), m_strIconFile, m_nIcon );
  132.       
  133.    if ( hIcon==NULL || hIcon==(HICON)1 )
  134.    {
  135.       m_strIconFile="";
  136.       m_nIcon = 0;      
  137.    }
  138.       
  139.    CDialog::OnOK();
  140. }
  141.  
  142. void CIconDlg::OnClickedHelp()
  143. {
  144.    AfxMessageBox("You might select a file containing an icon with the browse button.\n"
  145.                  "From this file you are than able to select an icon with the < and > buttons");
  146.    
  147. }
  148.