Date: 02-16-2022
Return to Index
created by gbSnippets
'PowerBASIC has a built-in DDT command to access the Windows color selection dialog
'Primary Code:
'Syntax: DISPLAY COLOR [hParent], [xpos], [ypos], firstcolor, custcolors, flags TO color&
Display Color hDlg, 100, 100, LastSelectedColor&, CustomColorList ,Flags& To ColorResult&
'Flag Options:
%CC_FULLOPEN 'Display entire dialog (including custom colors)
%CC_PREVENTFULLOPEN 'Disables custom color section
%CC_SHOWHELP 'Displays Help button (hParent parameter must not _
'be zero or %HWND_DESKTOP)
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
Type CustomColors
c(15) As Long
End Type
Global CustomColorList as CustomColors 'stores 16 user-defined colors
Global hDlg As DWord
Function PBMain() As Long
Dialog New Pixels, 0, "Test",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
'... test code goes here
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
'test code
GetColor
End If
End Function
Sub GetColor
Static LastSelectedColor&
Local ColorResult&, Flags&
Flags& = 0 'enables button to define customized colors, but does not force it open
Display Color hDlg, 100, 100, LastSelectedColor&, CustomColorList ,Flags& To ColorResult&
If ColorResult& = -1 Then
MsgBox "No color selected!" 'ColorResult$ is set to "" if Cancel/Escape is pressed
Else
LastSelectedColor& = ColorResult& 'used SelectedColor& as firstcolor the next time the dialog is displayed
MsgBox Str$(ColorResult&)
End If
End Sub
'gbs_00116
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm