Solved

Points for ptmcomp: Why setClassLong isn't working

Posted on 2000-05-06
1
446 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
1 Comment
 
LVL 10

Accepted Solution

by:
ptmcomp earned 25 total points
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now