Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi WM_NCCALCSIZE provozieren (Aufteilung NC - Client - Area hat sich geändert) (https://www.delphipraxis.net/152921-wm_nccalcsize-provozieren-aufteilung-nc-client-area-hat-sich-geaendert.html)

RSE 13. Jul 2010 07:44


WM_NCCALCSIZE provozieren (Aufteilung NC - Client - Area hat sich geändert)
 
Hallo,

ich habe ein eigenes Control, welches einen eingeschränkten Clientbereich hat. Das Ausmaß der Einschränkung ist vom Caption abhängig. Wenn sich das Caption ändert, muss ich also eine WM_NCCALCSIZE Message provozieren. Ich habe bisher folgenden Code:
Delphi-Quellcode:
    ...
    procedure SetHTMLCaptionHeight(const AValue: Integer); // löst alles aus

    procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
    procedure WMNCPaint(var Message: TWMNCPaint); message WM_NCPAINT;
    property HTMLCaptionHeight: Integer read FHTMLCaptionHeight write SetHTMLCaptionHeight;
    ...

procedure TCustomChoiceGroup.SetHTMLCaptionHeight(const AValue: Integer);
begin
  if FHTMLCaptionHeight = AValue then
    Exit;
  FHTMLCaptionHeight := AValue; // Höhe des neuen NC-Bereichs
  // hier Win über notwendiges Resize informieren... wie?
end;

procedure TCustomChoiceGroup.WMNCCalcSize(var Message: TWMNCCalcSize);
begin // das muss nach SetHTMLCaptionHeight aufgerufen werden
  with Message.CalcSize_Params^ do
    Inc(rgrc[0].Top,FHTMLCaptionHeight); // Einschränkung des ClientRect
  inherited;
end;

procedure TCustomChoiceGroup.WMNCPaint(var Message: TWMNCPaint);
var
  DC: HDC;
  c: TCanvas;
begin // TCustomChoiceGroup.Canvas ist nur für den Client-Bereich
  c := TCanvas.Create;
  try
    DC := GetWindowDC(Handle);
    try
      c.Handle := DC;
      c.Brush.Color := Color;
      c.FillRect(Rect(0,0,Width,FHTMLCaptionHeight));
      HTMLDraw(c,Rect(0,0,Width,FHTMLCaptionHeight),HTMLCaption,False);
    finally
      ReleaseDC(Handle, DC);
    end;
  finally
    c.free;
  end;
  Message.Result := 0;
end;

RSE 13. Jul 2010 12:14

AW: WM_NCCALCSIZE provozieren (Aufteilung NC - Client - Area hat sich geändert)
 
Ich habe die Lösung gefunden:
Delphi-Quellcode:
    procedure SetHTMLCaptionHeight(const AValue: Integer);
    procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
    procedure WMNCPaint(var Message: TWMNCPaint); message WM_NCPAINT;

procedure TCustomChoiceGroup.SetHTMLCaptionHeight(const AValue: Integer);
begin
  if HTMLCaptionHeight = AValue then
    Exit;
  FHTMLCaptionHeight := AValue;
  if not (csLoading in ComponentState) then // sonst ist Handle noch nicht gültig
    SetWindowPos(Handle,0,0,0,0,0, // das löst WM_NCCALCSIZE und WM_NCPAINT aus
                 SWP_FRAMECHANGED or SWP_NOCOPYBITS or SWP_NOMOVE or
                 SWP_NOOWNERZORDER or SWP_NOSENDCHANGING or SWP_NOSIZE or
                 SWP_NOZORDER);
end;

procedure TCustomChoiceGroup.WMNCCalcSize(var Message: TWMNCCalcSize);
begin
  Inc(Message.CalcSize_Params^.rgrc[0].Top,HTMLCaptionHeight);
  inherited;
end;

procedure TCustomChoiceGroup.WMNCPaint(var Message: TWMNCPaint);
var
  DC: HDC;
  c: TCanvas;
  r: TRect;
begin
  c := TCanvas.Create;
  try
    DC := GetWindowDC(Handle);
    try
      c.Handle := DC;
      c.Brush.Color := Color;
      r := c.ClipRect;
      r.Bottom := HTMLCaptionHeight;
      c.FillRect(r);
      HTMLDraw(c,r,HTMLCaption,False);
    finally
      ReleaseDC(Handle,DC);
    end;
  finally
    c.free;
  end;
  Message.Result := 0;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:25 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz