Disable and Enable MFC controls by name

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 ;
     }
}

Comments (3) left to “Disable and Enable MFC controls by name”

  1. steven wrote:

    click here

    http://www.abluestar.com/img/

  2. Aleph Ersatz wrote:

    You mean “Cheese” right?

    Nifty snippet, I’ll have to keep that in mind for later.

  3. Steven Smethurst wrote:

    Yep,
    I have come up with many different scenarios where my lack of English skills could cause my death.

Post a Comment

*Required
*Required (Never published)