Main Menu

CXpButton

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

Previous topic - Next topic

José Roca

#45
I have added:


      CASE BM_CLICK
         .SendMessageW hwnd, WM_LBUTTONDOWN, 0, 0
         .SendMessageW hwnd, WM_LBUTTONUP, 0, 0
         EXIT FUNCTION


Not tested yet, but it should work.

Paul Squires

I doubt that will work because LBUTTONDOWN and LBUTTONUP do hit testing based on the cursor position to determine if the user has clicked the button. When I get home this evening I will work up some code and post it here for you to include in the button class.

Thanks, Paul
Paul Squires
PlanetSquires Software

José Roca

You're right. I had no time for testing it. Let's see if this works:


      CASE BM_CLICK
         IF .IsWindowEnabled(hwnd) = FALSE THEN EXIT FUNCTION
         ' // Redraws the button in pushed state
         pButton = CAST(CXpButton PTR, .GetWindowLongPtrW(hwnd, 0))
         IF pButton = NULL THEN EXIT FUNCTION
         IF pButton->m_bIsToggle THEN
            IF pButton->m_bToggled = FALSE THEN
               pButton->m_bToggled = TRUE
            ELSE
               pButton->m_bToggled = FALSE
            END IF
         END IF
         pButton->m_fState = BST_PUSHED
         pButton->Redraw
         ' // Redraws the button in unpushed state
         pButton->m_fState = 0
         pButton->Redraw
         ' // Set the focus in the button
         .SetFocus hwnd
         ' // Forwards the message to the parent window
         .SendMessageW .GetParent(hwnd), WM_COMMAND, MAKELONG(GetDlgCtrlId(hwnd), BN_CLICKED), CAST(.LPARAM, hwnd)
         EXIT FUNCTION


Paul Squires

Thanks Jose! I tested it and it seems to be working okay so far  :-)

Paul Squires
PlanetSquires Software

José Roca

Hi Paul,

I have added the ButtonBkColorDown properties to change the background color of the button when it is pressed or toggled.

Paul Squires

#50
Hi José,

Thanks for the new code. I added a new Button property called "BackColorDown". Seems to be working okay.
Paul Squires
PlanetSquires Software

Paul Squires

Hi José,

The CXpButton could use two functions similar to the ones that you have for the CImageCtx control. Currently, I have to use the GetWindowLongPtr calls directly during my WM_DESTROY to get the CXpButton pointers. For convenience and consistency it would be nice to have AfxCXpButtonPtr like the AfxCImageCtxPtr functions below.


' ========================================================================================
' Returns a pointer to the class given the handle of its associated window handle.
' hCtl = Handle of the image control.
' ========================================================================================
PRIVATE FUNCTION AfxCImageCtxPtr OVERLOAD (BYVAL hCtl AS HWND) AS CImageCtx PTR
   FUNCTION = CAST(CImageCtx PTR, .GetWindowLongPtrW(hCtl, 0))
END FUNCTION
' ========================================================================================
' ========================================================================================
' hParent = Handle of the parent window of the image control.
' cID = Identifier of the image control.
' ========================================================================================
PRIVATE FUNCTION AfxCImageCtxPtr OVERLOAD (BYVAL hParent AS HWND, BYVAL cID AS LONG) AS CImageCtx PTR
   FUNCTION = CAST(CImageCtx PTR, .GetWindowLongPtrW(GetDlgItem(hParent, cID), 0))
END FUNCTION
' ========================================================================================

Paul Squires
PlanetSquires Software

José Roca

Done.

José Roca

I smile when I remember that I thought of deprecate it, and only adapted it to practice how to implement a custom control using a class :)

Paul Squires

Excellent - thanks :-) 

That button is one of the main controls in the WinFBE visual designer code output. It is very versatile.
Paul Squires
PlanetSquires Software

Paul Squires

Hi José,

I had to make a very change to the CTmageCtx.DrawImage function. I had to move the test for the pImage pointer being null down to the block where the image is actually outputted. It now looks like this:

   IF ( pGraphics ) andalso ( pImage )THEN

This enables me to draw the background normal or HOT regardless of whether an image is actually specified.

I have attached the new CImageCtx control code.

Paul Squires
PlanetSquires Software