From 0fd65273d4726cf746d6cc40e1fae53abb1a24d0 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Thu, 15 Aug 2019 09:48:55 +0000 Subject: [PATCH] mbColorLib: Eliminate effect of ScreenWin on result of TmbDeskPickerButton (based on code by forum user "d-_-b", https://forum.lazarus.freepascal.org/index.php/topic,46415.0.html) git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7130 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/mbColorLib/ScreenWin.pas | 45 +++++++++++++++++++---------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/components/mbColorLib/ScreenWin.pas b/components/mbColorLib/ScreenWin.pas index a6f421a05..09858c19b 100644 --- a/components/mbColorLib/ScreenWin.pas +++ b/components/mbColorLib/ScreenWin.pas @@ -29,6 +29,8 @@ type private FOnSelColorChange: TNotifyEvent; FOnKeyDown: TKeyEvent; + function GetDesktopColor(const X, Y: Integer): TColor; + function ReadScreenColor(const X, Y: Integer): TColor; protected procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW; @@ -51,21 +53,6 @@ implementation uses HTMLColors; -function GetDesktopColor(const X, Y: Integer): TColor; -var - c: TCanvas; - screenDC: HDC; -begin - c := TCanvas.Create; - try - screenDC := GetDC(0); - c.Handle := screenDC; - Result := c.Pixels[X, Y]; - finally - c.Free; - end; -end; - { TScreenForm } @@ -139,4 +126,32 @@ begin Top := 0; end; +function TScreenForm.GetDesktopColor(const X, Y: Integer): TColor; +var + savedAlphaBlendValue: Integer; +begin + savedAlphaBlendValue := AlphablendValue; + try + AlphaBlendValue := 0; + Result := ReadScreenColor(X, Y); + finally + AlphaBlendValue := savedAlphaBlendValue; + end; +end; + +function TScreenForm.ReadScreenColor(const X, Y: Integer): TColor; +var + c: TCanvas; + screenDC: HDC; +begin + c := TCanvas.Create; + try + screenDC := GetDC(0); + c.Handle := screenDC; + Result := c.Pixels[X, Y]; + finally + c.Free; + end; +end; + end.