Date: 02-16-2022
Return to Index
created by gbSnippets
'Provides a dialog in which to adjust sliders to create a desired color
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
%IDC_RGB = 500
%IDC_Value = 501
%IDC_Color = 502
%IDC_R = 601
%IDC_G = 602
%IDC_B = 603
Global hDlg As Dword, C() As Long
Function PBMain() As Long
Local i As Long
Dialog New Pixels, 0, "RGB Color",300,300,200,130, %WS_SysMenu, 0 To hDlg
Dim C(%IDC_R To %IDC_B) As Long
Control Add Label, hDlg,%IDC_Color, "Color", 25,10,150,30, %WS_Border
Control Add Label, hDlg, %IDC_RGB, "R" + $CrLf +$CrLf + "G" + $CrLf + $CrLf + "B", 10,53,10,80
Control Add Label, hDlg, %IDC_Value, "" + $CrLf + $CrLf + "128 (12)", 140,53,60,80
For i = %IDC_R To %IDC_B
Control Add ScrollBar, hDlg, i,"", 25,45+(i-%IDC_R)*30,100,20
ScrollBar Set Range hDlg, i, 0, 264
Next i
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local i, sBarID, Delta As Long
Select Case Cb.Msg
Case %WM_InitDialog
C(%IDC_R) = 110 : C(%IDC_G) = 140 : C(%IDC_B) = 170
For i = %IDC_R To %IDC_B : ScrollBar Set Pos hDlg, i, C(i) : Next i
UpdateLabels
Case %WM_HScroll
sBarID = GetDlgCtrlID(Cb.LParam)
Select Case Lo(Word, Cb.WParam)
Case %SB_LineLeft : Delta = -1
Case %SB_LineRight : Delta = +1
Case %SB_PageLeft : Delta = -10
Case %SB_PageRight : Delta = +10
Case %SB_ThumbTrack : Delta = Hi(Word, Cb.WParam) - C(sBarID)
End Select
ScrollBar Get Pos hDlg, sBarID To C(sBarID)
ScrollBar Set Pos hDlg, sBarID, C(sBarID) + Delta
UpdateLabels
End Select
End Function
Sub UpdateLabels
Control Set Color hDlg, %IDC_Color, RGB(C(%IDC_R),c(%IDC_G),c(%IDC_B)),RGB(C(%IDC_R),c(%IDC_G),c(%IDC_B))
Control Set Text hDlg, %IDC_Value, _
Str$(C(%IDC_R)) + Space$(5) + Hex$(c(%IDC_R)) + $CrLf + $CrLf + _
Str$(C(%IDC_G)) + Space$(5) + Hex$(c(%IDC_G)) + $CrLf + $CrLf + _
Str$(C(%IDC_B)) + Space$(5) + Hex$(c(%IDC_B))
Control ReDraw hDlg, %IDC_Color
End Sub
'gbs_00869
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm