2007. február 5., hétfő

Disable the transparent part of a TSpeedButton from clicking


Problem/Question/Abstract:

How to disable the transparent part of a TSpeedButton from clicking

Answer:

procedure TMFSpeedButton.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y:
  Integer);
var
  ScreenDC: HDC;
  Transp, Bits: Boolean;
begin
  inherited MouseDown(Button, Shift, X, Y);
  if (Button = mbLeft) and Enabled then
  begin
    Bits := False;
    Transp := False;
    ScreenDC := GetDC(0);
    try
      {Transparent color is color of form background. Test for True Color 24bit
                  or  more, because on lower color depth the color is blended, so it works only
                        on true color for some colors. If it is for example clBlack, it works
                        on everything}
      Bits := GetDeviceCaps(ScreenDC, BITSPIXEL) >= 24;
      {test for desired color}
      Transp := GetPixel(ScreenDC, Mouse.CursorPos.x, Mouse.CursorPos.Y) = $0094ADBD;
    finally
      ReleaseDC(0, ScreenDC);
    end;
    {leave procedure if test for transp. color was successful}
    if Transp and Bits then
      Exit;
    if not FDown then
    begin
      FState := bsDown;
      Invalidate;
    end;
    FDragging := True;
  end;
end;

Nincsenek megjegyzések:

Megjegyzés küldése