Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to draw in form's glass header area?

Status
Not open for further replies.

djjd47130

Programmer
Nov 1, 2010
480
0
0
US
I've been trying to figure out how to do custom drawing, or otherwise placing controls within the glass header area of a standard VCL form with a border. I'm trying to make a form look similar to these:

IETabs.png

FireFoxTabs.png

ExplorerTitle.png

ChromeTabs.png


I know that Delphi 2010 has the glass panels, but A) I'm using Delphi 7, and B) How to override the original glass title bar, without altering the close/max/min buttons?

JD Solutions
 
I don't know much about the window effects and styles available only to Vista and Seven. This might be part of what you'll run into in trying to do this.

But I do know you can get a fair number of those in XP. The main part of it after finding the right functions to call (what is below took 5 minutes), is making it so the VCL functions don't have a fit.

Code:
{ code sample.  Should render the entire form using alpha blending.  The third parm of SetLayeredWindowAttributes controls the degree which the alpha blending is done (0-255).  Play with this parm and the second parm (which controls which color is transparent) in order to see what effects you can get }

function SetLayeredWindowAttributes(hwnd: THandle; crKey: COLORREF;
   bAlpha: Byte; dwFlags: DWord): Bool; stdcall; external 'user32.dll';

procedure TForm1.Button1Click(Sender: TObject);
const
  WS_EX_LAYERED = $00080000;
  LWA_ALPHA = 2;
var
  CurrHandle: THandle;
begin
  CurrHandle := GetWindowLong(Handle, GWL_EXSTYLE);
  SetWindowLong(Handle, GWL_EXSTYLE, CurrHandle or WS_EX_LAYERED);
  SetLayeredWindowAttributes(Handle, RGB(255, 255, 255), 225, LWA_ALPHA);
end;

Looking into UpdateLayeredWindow should be profitable as well if you are looking for effects that exist only in portions of the form.

As for drawing things in the non-client area, it's quite possible. Here's an example to try.


As I keep saying, you can really accomplish anything with any 32-bit Delphi. The problem is finding the right functions to call and being able to deal with any impediments that VCL presents.

To that end, I'm thinking it's almost more beneficial in the end to learn API, given the amount of control it offers, and in not having to wait to upgrade Delphi to get certain things. I'm hoping to begin in earnest doing that in the near future once my current project is over.

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top