Solved

Points for ptmcomp: Why setClassLong isn't working

Posted on 2000-05-06
1
464 Views
Last Modified: 2012-06-27
Hi, ptmComp. Please post the same answer you gave to my othe question and I'll give you the points.

In Delphi 5 I'm using setClassLong to replace the window class background brush but it's not working. I tried with a solid brush and a bitmap brush.

var
brushBackGround : HBrush;
bm:graphics.tbitmap;
begin
bm := graphics.TBitmap.create;
try
bm.loadFromFile('patron1.bmp');
// brushBackGround := createPatternBrush(bm.handle);
brushBackGround := createSolidBrush(clRed);
setClassLong(application.handle,GCL_HBrBackGround,brushBackGround);
try
Application.Initialize;
Application.CreateForm(TForm1, Form1); // form1 is an empty form
// setClassLong(form1.handle,GCL_HBrBackGround,brushBackGround); tried this, didn't work neither
Application.Run;
finally
deleteObject(brushBackGround);
end;
finally
bm.Free;
end;
end.

0
Comment
Question by:ms99
[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
1 Comment
 
LVL 10

Accepted Solution

by:
ptmcomp earned 25 total points
ID: 2785599
The problem is that Delphi overrides the WM_ERASEBKGND message handler.

procedure TWinControl.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
  { Only erase background if we're not doublebuffering or painting to memory. }
  if not FDoubleBuffered or
    (TMessage(Message).wParam = TMessage(Message).lParam) then
    FillRect(Message.DC, ClientRect, FBrush.Handle); // here Delpi uses FBrush.Handle instead of the window class brush
  Message.Result := 1; // message handled
end;

If you want to change to color of your window class, change the color property in the constructor.

But this works:

procedure TForm1.FormCreate(Sender: TObject);
begin
  Form1.Brush.Bitmap:= TBitmap.Create;
  Form1.Brush.Bitmap.LoadFromFile('c:\winnt\Santa Fe-Stuck.bmp');
end;

Regards, ptm.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month8 days, 9 hours left to enroll

615 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