Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Debug Error On
#Include "Win32API.inc"
%IDC_Graphic = 500
%IDC_Button = 501
Global hDlg,hConsole As Dword
Global GradientColors() As Long
Function PBMain() As Long
Dialog New Pixels, 0, "Gradient Fill Test",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Push", 10,10,100,20
Control Add Graphic, hDlg, %IDC_Graphic, "", 50,40,10,150
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local i As Long, temp$
Select Case Cb.Msg
Case %WM_InitDialog
CreateGradientColors (%Red,%Green)
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
If Cb.CtlMsg = %BN_Clicked Then
'Graphic Attach hDlg, %IDC_Graphic, Redraw
For i = 0 To UBound(GradientColors)
temp$ = temp$ + Str$(i) + Str$(GradientColors(i)) + $CrLf
Next i
? temp$
End If
End Select
End Select
End Function
Sub CreateGradientColors(clrTop As Long, clrBottom As Long)
Local hBMP,hDC As Dword, j As Long, gRect As Gradient_Rect
Dim V(1) As TriVertex
ReDim GradientColors(100) '0 to 100
'create memory bitmap on which to use GradientFill
Graphic Bitmap New 1,101 To hBMP 'w=1 h = 101 --> (0-100)
Graphic Attach hBMP, 0
Graphic Get DC To hDC
'use GradientFill API to put colors in the memory bitmap
V(0).x = 0
V(0).y = 0
V(0).Red = Mak(Word,0,GetRValue(clrTop))
V(0).Green = Mak(Word,0,GetGValue(clrTop))
V(0).Blue = Mak(Word,0,GetBValue(clrTop))
V(1).x = 1
V(1).y = UBound(GradientColors)
V(1).Red = Mak(Word,0,GetRValue(clrBottom))
V(1).Green = Mak(Word,0,GetGValue(clrBottom))
V(1).Blue = Mak(Word,0,GetBValue(clrBottom))
gRect.UpperLeft = 0
gRect.LowerRight = 1
GradientFill hDC, V(0), 2, gRect, 1, %Gradient_Fill_Rect_V
'put colors in GradientColors() array for later use in the app
For j = 0 To UBound(GradientColors)
Graphic Get Pixel (0,j) To GradientColors(j)
Next i
'remove memory bitmap
Graphic Bitmap End
End Sub
'gbs_00879
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm