260 lines
		
	
	
		
			6.6 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			260 lines
		
	
	
		
			6.6 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
// ex02dlg.cpp : implementation file
 | 
						|
//
 | 
						|
 | 
						|
#include "ex02std.h"
 | 
						|
#include "ex02mfc.h"
 | 
						|
#include "ex02dlg.h"
 | 
						|
#include "wildcard.h"
 | 
						|
#include "stdio.h"
 | 
						|
 | 
						|
#ifdef _DEBUG
 | 
						|
#define new DEBUG_NEW
 | 
						|
#undef THIS_FILE
 | 
						|
static char THIS_FILE[] = __FILE__;
 | 
						|
#endif
 | 
						|
 | 
						|
/////////////////////////////////////////////////////////////////////////////
 | 
						|
// CAboutDlg dialog used for App About
 | 
						|
 | 
						|
class CAboutDlg : public CDialog
 | 
						|
{
 | 
						|
public:
 | 
						|
	CAboutDlg();
 | 
						|
 | 
						|
// Dialog Data
 | 
						|
	//{{AFX_DATA(CAboutDlg)
 | 
						|
	enum { IDD = IDD_ABOUTBOX };
 | 
						|
	//}}AFX_DATA
 | 
						|
 | 
						|
	// ClassWizard generated virtual function overrides
 | 
						|
	//{{AFX_VIRTUAL(CAboutDlg)
 | 
						|
	protected:
 | 
						|
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
 | 
						|
	//}}AFX_VIRTUAL
 | 
						|
 | 
						|
// Implementation
 | 
						|
protected:
 | 
						|
	//{{AFX_MSG(CAboutDlg)
 | 
						|
	virtual BOOL OnInitDialog();
 | 
						|
	//}}AFX_MSG
 | 
						|
	DECLARE_MESSAGE_MAP()
 | 
						|
};
 | 
						|
 | 
						|
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
 | 
						|
{
 | 
						|
	//{{AFX_DATA_INIT(CAboutDlg)
 | 
						|
	//}}AFX_DATA_INIT
 | 
						|
}
 | 
						|
 | 
						|
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
 | 
						|
{
 | 
						|
	CDialog::DoDataExchange(pDX);
 | 
						|
	//{{AFX_DATA_MAP(CAboutDlg)
 | 
						|
	//}}AFX_DATA_MAP
 | 
						|
}
 | 
						|
 | 
						|
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
 | 
						|
	//{{AFX_MSG_MAP(CAboutDlg)
 | 
						|
	//}}AFX_MSG_MAP
 | 
						|
END_MESSAGE_MAP()
 | 
						|
 | 
						|
/////////////////////////////////////////////////////////////////////////////
 | 
						|
// CEx02mfcDlg dialog
 | 
						|
 | 
						|
CEx02mfcDlg::CEx02mfcDlg(CWnd* pParent /*=NULL*/)
 | 
						|
	: CDialog(CEx02mfcDlg::IDD, pParent)
 | 
						|
{
 | 
						|
	//{{AFX_DATA_INIT(CEx02mfcDlg)
 | 
						|
	//}}AFX_DATA_INIT
 | 
						|
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
 | 
						|
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
 | 
						|
}
 | 
						|
 | 
						|
void CEx02mfcDlg::DoDataExchange(CDataExchange* pDX)
 | 
						|
{
 | 
						|
	CDialog::DoDataExchange(pDX);
 | 
						|
	//{{AFX_DATA_MAP(CEx02mfcDlg)
 | 
						|
	//}}AFX_DATA_MAP
 | 
						|
}
 | 
						|
 | 
						|
BEGIN_MESSAGE_MAP(CEx02mfcDlg, CDialog)
 | 
						|
	//{{AFX_MSG_MAP(CEx02mfcDlg)
 | 
						|
	ON_WM_SYSCOMMAND()
 | 
						|
	ON_WM_PAINT()
 | 
						|
	ON_WM_QUERYDRAGICON()
 | 
						|
	ON_BN_CLICKED(IDC_EXIT, OnExit)
 | 
						|
	ON_BN_CLICKED(IDC_EXPAND, OnExpand)
 | 
						|
	ON_BN_CLICKED(IDC_ABOUT, OnAbout)
 | 
						|
	//}}AFX_MSG_MAP
 | 
						|
END_MESSAGE_MAP()
 | 
						|
 | 
						|
/////////////////////////////////////////////////////////////////////////////
 | 
						|
// CEx02mfcDlg message handlers
 | 
						|
 | 
						|
BOOL CEx02mfcDlg::OnInitDialog()
 | 
						|
{
 | 
						|
	CDialog::OnInitDialog();
 | 
						|
 | 
						|
	// Add "About..." menu item to system menu.
 | 
						|
 | 
						|
	// IDM_ABOUTBOX must be in the system command range.
 | 
						|
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
 | 
						|
	ASSERT(IDM_ABOUTBOX < 0xF000);
 | 
						|
 | 
						|
	CMenu* pSysMenu = GetSystemMenu(FALSE);
 | 
						|
	CString strAboutMenu;
 | 
						|
	strAboutMenu.LoadString(IDS_ABOUTBOX);
 | 
						|
	if (!strAboutMenu.IsEmpty())
 | 
						|
	{
 | 
						|
		pSysMenu->AppendMenu(MF_SEPARATOR);
 | 
						|
		pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
 | 
						|
	}
 | 
						|
	// Set the icon for this dialog.  The framework does this automatically
 | 
						|
	//  when the application's main window is not a dialog
 | 
						|
	SetIcon(m_hIcon, TRUE);			// Set big icon
 | 
						|
	SetIcon(m_hIcon, FALSE);		// Set small icon
 | 
						|
	
 | 
						|
	// TODO: Add extra initialization here
 | 
						|
    for ( int i = 0 ; i < 10 ; i++ ) {
 | 
						|
        char buffer[ 40 ];
 | 
						|
        sprintf( buffer, "Temp file %d.tmp", i );
 | 
						|
        FILE *f = fopen( buffer, "wb" );
 | 
						|
        fclose( f );
 | 
						|
    }
 | 
						|
    CEdit *edit = (CEdit *) GetDlgItem( IDC_EDIT1 );
 | 
						|
    if ( edit )
 | 
						|
        edit->SetWindowText( "Temp File ?.*" );
 | 
						|
	CAboutDlg dlgAbout;
 | 
						|
	dlgAbout.DoModal();
 | 
						|
    
 | 
						|
	return TRUE;  // return TRUE  unless you set the focus to a control
 | 
						|
}
 | 
						|
 | 
						|
void CEx02mfcDlg::OnSysCommand(UINT nID, LPARAM lParam)
 | 
						|
{
 | 
						|
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
 | 
						|
	{
 | 
						|
		CAboutDlg dlgAbout;
 | 
						|
		dlgAbout.DoModal();
 | 
						|
	}
 | 
						|
	else
 | 
						|
	{
 | 
						|
		CDialog::OnSysCommand(nID, lParam);
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
// If you add a minimize button to your dialog, you will need the code below
 | 
						|
//  to draw the icon.  For MFC applications using the document/view model,
 | 
						|
//  this is automatically done for you by the framework.
 | 
						|
 | 
						|
void CEx02mfcDlg::OnPaint() 
 | 
						|
{
 | 
						|
	if (IsIconic())
 | 
						|
	{
 | 
						|
		CPaintDC dc(this); // device context for painting
 | 
						|
 | 
						|
		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
 | 
						|
 | 
						|
		// Center icon in client rectangle
 | 
						|
		int cxIcon = GetSystemMetrics(SM_CXICON);
 | 
						|
		int cyIcon = GetSystemMetrics(SM_CYICON);
 | 
						|
		CRect rect;
 | 
						|
		GetClientRect(&rect);
 | 
						|
		int x = (rect.Width() - cxIcon + 1) / 2;
 | 
						|
		int y = (rect.Height() - cyIcon + 1) / 2;
 | 
						|
 | 
						|
		// Draw the icon
 | 
						|
		dc.DrawIcon(x, y, m_hIcon);
 | 
						|
	}
 | 
						|
	else
 | 
						|
	{
 | 
						|
		CDialog::OnPaint();
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
// The system calls this to obtain the cursor to display while the user drags
 | 
						|
//  the minimized window.
 | 
						|
HCURSOR CEx02mfcDlg::OnQueryDragIcon()
 | 
						|
{
 | 
						|
	return (HCURSOR) m_hIcon;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
void CEx02mfcDlg::OnExit() 
 | 
						|
{
 | 
						|
	// TODO: Add your control notification handler code here
 | 
						|
    PostMessage( WM_QUIT, 0, 0 );
 | 
						|
}
 | 
						|
 | 
						|
void CEx02mfcDlg::OnExpand() 
 | 
						|
{
 | 
						|
	// TODO: Add your control notification handler code here
 | 
						|
    CListBox *lb = (CListBox *) GetDlgItem( IDC_LIST1 );
 | 
						|
    CEdit *edit = (CEdit *) GetDlgItem( IDC_EDIT1 );
 | 
						|
    CButton *check = (CButton *) GetDlgItem( IDC_CHECK1 );
 | 
						|
    if ( lb && edit && check ) {
 | 
						|
        lb->ResetContent();
 | 
						|
        CString s;
 | 
						|
        edit->GetWindowText( s );
 | 
						|
        ALWildCardExpander *ex;
 | 
						|
        if  ( check->GetCheck() )
 | 
						|
            ex = new ALWildCardExpander( s );
 | 
						|
        else
 | 
						|
            ex = new ALWildCardExpander( s, "" );
 | 
						|
        char *p;
 | 
						|
        p = ex->GetNextFile();
 | 
						|
        if ( p ) {
 | 
						|
            do {
 | 
						|
                lb->AddString( p );
 | 
						|
                p = ex->GetNextFile();
 | 
						|
            } while (p);
 | 
						|
        } else
 | 
						|
            lb->AddString( "<No files>" );
 | 
						|
        delete ex;
 | 
						|
    }
 | 
						|
    
 | 
						|
}
 | 
						|
 | 
						|
BOOL CEx02mfcDlg::DestroyWindow() 
 | 
						|
{
 | 
						|
	// TODO: Add your specialized code here and/or call the base class
 | 
						|
    for ( int i = 0 ; i < 10 ; i++ ) {
 | 
						|
        char buffer[ 40 ];
 | 
						|
        sprintf( buffer, "Temp file %d.tmp", i );
 | 
						|
        unlink( buffer );
 | 
						|
    }
 | 
						|
	
 | 
						|
	return CDialog::DestroyWindow();
 | 
						|
}
 | 
						|
 | 
						|
void CEx02mfcDlg::OnAbout() 
 | 
						|
{
 | 
						|
	// TODO: Add your control notification handler code here
 | 
						|
	CAboutDlg dlgAbout;
 | 
						|
	dlgAbout.DoModal();
 | 
						|
}
 | 
						|
 | 
						|
char *about = 
 | 
						|
"This program demonstrates the use of the wild card "
 | 
						|
"expander delimiters argument.  I create a batch of "
 | 
						|
"files with embedded spaces in the name. Performing "
 | 
						|
"a normal wild card search on these files doesn't work, "
 | 
						|
"because the space in the wildcard spec is interpreted "
 | 
						|
"as a delimiter.  Calling the routine with an empty "
 | 
						|
"string in the delimiter argument means the space char "
 | 
						|
"will be treated as just a normal character, and will be "
 | 
						|
"used to expand the wild card filespec";
 | 
						|
 | 
						|
BOOL CAboutDlg::OnInitDialog() 
 | 
						|
{
 | 
						|
	CDialog::OnInitDialog();
 | 
						|
	
 | 
						|
	// TODO: Add extra initialization here
 | 
						|
	CEdit *edit = (CEdit *) GetDlgItem( IDC_EDIT1 );
 | 
						|
    if ( edit )
 | 
						|
        edit->SetWindowText( about );
 | 
						|
	
 | 
						|
	return TRUE;  // return TRUE unless you set the focus to a control
 | 
						|
	              // EXCEPTION: OCX Property Pages should return FALSE
 | 
						|
}
 |