// QFRestore ¯68,1® #include "common.ch" #include "Gra.ch" #include "Xbp.ch" #include "Appevent.ch" #include "Font.ch" #include "dll.ch" Class ColorPicker From XbpStatic Exported: Method Create Method Destroy Method ChooseTheColor Var oShow Var oBmp Var nColor Var lCaptured Var hDC Var bColorPick EndClass Method ColorPicker:Create(oParent,oOwner,aPos) Local aSize := {312,60}, oDa //** configure the parent ::XbpStatic:Type := XBPSTATIC_TYPE_RAISEDRECT ::XbpStatic:ClipSiblings := .T. //** create and store the parent ::XbpStatic:Create(oParent,oOwner,aPos,aSize) //** create the bitmap object ::oBmp := XbpStatic():new( ::XbpStatic, , {8,8}, {253,43}) ::oBmp:Caption := 201 ::oBmp:ClipSiblings := .T. ::oBmp:type := XBPSTATIC_TYPE_BITMAP ::oBmp:create() ::oBmp:lbClick := {|aPos| ::ChooseTheColor(aPos,self) } //** now do the color shower thingie ::oShow := XbpStatic():new( ::XbpStatic, , {268,12}, {36,36} ) ::oShow:clipSiblings := .T. ::oShow:options := XBPSTATIC_TEXT_VCENTER+XBPSTATIC_TEXT_RIGHT ::oShow:create() Default ::nColor to GraMakeRGBColor({0,0,0}) ::oShow:SetColorBG(::nColor) ::lCaptured := .F. ::hDC := GetDC(::oBmp:GethWnd()) Return Self Method ColorPicker:Destroy() ::oShow:Destroy() ::oBmp:Destroy() ::XbpStatic:Destroy() ::nColor := nil ::lCaptured := nil ::hDC := nil ::bColorPick := nil Return Self Method ColorPicker:ChooseTheColor(aPos,aColor) Local nColor If !Empty(aPos) //** invert the pos to normal coords aPos[2] := ::oBmp:CurrentSize()[2] - aPos[2] nColor := GetPixel(::hDC,aPos[1],aPos[2]) nColor := ClrWin2Xb(nColor) Else nColor := GraMakeRGBColor(aColor) EndIf ::oShow:SetColorBG(nColor) ::nColor := nColor If !Empty(::bColorPick) .and. !Empty(aPos) Eval(::bColorPick,::nColor) EndIf Return self DllFunction GetPixel(hdc,x,y) Using STDCALL From GDI32.DLL DllFunction GetDC(hwnd) Using STDCALL From USER32.DLL