GradientFill/Custom form painting

Started by Richard Kelly, July 15, 2011, 12:04:04 AM

Previous topic - Next topic

Richard Kelly

I'm having a challenge just figuring out how to take a form, do some custom painting including gradientfill api and then sticking some controls on the area (not the whole form) where I've done the gradient fill. Any general how-to steps from our local guru's?

Rick Kelly

Richard Kelly

I've tried this in the custom function for the form. It does paint the gradient. If I place, say a label control, on the form with the transparency property set, it doesn't blend in with the gradient. I've tried using invalidaterect without success. Any ideas and is this the best approach?


Function GRADIENTFILLMAINFORM_CUSTOM ( _
                                     hWndForm      As Dword, _  ' handle of Form
                                     wMsg          As Long,  _  ' type of message
                                     wParam        As Dword, _  ' first message parameter
                                     lParam        As Long   _  ' second message parameter
                                     ) As Long
                                     
Local hDC            As Dword
Local rc             As Rect
Dim gRect(0)         As GRADIENT_RECT
Dim vert(1)          As TRIVERTEX

   Select Case wMsg
   
      Case %WM_ERASEBKGND

         PostMessage (hWndForm,%WM_USER + 100, 0 , 0)
         
      Case %WM_USER + 100

         hDC = GetDC (hWndForm)
         GetClientRect (hWndForm,rc)
         
         vert(0).x      = 0
         vert(0).y      = 0
         vert(0).Red    = &HFFFF
         vert(0).Green  = &HFFFF
         vert(0).Blue   = &HFFFF
         vert(0).Alpha  = &H0000

         vert(1).x      = rc.nRight
         vert(1).y      = rc.nBottom 
         vert(1).Red    = &H0000
         vert(1).Green  = &H0000
         vert(1).Blue   = &H0000
         vert(1).Alpha  = &H0000
         
         gRect(0).UpperLeft  = 0
         gRect(0).LowerRight = 1

         GradientFill hDC, vert(0), 2, gRect(0), 1, %GRADIENT_FILL_RECT_V
   
   End Select   

End Function

Robert Eaton

I believe that the transparent property simply causes the control to inherit the background color of the parent form. It's not truly transparent. (Try placing two label controls on top of each other.) To create a "label", you might have draw the text directly on the form.

Paul Squires

I haven't run your code, but try the following at the end of %WM_ERASEBKGND:

FUNCTION = %TRUE
EXIT FUNCTION

Instead of %WM_USER + 100, I would just handle all of the painting in WM_PAINT (including writing text to represent a "Label").


Paul Squires
PlanetSquires Software

Richard Kelly

It's a bit of a hack but this code works. I had to turn off the clipping properties for the main form. Thoughts?


Function GRADIENTFILLMAINFORM_WM_CREATE ( _
                                        hWndForm As Dword, _      ' handle of Form
                                        ByVal UserData As Long _  ' optional user defined Long value
                                        ) As Long

Local ff As FLY_DATA Ptr


   ff = GetProp (HWND_GRADIENTFILLMAINFORM_LABEL1, "FLY_PTR")
   @ff.hBackBrush = GetStockObject (%NULL_BRUSH)
   SetProp HWND_GRADIENTFILLMAINFORM_LABEL1, "FLY_PTR", ff
   SetBkMode GetDC(HWND_GRADIENTFILLMAINFORM_LABEL1), %TRANSPARENT
   
End Function



'--------------------------------------------------------------------------------
Function GRADIENTFILLMAINFORM_CUSTOM ( _
                                     hWndForm      As Dword, _  ' handle of Form
                                     wMsg          As Long,  _  ' type of message
                                     wParam        As Dword, _  ' first message parameter
                                     lParam        As Long   _  ' second message parameter
                                     ) As Long
                                     
Local hDC            As Dword
Local rc             As Rect
Dim gRect            As GRADIENT_RECT
Dim vert(1)          As TRIVERTEX

   Select Case wMsg
   
      Case %WM_ERASEBKGND

         hDC = GetDC (hWndForm)
         GetClientRect (hWndForm,rc)
         
         vert(0).x      = 0
         vert(0).y      = 0
         vert(0).Red    = &HFF00
         vert(0).Green  = &HFF00
         vert(0).Blue   = &HFF00
         vert(0).Alpha  = &H0000

         vert(1).x      = rc.nRight
         vert(1).y      = rc.nBottom 
         vert(1).Red    = &H0000
         vert(1).Green  = &H0000
         vert(1).Blue   = &H0000
         vert(1).Alpha  = &H0000
         
         
         gRect.UpperLeft  = 0
         gRect.LowerRight = 1

         GradientFill hDC, vert(0), 2, gRect, 1, %GRADIENT_FILL_RECT_V
         


         Function = %TRUE
         Exit Function
   
   End Select   

End Function


Rick