Disable and Enable MFC controls by name

Contents

    I use this snippet all the time to disable/enable, hide/show, move MFC controls.

    // Enables and disables an MFC control by name void CCILikeChease::EnableControl( int iControl, bool enable ) { // Enable Control      CWnd* wnd_control = (CWnd*)( GetDlgItem( iControl ) );      if( wnd_control != NULL ) {           wnd_control->EnableWindow( enable ) ;      } } void CNetworkDlg::HideControl( int iControl, bool show ) {      // Hide the Control      CWnd* wnd_control = (CWnd*)( GetDlgItem( iControl ) );      if( wnd_control != NULL ) {           if( show ) {                wnd_control->ShowWindow( SW_SHOW ) ;           } else {                wnd_control->ShowWindow( SW_HIDE ) ;           }      } } void CNetworkDlg::MoveControl( int iControl, int top, int left, int sizex, int sizey ) {      // Move the control      CWnd* wnd_control = (CWnd*)( GetDlgItem( iControl ) );      if( wnd_control != NULL ) {           LPRECT lpRect = new RECT ;           wnd_control->GetClientRect( lpRect ) ;           lpRect->top = top;           lpRect->left = left;           if( sizex > 0 || sizey > 0 ) {                lpRect->right = sizex + left ;                lpRect->bottom = sizey + top;           }           wnd_control->MoveWindow( lpRect ) ;           delete lpRect ;      } }