"Donovan J. Edye" wrote:
> 
> G'Day,
> 
> Has someone got some code or a pointer to how I could create a drop shadow
> similair to the one you receive when you get context sensitive help?

The following code should do what you want.

Martin

//==============================================================================
// This procedure is used to create the region shape used by windows
when
// painting the form on the screen. It combines a lot of one pixel wide
// square regions into two checkerboard patters, and adds these to a
square
// region that is smaller than the window size. This give the effect of
a shadow
// around the window if the form is coloured correctly in the paint
procedure.
//------------------------------------------------------------------------------

procedure TForm1.setRegion;
var
  R: hRgn;
  I, J: Integer;
  bShadow, // width x 6 bottom shadow region piece
  sShadow: hRgn; // 6x height side shadow region piece
begin
  // if need be bump up width & height so our side shadows do not
overlap..
  if not odd(clientWidth) then
    width := width + 1;
  if odd(clientHeight) then
    height := height + 1;
  // create and populate the bottom shadow
  bShadow := CreateRectRgn(0, 0, 0, 0);
  for I := 0 to clientWidth - 12 do
    for J := 0 to 6 do
      if odd(I + J) then
      begin
        R := CreateRectRgn(I, J, I + 1, J + 1);
        CombineRgn(bShadow, bShadow, R, RGN_OR);
        DeleteObject(R);
      end;
  OffsetRgn(bShadow, 6, Height - 6);
  // create and populate side shadow
  sShadow := CreateRectRgn(0, 0, 0, 0);
  for I := 0 to clientHeight - 6 do
    for J := 0 to 6 do
      if not odd(I + J) then
      begin
        R := CreateRectRgn(J, I, J + 1, I + 1);
        CombineRgn(sShadow, sShadow, R, RGN_OR);
        DeleteObject(R);
      end;
  OffsetRgn(sShadow, Width - 6, 6);
  // create main region.
  R := CreateRectRgn(0, 0, clientWidth - 6, clientHeight - 6);
  // add shadows
  CombineRgn(R, bShadow, R, RGN_OR);
  DeleteObject(bShadow);
  CombineRgn(R, sShadow, R, RGN_OR);
  DeleteObject(sShadow);
  // set region to window
  SetWindowRgn(Handle, R, False);
end;

//==============================================================================
// This procedure is called everytime the form is painted. It simply
paints a
// black box around the window and then pads out the bottom and right
hand edges
// with a thick black border. These borders are under the 'shadow'
regions
// of the window.
//------------------------------------------------------------------------------

procedure TForm1.FormPaint(Sender: TObject);
var
  R: TRect;
begin
  Canvas.Brush.Color := clBlack;
  R.Left := clientRect.left;
  R.Right := ClientRect.right - 6;
  R.Top := clientRect.Top;
  R.Bottom := clientRect.Bottom - 6;
  Canvas.FrameRect(R);
  // draw the bottom shadow
  R.Left := clientRect.left;
  R.Right := ClientRect.right;
  R.Top := clientRect.Bottom - 6;
  R.Bottom := clientRect.Bottom;
  Canvas.FillRect(R);
  // draw the side shadow
  R.Left := ClientRect.Right - 6;
  R.Right := ClientRect.Right;
  R.Top := ClientRect.Top;
  R.Bottom := ClientRect.Bottom;
  Canvas.FillRect(R);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  setRegion;
end;
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to