Author: Jonas Bilinkevicius
I have a good reason why I cannot use forms. So as an alternative I'm using two
panels to mimic a simple form, i.e. with no windows icons (close, minimize etc.).
One is aligned to the top to pose like the window title bar and the other to
client. I want to paint the top panel like a typical title bar. How can I do this?
Answer:
There is an API function named DrawCaption, you can use it to draw the caption bar.
Drop a client-aligned TPaintbox on your fake caption panel and do the drawing in
the paintboxes OnPaint handler.
1 2 procedure TPLabBaseChildform.CaptionPaint(Sender: TObject);
3 const4 activeFlags: array[Boolean] of DWORD = (0, DC_ACTIVE);
5 begin6 with Sender as TPaintbox do7 DrawCaption(self.handle, canvas.handle, clientrect, activeFlags[FActive] or8 DC_TEXT or DC_GRADIENT);
9 end;
To draw other elements as well (beside the icon, which DrawCaption can handle) you use DrawFrameControl instead.