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 Tech Support » No icons for check/radio boxes? Collapse All
Subject Author Date
Robert Webb Jun 25, 2009 - 7:35 PM

Our old code sometimes used an icon instead of a text label beside check and radio boxes.  This was a simple matter of calling SetIcon() on the standard MFC CButton controls.


However in Prof-UIS, if I use the CExtCheckBox or CExtRadioButton classes and call SetIcon(), no icon appears.  I just get a check/radio box with nothing next to it.  If I use CExtButton instead then the icon appears on the button.  Why isn’t this MFC-compatible for check and radio buttons too?  How can I get the icon to appear?


Thanks,


Rob.

Technical Support Jun 30, 2009 - 6:37 AM

We added this improvement into the CExtLabel source code.

Technical Support Jun 26, 2009 - 1:09 PM

You can use the CExtButton class for subclassing check boxes and radio buttons. Such check boxes look like classic push buttons which are pressed in the checked state. The CExtButton::m_icon property is public so you can assign any icon you need to it. The CExtCmdIcon class allows you to specify several images for different icon states. That’s why we do not support the classic MFC icon assignment to the button control.

Robert Webb Jun 28, 2009 - 6:44 PM

Well, for a start CExtButton can not behave like a radio button as far as I know, but more importantly the whole point is that I do not wish my check and radio boxes to appear like normal push buttons.  If I did, I would have used normal push buttons, obviously.  So I don’t follow your logic at all for not supporting this basic MFC capability.  In MFC it’s a simple matter to have a check box or radio box with an icon beside it.  Surely it is reasonable to expect the same from Prof-UIS.  If an icon has been set, why not use it?


Thanks,


Rob.

Robert Webb Jun 28, 2009 - 8:11 PM

I’ve managed to half work-around this limitation of Prof-UIS by making the check/radio box smaller and creating a CExtLabel to fill the remaining space.  The CExtLabel shows the icon required beside the check/radio box.


This works quite well except when the check/radio box needs to be greyed out.  I am calling EnableWindow(false) for the label, but the icon just stays looking the same.  In MFC, when a check/radio box has an icon and the control is disabled, the icon becomes greyed out.  How can I make that happen in Prof-UIS for the CExtLabel control?  Why doesn’t it happen automatically?


Thanks,


Rob.

Technical Support Jun 29, 2009 - 1:31 PM

Please take a look at the CExtLabel::OnPaint() method. If you are using rectangular shape labels and or SS_BITMAP() labels, then the CExtLabel::OnPaint() invokes the default painting code of the static common control. If you are using the SS_ICON() labels, text labels or labels displaying extended bitmap which is assigned with the CExtLabel::SetBitmapEx() method, then the CExtLabel::DoPaint() virtual method does all the painting work. The SS_ICON() labels and extended bitmap labels are always painted with enabled like looking. The disabled labels are typically un-recognizable and meaning less. But you can change this label’s behavior. For instance, the following part of the CExtLabel::DoPaint() virtual method draws the SS_ICON() labels:

      else if( dwWndType == SS_ICON )
      {
            HICON hIcon = GetIcon();
            if( hIcon != NULL )
            {
                  CExtCmdIcon _icon;
                  _icon.AssignFromHICON( hIcon, true );
                  CSize szIcon = _icon.GetSize();
                  int nOffsetX = bCenterImage ? (rcClient.Width() - szIcon.cx) / 2 : 0;
                  int nOffsetY = bCenterImage ? (rcClient.Height() - szIcon.cy) / 2 : 0;
                  _icon.Paint( PmBridge_GetPM(), dc.GetSafeHdc(), rcClient.left + nOffsetX, rcClient.top + nOffsetY, -1, -1 );
            }
      }
You can override the CExtLabel::DoPaint() virtual method and use the modified version of the code snipped above for painting disabled icons:
      if( dwWndType == SS_ICON )
      {
            HICON hIcon = GetIcon();
            if( hIcon != NULL )
            {
                  CExtCmdIcon _icon;
                  _icon.AssignFromHICON( hIcon, true );
                  CSize szIcon = _icon.GetSize();
                  int nOffsetX = bCenterImage ? (rcClient.Width() - szIcon.cx) / 2 : 0;
                  int nOffsetY = bCenterImage ? (rcClient.Height() - szIcon.cy) / 2 : 0;
                  _icon.Paint(
                        PmBridge_GetPM(), dc.GetSafeHdc(), rcClient.left + nOffsetX, rcClient.top + nOffsetY, -1, -1,
                        IsWindowEnabled() ? CExtCmdIcon::__PAINT_NORMAL : CExtCmdIcon::__PAINT_DISABLED
                        );
            }
      }



Robert Webb Jun 30, 2009 - 12:51 AM

Thanks, this worked.  It does feel like bad practice though to copy large chunks of code from the base class just to change one line in the derived version.


I don’t understand why you don’t just include the change you give above directly in the CExtLabel code.  Saying that "The disabled labels are typically un-recognizable and meaning less" isn’t a good excuse.  The user won’t often disable a label.  If they do, then surely greying it out is exactly what they intended.


Rob.