Main Menu

CXpButton

Started by Paul Squires, June 15, 2018, 11:44:53 PM

Previous topic - Next topic

Paul Squires

Okay, I see what you've done... seems to work for as well. Only thing is that you don't get that visual depressed look when the button is pressed and then released.
Paul Squires
PlanetSquires Software

Paul Squires

As an aside: I was reading about theming and noticed that the control doesn't respond to WM_THEMECHANGED

        case WM_THEMECHANGED:
            if(pData->hTheme)
                CloseThemeData(pData->hTheme);
            pData->hTheme = OpenThemeData(hwnd, wszClass);
            InvalidateRect(hwnd, NULL, TRUE);
            return 0;

Paul Squires
PlanetSquires Software

José Roca

Quote from: Paul Squires on June 16, 2018, 06:41:02 PM
As an aside: I was reading about theming and noticed that the control doesn't respond to WM_THEMECHANGED

        case WM_THEMECHANGED:
            if(pData->hTheme)
                CloseThemeData(pData->hTheme);
            pData->hTheme = OpenThemeData(hwnd, wszClass);
            InvalidateRect(hwnd, NULL, TRUE);
            return 0;



It is not needed. I call OpenThemeData and CloseThemeData in UxDrawPushButton each time that the button is redrawn.

Paul Squires

Paul Squires
PlanetSquires Software

Paul Squires

Unfortunately, my studying for tonight now has to end as I have to go out for the night. :(

Good series of articles you've no doubt have already read  :)
https://www.codeproject.com/Articles/620045/Custom-Controls-in-Win-API-Visual-Styles

The guy who wrote them also maintains the mCtl project:
http://www.mctrl.org/
Paul Squires
PlanetSquires Software

José Roca

#20
Quote from: Paul Squires on June 16, 2018, 06:57:54 PM
Unfortunately, my studying for tonight now has to end as I have to go out for the night. :(

Good series of articles you've no doubt have already read  :)
https://www.codeproject.com/Articles/620045/Custom-Controls-in-Win-API-Visual-Styles

The guy who wrote them also maintains the mCtl project:
http://www.mctrl.org/


But this guy still has not learned how to write DPI aware controls :) The mCtl controls are unusable with High DPI settings.


José Roca

Quote from: Paul Squires on June 16, 2018, 06:39:32 PM
Okay, I see what you've done... seems to work for as well. Only thing is that you don't get that visual depressed look when the button is pressed and then released.

Well, I have modified the code again and we will only lose the depressed look when using custom colors.


   ' // Draws the button
   IF m_bIsThemed THEN
      ' // Increase 1 pixel to include the edge
      .InflateRect @rc, 1, 1
      ' // Draws the theme-specified border and fills for the "iPartId" and "iStateId".
      .DrawThemeBackground(hTheme, hDc, BP_PUSHBUTTON, iStateId, @rc, NULL)
      ' // Gets the size of the content for the theme-defined background
      .GetThemeBackgroundContentRect(hTheme, hDc, BP_PUSHBUTTON, iStateId, @rc, @rcContent)
   ELSE
      ' // Uses GDI to draw the button
      rcContent = rc
      IF bIsFocused THEN
         IF m_bIsToggle = FALSE OR bIsPressed = FALSE THEN
            .FrameRect hDc, @rcContent, GetSysColorBrush(COLOR_WINDOWTEXT)
         END IF
         .InflateRect @rcContent, -1, -1
      END IF
      IF m_bIsToggle THEN
         IF iStateId = PBS_PRESSED THEN
            .DrawEdge hDc, @rcContent, EDGE_SUNKEN, BF_RECT OR BF_MIDDLE OR BF_SOFT
         ELSE
            IF (lStyle AND BS_FLAT) = BS_FLAT THEN
               .DrawEdge hDc, @rcContent, EDGE_RAISED, BF_RECT OR BF_MIDDLE OR BF_SOFT OR BF_FLAT
            ELSE
               .DrawEdge hDc, @rcContent, EDGE_RAISED, BF_RECT OR BF_MIDDLE OR BF_SOFT
            END IF
         END IF
      ELSE
         IF m_hBkgBrush = NULL THEN .FillRect hDc, @rcContent, GetSysColorBrush(COLOR_BTNFACE)
         IF bIsPressed THEN
            .FrameRect hDc, @rcContent, GetSysColorBrush(COLOR_BTNSHADOW)
         ELSE
            uState = DFCS_BUTTONPUSH
            IF iStateId = PBS_HOT THEN uState = uState OR DFCS_HOT
            IF (lStyle AND BS_FLAT) = BS_FLAT THEN uState = uState OR DFCS_FLAT
            .DrawFrameControl hDc, @rcContent, DFC_BUTTON, uState
         END IF
      END IF
      IF m_hBkgBrush THEN.FillRect hDc, @rcContent, m_hBkgBrush
   END IF


I don't know what more I can do unless I get the source code of these API functions an rewrite them.

José Roca

#22
I have added support for text foreground and background colors. Also some minor changes, e.g. SetBkgColor changed to SetButtonBkColor.

I also have added SetTextForeDownColor and SetTextBkDownColor to set the colors used when the button is down (pressed or toggled). This is a workaround to provide a clear indication that the button is pressed or toggled.

If you don't need more changes, we can simply rename it as CXpButton.inc, as the original. This way I don't need to change all the documentation of this control.

Paul Squires

Thanks Jose, yes, rename this one as the original. I will use it in the designer and if I encounter any problems or suggestions for improvements then I will let you know. It seems like it has all of the properties I would need. Tomorrow, I will look at the button in Visual Studio 2017 to see how the fore/back color affects that button and themeing.

Thanks!
Paul Squires
PlanetSquires Software

José Roca

It is SetTextForeDownColor an appropriate name? What I want to mean is foreground color when the button is down (pressed).

Paul Squires

Maybe, "SetTextForeColorDown" or "SetTextForeColorPressed" ?

or even, "SetForeColorTextDown" or "SetForeColorTextPressed" ?
Paul Squires
PlanetSquires Software

José Roca

Changed names to SetTextForeColorDown and SetTextBkColorDown and renamed the include file as the original: CXpButton.inc.

Paul Squires

Hi Jose, I'm happy to report that I have been able to integrate the CXpButton into the visual designer as a replacement for the standard Windows button (so far, so good). I only really needed to add a call to subclass the control and an additional pointer in order to track the NEW/DELETE sequence for when I create and subsequently destroy the control. Working on integrating all of the CXpButton functionality into the PropertyList. Any issues/problems, I'll let you know. Thanks
Paul Squires
PlanetSquires Software

José Roca

Excellent. I always have wondered why one of the first questions that every novice asks is how to change the color of a button. The result can be awful if you choose colors using a theme and then the user chooses another theme. The user needs a gui that doesn't strain their eyes. I have seen things like red text against a light green background or dark blue text against a black background.

Marc Pons

José,
You probably have changed your Rar tool to new version, with my installed winrar 3.93 i was not able to uncompress your last attachments.


It would better stay on zip or previous version rar for more compatibiity when sharing

thanks for your tremendous job