2010. október 4., hétfő

How to define the client area of a window


Problem/Question/Abstract:

Is it possible to define (set the size and position) of a window's client area (without resizing the window itself)? What I want to do is increase the non-client area to get more space to paint my own custom borders around a window. I want this to be reflected to the client area so that my border is protected from anything that goes on in the client area (painting, scrolling etc.).

Answer:

You have to handle the WM_NCCALCSIZE message on your form. See win32.hlp for details. The following example handler for a TListBox descendent excludes some space for a header bar from the listboxes client area:


procedure THeaderListbox.wmnccalcsize(var msg: TWMNCCALCSIZE);
begin
  inherited;
  if msg.CalcValidRects then
    with msg.CalcSize_Params^.rgrc[0] do
      top := top + Itemheight + 4;
end;


I hope you know how to define a message handler in the class declaration.

Nincsenek megjegyzések:

Megjegyzés küldése