Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » Standard WIndows controls background Collapse All
Subject Author Date
Sergio Buonanno Feb 21, 2006 - 6:06 AM

I have a class derived from CExtResizableDialog with Visual Studio 2005 Visual Style. If I use standard Windows controls the background of child controls is not painted correctly (solid color instead of the gradient used by Prof-UIS). Is there a solution to fix that problem ? I tried to handle OnCtlColor and return a NULL brush, but under Windows XP with an active theme the NULL brush causes checkboxes and radio buttons to be painted with a black background.

Technical Support Feb 22, 2006 - 3:22 AM

Pease use the corresponding Prof-UIS classes: CExtCheckBox for check boxes, CExtRadioButton for radio buttons, CExtGroupBox for group boxes, and CExtLabel for static text controls. Unlike those available in MFC, these classes are fully consistent with the Office 2003 andVS 2005 themes and include some additional features.

If you are using a group box along with other controls on a dialog template, make sure they are assigned the proper tab order. Since the Prof-UIS group box has a non-transparent background, the tab order is essential. Windows paints controls on the dialog step by step starting from the control with the highest tab order number to the control with the lowest number. So, ensure your group box is assigned the highest tab order number.

If you have many controls on your dialogs, that means to subsclass all the items may require considerable time. In this case, we can offer a ready-to-use solution that allows you to automatically subclass all the controls. Here is a SubclassAllControlsDynamically function that helps to subsclass all the controls on a dialog:

void SubclassAllControlsDynamically( HWND hWndDialogForm )
{
 
 if( hWndDialogForm == NULL )
  return;
 if( ! ::IsWindow( hWndDialogForm ) )
  return;
 HWND hWnd = ::GetWindow( hWndDialogForm, GW_CHILD );
 while( hWnd != NULL )
 {
  TCHAR szCompare[512] = _T("");
  ::GetClassName( 
   hWnd, 
   szCompare, 
   sizeof(szCompare)/sizeof(szCompare[0]) 
   );
 
  static const TCHAR szStatic[] = _T("STATIC");
  static const TCHAR szEdit[] = _T("EDIT");
  static const TCHAR szComboBox[] = _T("COMBOBOX");
  static const TCHAR szButton[] = _T("BUTTON");
 
  // STATIC
  if( ! _tcsicmp( szCompare, szStatic ) )
  {
   CWnd * pWnd = CWnd::FromHandlePermanent( hWnd );
   if( pWnd == NULL )
   {
    class TheDynamicLabel : public CExtLabel
    {
     void PostNcDestroy()
     {
      delete this;
     }
    };
    pWnd = new TheDynamicLabel;
    pWnd->SubclassWindow( hWnd );
   }
  }
  // EDIT
  else if( ! _tcsicmp( szCompare, szEdit ) )
  {
   CWnd * pWnd = CWnd::FromHandlePermanent( hWnd );
   if( pWnd == NULL )
   {
    class TheDynamicEdit : public CExtEdit
    {
     void PostNcDestroy()
     {
      delete this;
     }
    };
    pWnd = new TheDynamicEdit;
    pWnd->SubclassWindow( hWnd );
   }
  }
  // COMBOBOX
  else if( ! _tcsicmp( szCompare, szComboBox ) )
  {
   CWnd * pWnd = CWnd::FromHandlePermanent( hWnd );
   if( pWnd == NULL )
   {
    class TheDynamicComboBox : public CExtComboBox
    {
     void PostNcDestroy()
     {
      delete this;
     }
    };
    pWnd = new TheDynamicComboBox;
    pWnd->SubclassWindow( hWnd );
   }
  }
  // BUTTON
  else if( ! _tcsicmp( szCompare, szButton ) )
  {
   CWnd * pWnd = CWnd::FromHandlePermanent( hWnd );
   if( pWnd == NULL )
   {
    DWORD dwWndStyle = (DWORD)::GetWindowLong( hWnd, GWL_STYLE );
    DWORD dwWndType = (dwWndStyle & BS_TYPEMASK);
    if(  dwWndType == BS_PUSHBUTTON 
     || dwWndType == BS_DEFPUSHBUTTON
     )
    {
     class TheDynamicButton : public CExtButton
     {
      void PostNcDestroy()
      {
       delete this;
      }
     };
     pWnd = new TheDynamicButton;
     pWnd->SubclassWindow( hWnd );
    }
    else if( dwWndType == BS_AUTOCHECKBOX 
      || dwWndType == BS_CHECKBOX 
      || dwWndType == BS_AUTO3STATE 
      || dwWndType == BS_3STATE 
      )
    {
     class TheDynamicCheckBox : public CExtCheckBox
     {
      void PostNcDestroy()
      {
       delete this;
      }
     };
     pWnd = new TheDynamicCheckBox;
     pWnd->SubclassWindow( hWnd );
    }
    else if( dwWndType == BS_AUTORADIOBUTTON 
      || dwWndType == BS_RADIOBUTTON 
      )
    {
     class TheDynamicRadioButton : public CExtRadioButton
     {
      void PostNcDestroy()
      {
       delete this;
      }
     };
     pWnd = new TheDynamicRadioButton;
     pWnd->SubclassWindow( hWnd );
    }
    else if( dwWndType == BS_GROUPBOX )
    {
     class TheDynamicGroupBox : public CExtGroupBox
     {
      void PostNcDestroy()
      {
       delete this;
      }
     };
     pWnd = new TheDynamicGroupBox;
     pWnd->SubclassWindow( hWnd );
    }
   }
  }
  hWnd = ::GetWindow( hWnd, GW_HWNDNEXT );
 }
}