• Welcome to PlanetSquires Forums.
 

CXpButton

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

Previous topic - Next topic

José Roca

Same file in .zip format.

Paul Squires

Also, don't forget that you can always get Jose's latest files from: https://github.com/JoseRoca/WinFBX
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

Should the CXpButton's TextMargin and ImageMargin be adjusted based on DPI setting? It says that the incoming value should be specified as a pixel number (the default is 4 pixels). Should that value be upscaled when the control is drawn?   pWindow->ScaleX(m_TextMargin)
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

Well, when I wrote it, DPI did not still existed... and I had not realized this detail when I did the translation. Maybe we can modify the control to scale this value and also m_ImageWidth, m_ImageHeight and m_ImageMargin.

Paul Squires

Thanks Jose, yes, I think the control should do the transformation of the ImageMargin and TextMargin values during the drawing routine. (not sure about the image scaling.. maybe let the user do that one in case they manually specify images based on dpi settings. Wouldn't want a 64px image to be scaled even bigger automatically).
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

Then we will scale only the margins.

José Roca

Changed it to scale the margins.

Paul Squires

Thanks Jose, I will integrate this new version into the visual designer.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

Hi Jose, I am working on the various properties of the CXpButton. It would seem to me that it would be easier to work with the control if the various items were implemented as Properties rather than functions. There are various functions to set colors for the background and various text states but no functions to retrieve those values. If implemented as properties then the it would eliminate the need to have a corresponding Get function.

eg.

Using Function approach:
SetButtonBkColor
GetButtonBkColor (this function does not exist)

Using Property approach:
ButtonBkColor( byval nValue as COLORREF )
ButtonBkColor () as COLORREF

Is it too late in this control's life to make such a large change? If it is too late, then maybe you could simply add the missing Get functions for the sake of completeness?

Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

#39
Now you have both functions and properties:


      ' // Properties
      DECLARE PROPERTY Font () AS HFONT
      DECLARE PROPERTY Font (BYVAL hFont AS HFONT)
      DECLARE PROPERTY TextFormat () AS DWORD
      DECLARE PROPERTY TextFormat (BYVAL dwTextFlags AS DWORD)
      DECLARE PROPERTY Cursor () AS HCURSOR
      DECLARE PROPERTY Cursor (BYVAL hCursor AS HCURSOR)
      DECLARE PROPERTY Toggle (BYVAL fToggle AS LONG)
      DECLARE PROPERTY Toggle () AS LONG
      DECLARE PROPERTY ToggleState () AS LONG
      DECLARE PROPERTY ToggleState (BYVAL fState AS LONG)
      DECLARE PROPERTY ImageWidth () AS LONG
      DECLARE PROPERTY ImageWidth (BYVAL nWidth AS LONG)
      DECLARE PROPERTY ImageHeight () AS LONG
      DECLARE PROPERTY ImageHeight (BYVAL nHeight AS LONG)
      DECLARE PROPERTY ImagePos () AS LONG
      DECLARE PROPERTY ImagePos (BYVAL nPos AS LONG)
      DECLARE PROPERTY ImageMargin () AS LONG
      DECLARE PROPERTY ImageMargin (BYVAL nMargin AS LONG)
      DECLARE PROPERTY ButtonState () AS LONG
      DECLARE PROPERTY ImageType () AS LONG
      DECLARE PROPERTY ButtonBkColor () AS COLORREF
      DECLARE PROPERTY ButtonBkColor (BYVAL bkColor AS COLORREF)
      DECLARE PROPERTY TextForeColor () AS COLORREF
      DECLARE PROPERTY TextForeColor (BYVAL textColor AS COLORREF)
      DECLARE PROPERTY TextBkColor () AS COLORREF
      DECLARE PROPERTY TextBkColor (BYVAL textColor AS COLORREF)
      DECLARE PROPERTY TextForeColorDown () AS COLORREF
      DECLARE PROPERTY TextForeColorDown (BYVAL textColor AS COLORREF)
      DECLARE PROPERTY TextBkColorDown () AS COLORREF
      DECLARE PROPERTY TextBkColorDown (BYVAL textColor AS COLORREF)
      DECLARE PROPERTY NormalImageHandle () AS HANDLE
      DECLARE PROPERTY HotImageHandle () AS HANDLE
      DECLARE PROPERTY DisabledImageHandle () AS HANDLE
      DECLARE PROPERTY BkBrush () AS HBRUSH


Functions have the advantage of the additional fRedraw parameter. Using properties on the fly, you may need to call the Redraw method separately.

Paul Squires

Thanks Jose! Great job as always :)
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

Here's another one.... 

Would be nice if CXpButton handled the WM_SETFONT message. I know that I can set it via the Font property but being able to WM_SETFONT to the control is easier based on the code I am using. WM_SETCURSOR is handled, but not WM_SETFONT.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

This should work:


      CASE WM_SETFONT
         ' // Sets the font that a control is to use when drawing text.
         pButton = CAST(CXpButton PTR, .GetWindowLongPtrW(hwnd, 0))
         IF pButton THEN
            pButton->SetFont(CAST(.HFONT, wParam), lParam)
            EXIT FUNCTION
         END IF


Paul Squires

Thanks Jose, yes it seems to be working perfectly so far.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

Hi Jose,

Maybe add code for the button to handle an incoming BM_CLICK message? I am sending the BM_CLICK message to the button designated as the default button when the ENTER key or ESC keys are pressed. This works perfectly for regular push buttons of course, but fails with the CXPButton button because it doesn't handle the BM_CLICK message.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer