Filed Under Delphi
Custom Form Modules
posted by sysrpl on Thursday January 27, 2011 2:47 AM

f you're interested in programming, you may want to view the video below. In it I describe how you can use image files to produce creative Windows forms.

This is my first programming video. Hopefully more will follow :)

For the curious, this is how how you can create the effect in your own projects. Just pass this procedure your window, and a graphic object with a canvas. For the best effect, make sure your graphic refers to a 32bit image.

procedure UpdateAlphaWindow(Wnd: HWND; Image: TGraphic;
  Canvas: TCanvas; Opacity: Byte = $FF);
  Blend: TBlendFunction;
  Rect: TRect;
  P1, P2: TPoint;
  S: TSize;
  DC: HDC;
  if Image.Height = 0 then Exit;
  SetWindowLong(Wnd, GWL_EXSTYLE,
  GetWindowLong(Wnd, GWL_EXSTYLE) or WS_EX_LAYERED);
  GetWindowRect(Wnd, Rect);
  P1.X := Rect.Left;
  P1.Y := Rect.Top;
  with Blend do
    BlendOp := AC_SRC_OVER;
    BlendFlags := 0;
    SourceConstantAlpha := Opacity;
    AlphaFormat := AC_SRC_ALPHA;
  DC := GetDC(0);
  P2 := Point(0, 0); := Image.Width; := Image.Height;
  UpdateLayeredWindow(Wnd, DC, @P1, @S, Canvas.Handle,
    @P2, 0, @Blend, ULW_ALPHA);
  ReleaseDC(0, DC);