#Include "FiveWin.ch"
#include "Slider.ch"
STATIC oDlg
// ---------------------------
FUNCTION Main()
LOCAL oBmp, oSlider, nSlidPos, oCGet1, oCGet2, oCSay, nPickcolor, cPickcolor
LOCAL oFont, oPos, Pickvalues, cGrdCol, nPos, nGrdCol := 255 // RED
DEFINE FONT oFont NAME "Tahoma" SIZE 0, -16 BOLD
DEFINE DIALOG oDlg TITLE "Testing colorchange " + FWVERSION ;
FROM 1, 1 TO 430, 300 PIXEL
nPos := 0.5
cGrdCol := "nRGB( " + ALLTRIM(STR(nRGBRed( 255 ))) + ", " + ;
ALLTRIM(STR(nRGBGreen( 255 ))) + ", " + ;
ALLTRIM(STR(nRGBBlue( 255 ))) + " )"
@ 145, 45 SAY oCSay PROMPT " " OF oDlg SIZE 60, 12 PIXEL FONT oFont BORDER UPDATE
oCSay:SetColor( 0, nGrdCol )
@ 160, 45 GET oCGet1 VAR nGrdCol SIZE 60, 10 PICTURE "99999999" OF oDlg FONT oFont PIXEL UPDATE
@ 173, 45 GET oCGet2 VAR cGrdCol SIZE 85, 10 OF oDlg FONT oFont PIXEL UPDATE
@ 68, 95 SAY oPos PROMPT nPos OF oDlg SIZE 25, 12 PIXEL FONT oFont BORDER UPDATE
@ 15, 45 BITMAP oBmp FILENAME NIL SIZE 25, 115 OF oDlg ;
PIXEL ADJUST BORDER UPDATE
oBmp:bPainted := { |hDC| DRAW_BMP( hDC, oBmp, nGrdCol ) }
oBmp:bLClicked := { | nRow, nCol | nPos := nRow / 220, oPos:Refresh(), ;
oBmp:SaveToBmp( "Picker.bmp" ), ;
Pickvalues := PICK_COLOR( nRow, nCol, oBmp, nPos ), ;
nGrdCol := Pickvalues[1], ;
cGrdCol := Pickvalues[2], ;
oCSay:SetColor( 0, nGrdCol ), oCSay:Refresh(), ;
oCGet1:Refresh(), oCGet2:Refresh(), ;
oSlider:Set( nRow / 22 ), oSlider:Refresh() }
nSlidPos := 5
// MsgAlert( nSlidPos[1], "Slider-Row" ) , ; // 110 = 5 x 22
@ 10, 70 SLIDER oSlider VAR nSlidPos OF oDlg ;
VERTICAL ;
RANGE 0, 10 ;
COLORS CLR_RED, 12632256, CLR_CYAN ;
MARKS 20 ;
SIZE 18, 125 PIXEL UPDATE ;
ON CHANGE ( nPos := nSlidPos / 10, oPos:Refresh(), ;
oBmp:SaveToBmp( "Picker.bmp" ), ;
Pickvalues := PICK_COLOR( nSlidPos * 22, 8, oBmp, nPos ), ;
nGrdCol := Pickvalues[1], ;
cGrdCol := Pickvalues[2], ;
oCSay:SetColor( 0, nGrdCol ), oCSay:Refresh(), ;
oCGet1:Refresh(), oCGet2:Refresh() )
@ 195, 90 BTNBMP PROMPT "&EXIT" SIZE 50, 15 PIXEL 2007;
TOP ACTION oDlg:End()
ACTIVATE DIALOG oDlg CENTERED
oFont:End()
RETURN NIL
//------------- BMP-Brush -----------
FUNCTION DRAW_BMP( hDC, oBitmap, nColor )
LOCAL oBMPBrush, aGrad
LOCAL aRect := GETCLIENTRECT( oBitmap:hWnd )
aGrad := { { .5, CLR_WHITE, nColor }, { .5, nColor, CLR_BLACK } }
DEFINE BRUSH oBMPBrush ;
COLOR GradientFill( hDC, 0, 0, aRect[3], aRect[4], aGrad, .T. ) // .T: = Vertical
oBMPBrush:End()
RETURN( NIL )
//---------
FUNCTION PICK_COLOR( nRow, nCol, oBmp, nPos )
LOCAL hDC := CreateCompatibleDC( oBmp:GetDC() )
LOCAL hBmp, nColor, hOldBmp, aValues[4]
hBmp := ReadBitmap( 0, "Picker.Bmp" )
hOldBmp := SelectObject( hDC, hBmp )
aValues[1] := GetPixel( hDC, nCol, nRow )
IF nPos = 0
aValues[1] := 16777215 // white
ENDIF
IF nPos = 1
aValues[1] := 0 // black
ENDIF
SelectObject( hDC, hOldBmp )
DeleteObject( hBmp )
DeleteDC( hDC )
oBmp:ReleaseDC()
nRed := nRGBRed( aValues[1] )
nGreen := nRGBGreen(aValues[1] )
nBlue := nRGBBlue( aValues[1] )
aValues[2] := "nRGB( " + ALLTRIM(STR(nRed)) + ", " + ;
ALLTRIM(STR(nGreen)) + ", " + ;
ALLTRIM(STR(nBlue)) + " )"
//MsgAlert( nRow, "Img-Row" ) // 110 = 0.5
RETURN aValues