#include <functional> #include <algorithm> using std::bind1st; using std::binary_function; using std::for_each; template <bool bEnable> struct EnableWnd : public binary_function<CWnd *, int, int> { public: int operator()(CWnd *pWnd, int nChildWndID) const { CWnd *pChildWnd = pWnd->GetDlgItem(nChildWndID); if (pChildWnd) { pChildWnd->EnableWindow(bEnable); } return 0; } }; int nIDArray[] = { IDOK, IDCANCEL, }; int main() { // this, at here is a CWnd for_each(nIDArray, nIDArray + ItemCount(nIDArray), bind1st(EnableWnd<false>(), this)); }