Solved

Partial alphablend.

Posted on 2006-06-18
4
781 Views
Last Modified: 2010-04-05
Hi

I have a problem with alphablend.
I'd like to set the alphablend value of the form very low (ex 50 or 30) but
i want the labels of the form to be visible (No alphablend)... Is that possible ?

Thanks in advance. :)
0
Comment
Question by:CodedK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Author Comment

by:CodedK
ID: 16929241
The form has no borders...
If it is easier i could put an image (image width and height = form width and height)
and set only the image to be transparent.
0
 
LVL 9

Assisted Solution

by:ginsonic
ginsonic earned 50 total points
ID: 16930226
Sorry to say but you can't set alphablending just for form. The settings will work for all vcls from form.
0
 
LVL 16

Author Comment

by:CodedK
ID: 16930654
Hi Ginsonic.

I know that. Maybe a trick could do the job. Something like capture a portion of what is behind
the form (window or desktop) and load it to the image.
There is a PAQ in EE database, but that solution doesnt work for me.
(It gives transparency to the form and not to the other vcls, but gives ugly results for images)
So i thing the image trick could work nice.

How can i capture what is behind the form ?
The event sshould be triggered when i drag the form.

Thanks in advance.
0
 
LVL 34

Accepted Solution

by:
Slick812 earned 200 total points
ID: 16936009
hello CodedK , As ginsonic  has already told you, the alpha blending is for the entire form and the child controls
are always set to it's parent alpha-blend. . .
I have never seen any way to change the alpha-blend for child controls, since the system would need to do to much work
 to have various different alpha blend values for hundreds of child controls.
 Here is some code that will create two separate TForms, each with a TLabel on them. Since these forms are
separate windows and not child windows, they will not have the alpha-blend of the alphs-blend form, however these
two forms will not stay at the same client position, so your code will have to dock them over top of the main form.

Here is the code for the Non-Alpha Form, which I call the FloatForm, be sure NOT to set any alpha-blend on this form,
  It has a single TLabel on it with the design time caption of 'Label1' -->



unit FloatForm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TFloatForm1 = class(TForm)
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure WMActivate(var Msg: TMessage); message WM_ACTIVATE;
    procedure WMMouseAct(var Msg: TMessage); message WM_MOUSEACTIVATE;
  protected
  { Protected declarations }
    procedure CreateParams(var Params: TCreateParams); override;
  public
    { Public declarations }
  end;

var
  FloatForm1: TFloatForm1;

implementation

uses BorderDock;

{$R *.DFM}

procedure TFloatForm1.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.WndParent := MainForm.Handle;
// The important thing here is to set new WndParent to forn that is docked to
end;

procedure TFloatForm1.WMActivate(var Msg: TMessage);
begin
// you need to prevent this form from getting focus
if (LOWORD(Msg.wParam) = WA_ACTIVE) or
   (LOWORD(Msg.wParam) = WA_CLICKACTIVE) then
  SetActiveWindow(MainForm.Handle)
  else inherited;
end;

procedure TFloatForm1.WMMouseAct(var Msg: TMessage);
begin
// you need to prevent this form from getting focus
Msg.Result := MA_NOACTIVATEANDEAT;
SetActiveWindow(MainForm.Handle);
end;

procedure TFloatForm1.FormCreate(Sender: TObject);
begin
borderStyle := bsNone;
Label1.Top := 0;
Label1.Left := 0; // these can be set in the object inspector

Width := Label1.Width;
Height := Label1.Height;
// If you change the Label1 then you will need to change this Form's Size to match
end;

end.


 = = = = = = = = = = = = = = = = = = = = = = = = = = = = =  =

Below is some code for the Main Form, which will have the Float Forms docked above it as labels.
  Please notice that all of the docking set up in in the OnShow event and NOT in the OnCreate event. -->




  TDock = Record
    Count, hWnd: Cardinal; // docked window Count and Handle for window
    OffLeft, OffTop: Integer; // offset of the float form position
    end;

  TMainForm = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);

  private
    { Private declarations }
    FirstShow: Boolean;
    aryDock: Array[0..2] of TDock; // set to amount of docked float forms, 3 in this case
    Float2: TFloatForm1; // second float form
    function doMoving(pRect: PRect): Boolean;
    procedure WMMoving(var Msg: TMessage); message WM_MOVING;


// = = = = = = =

procedure TMainForm.FormCreate(Sender: TObject);
begin
FirstShow := True;
end;



procedure TMainForm.FormShow(Sender: TObject);
var
fPnt: TPoint;
begin
if FirstShow then
  begin
  // this fills the aryDock and initializes the labels on the float forms
  FirstShow := False;
  aryDock[0].hWnd := Handle; // you MUST set the handle for each window docked
  // this first aryDock if for the main form and has zero OffSets
  aryDock[0].OffLeft := 0;
  aryDock[0].OffTop := 0;


  {FloatForm1 is the auto Created Float Form}

  FloatForm1.Label1.Caption := 'Non Alpha'; // change label
  FloatForm1.Label1.Color := clYellow;
  FloatForm1.Label1.Font.Size := 10;
  aryDock[1].hWnd := FloatForm1.Handle; // you MUST set the handle for each window docked
  fPnt.x := 8; // I want this docked form to be at client position 8, 6
  fPnt.y := 6;
  windows.ClientToScreen(Handle, fPnt); // get client position to screen position
  // You must set the Float Form initial Left and Top position
  // IMPORTANT , if you change the Label1, you MUST change the Form Size to match
  FloatForm1.SetBounds(fPnt.x, fPnt.y, FloatForm1.Label1.Width, FloatForm1.Label1.Height);
  // you will need to set the docking OffSets
  aryDock[1].OffLeft := fPnt.x-Left;
  aryDock[1].OffTop := fPnt.y-Top;


  Application.CreateForm(TFloatForm1, Float2);
  // Create a second Float Form here
  Float2.Label1.Caption := 'Read This Here';
  Float2.Label1.Color := clRed;
  Float2.Label1.Font.Size := 16;
  aryDock[2].hWnd := Float2.Handle;
  fPnt.x := 0; // I want this second docked form to be at client position 0, 32
  fPnt.y := 32;
  windows.ClientToScreen(Handle, fPnt);
  // IMPORTANT , if you change the label, you MUST change the Form Size to match
  Float2.SetBounds(fPnt.x, fPnt.y, Float2.Label1.Width, Float2.Label1.Height);
  aryDock[2].OffLeft := fPnt.x-Left;
  aryDock[2].OffTop := fPnt.y-Top;

  // Important - you must set the aryDock[0].Count to the number of windows docked
  aryDock[0].Count := 3;
  end;
end;


procedure TMainForm.WMMoving(var Msg: TMessage);
begin
if not doMoving(PRect(Msg.LParam)) then
  inherited;
// WARNING, if the windows are are docked do NOT call inherited
end;


function TMainForm.doMoving(pRect: PRect): Boolean;
var
hDwp1, i: Integer;
begin
{this function is called by the WM_MOVING message of MainForm.
 if the aryDock[0].Count is zero then the windows are NOT docked}
if MainForm.aryDock[0].Count <> 0 then
  begin
  hDwp1 := BeginDeferWindowPos(MainForm.aryDock[0].Count);
   { to move windows in the same "refresh" paint, you can use
   the BeginDeferWindowPos( ) function }
  for i := 0 to Pred(MainForm.aryDock[0].Count) do
    begin
  {the pRect comes from the WM_MOVING message, and has the new hForm1 position.
   You must call DeferWindowPos( ) for each window to be moved. Be sure to
   update the hDwp1 with the result of DeferWindowPos}
    with MainForm.aryDock[i] do
    hDwp1 := DeferWindowPos(hDwp1, hWnd, HWND_BOTTOM,
        pRect^.Left+OffLeft,
        pRect^.Top+OffTop, 1, 1,
        SWP_NOSIZE or SWP_NOZORDER or SWP_NOACTIVATE);
    end;
  EndDeferWindowPos(hDwp1);
  { when the EndDeferWindowPos( ) is called, the windows are supposed
    to be moved together , and repainted in the same cycle}
  Result := True;
  end else
  Result := False; // false if aryDock[0].Count is zero
{I use the result of this function in the WM_MOVING message, in order to have
 the EndDeferWindowPos function work correctly, you MUST BLOCK the WM_MOVING message}
end;


 = = = = = = = = = = = = = = = = = = = = = = = = = = =
this code seems to work for me, the 2 float forms look like TLables on the mainForm, but have no alpha blending
ask question if you need more information

 
 
as to the  --> " How can i capture what is behind the form ? "
one way is to "Hide" the form for for just long enough to bitBlt the screen, but this method of screen capture to bitmap and
form transparency is sometimes (all times) tricky to do, and may have many problems, in both getting the screen and showing tranparency, especially with other "Stay On Top" windows.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question