|
// STL_with_MFCDlg.h : header file
//
#if !defined(AFX_STL_WITH_MFCDLG_H__506BF7FC_CB1D_45DB_8396_0326B89F3CB4__INCLUDED_)
#define AFX_STL_WITH_MFCDLG_H__506BF7FC_CB1D_45DB_8396_0326B89F3CB4__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <algorithm>
#include <functional>
#include <vector>
#include "DemoDlg.h"
// a function object to delete a pointer
// from a for_each algorithm
struct DeletePtr
{
template<typename T>
void operator()(const T* ptr) const { delete ptr; }
};
// a function object to close a CWnd
// from a for_each algorithm
struct CloseWnd
{
void operator()(CWnd* wnd) const { wnd->PostMessage(WM_CLOSE); }
};
// an enum for modes
enum findmodes
{
FM_INVALID = 0,
FM_IS,
FM_STARTSWITH,
FM_ENDSWITH,
FM_CONTAINS
};
// a typedef to pass to our predicate
typedef struct tagFindDlg
{
UINT iMode;
CString szWindowTitle;
} FindDlg;
typedef FindDlg* LPFIND_DIALOG;
// declare a function object to use as a
// predicate for remove_if(). This predicate
// will close and delete a CDialog* if window
// titles match by the specified mode.
class CloseAndDeleteByTitle :
public std::unary_function<CDialog, bool>
{
public:
CloseAndDeleteByTitle(const LPFIND_DIALOG lpFDD) : m_lpFDD(lpFDD) {}
bool operator()(CDialog* w) const
{
bool retVal = false;
CString szWndTitle = "";
w->GetWindowText(szWndTitle);
switch(m_lpFDD->iMode)
{
case FM_IS:
{
retVal = (szWndTitle == m_lpFDD->szWindowTitle);
break;
}
case FM_STARTSWITH:
{
retVal = (szWndTitle.Left(m_lpFDD->szWindowTitle.GetLength()) ==
m_lpFDD->szWindowTitle);
break;
}
case FM_ENDSWITH:
{
retVal = (szWndTitle.Right(m_lpFDD->szWindowTitle.GetLength()) ==
m_lpFDD->szWindowTitle);
break;
}
case FM_CONTAINS:
{
retVal = (szWndTitle.Find(m_lpFDD->szWindowTitle) != -1);
break;
}
}
if(retVal)
{
w->PostMessage(WM_CLOSE);
delete w;
}
return retVal;
}
private:
LPFIND_DIALOG m_lpFDD;
};
/////////////////////////////////////////////////////////////////////////////
// CSTL_with_MFCDlg dialog
class CSTL_with_MFCDlg : public CDialog
{
// Construction
public:
CSTL_with_MFCDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CSTL_with_MFCDlg)
enum { IDD = IDD_STL_WITH_MFC_DIALOG };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSTL_with_MFCDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
std::vector<CDemoDlg*> m_vpDemoDialogs;
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CSTL_with_MFCDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnCreateDemoDlg();
afx_msg void OnRemoveAllDemoDialogs();
afx_msg void OnClose();
afx_msg void OnRemoveDemoDlg();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STL_WITH_MFCDLG_H__506BF7FC_CB1D_45DB_8396_0326B89F3CB4__INCLUDED_)
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.