1 Attachment(s)
Gradient window background is not working properly
Hi all,
I am trying to implement a gradient background color in tWindow class. Here is the the function for it.
Code:
Function tWindow.SetGradientBackColor(Byval c1 As Long, Byval c2 As Long)
Me.mGradientBkGnd = true
Me.mIsBkChanged = True
Me.mGradiClrOne = c1 '// This is Long
Me.mGradiClrTwo = c2 '// This is also Long
if me.mIsCreated Then Win_InvalidateRect(Me.mHandle, 0, true)
End function
And the user can call this function like this.
Code:
win.SetGradientBackColor(0xFFCCCC, 0x6656FF)
When the user calls this function, we will end up in WM_ERASEBKGND message. And in that message, I tried this function.
Code:
Function tWindow.CreateGreadientBrush(Byval hDc As Dword)
Dim tc1 As tRgb(me.mGradiClrOne) '// tRgb is my UDT. I will show the elements.
Dim tc2 As tRgb(me.mGradiClrTwo)
Dim rct As RECT
Win_getclientrect(me.mHandle, rct)
Dim gBrush As Dword = 0
Dim memHdc As Dword = Win_CreateCompatibleDC(hDc)
Dim hBmp As Dword = Win_CreateCompatibleBitmap(hDc, rct.nRight, rct.nBottom)
Dim loopEnd As Long = rct.nBottom
Win_SelectObject(memHdc, hBmp)
For i as Long = 0 to loopEnd - 1
Dim tRct As Rect
Dim red as Long
Dim green As Long
Dim blue As Long
red = tc1.Red + (i * ((tc2.Red - tc1.Red) / loopEnd))
green = tc1.Green + ( i * (( tc2.Green - tc1.Green) / loopEnd))
blue = tc1.Blue + ( i * ((tc2.Blue - tc1.Blue) / loopEnd))
gBrush = CreateSolidBrush(Rgb(red, green, blue))
tRct.nLeft = 0
tRct.nTop = i
tRct.nRight = rct.nRight - rct.nLeft
tRct.nBottom = i + 1
Win_fillrect(memHdc, tRct, gBrush)
Win_deleteobject(gBrush)
Next
Dim Pattern As Dword = Win_CreatePatternBrush(hBmp)
Win_deletedc(memHdc)
Win_deleteobject(gBrush)
Win_deleteobject(hBmp)
Win_fillrect(hDc, rct, Pattern)
Win_deleteobject(Pattern)
End Function
This is tRgb UDT.
Code:
Type tRgb
Red As Long
Green As Long
Blue As Long
Function _Create(iVal As Long)
Me.Red = iVal >> 16
Me.Green = (Andb(iVal, 65280)) >> 8
Me.Blue = Andb(iVal, 255)
End function
Function PrintRgb()
Printl(Me.Red, ", ", Me.Green, ", ", Me.Blue)
End function
End Type
And the end result is attached here. Please check and guide me.