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 ;
}
}
steven wrote:
click here
http://www.abluestar.com/img/
Posted on 26-Dec-07 at 7:47 pm | Permalink
Aleph Ersatz wrote:
You mean “Cheese” right?
Nifty snippet, I’ll have to keep that in mind for later.
Posted on 01-Jan-08 at 1:30 am | Permalink
Steven Smethurst wrote:
Yep,
I have come up with many different scenarios where my lack of English skills could cause my death.
Posted on 02-Jan-08 at 4:59 pm | Permalink