Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#7

AW: WMNCHitTest ist tot seit Vcl.Styles benutzt wird

  Alt 21. Nov 2019, 10:25
Da ich nicht genau weiß, wegen copyright von style "Jet", lade ich nicht das project hoch sondern zeige hier nur den code.

Vielen Dank an Frühlingsrolle, Du hast mir den Weg gezeigt wie man es lösen könnte!

Delphi-Quellcode:
program Project1;

{$IFNDEF MSWindows}
  {$MESSAGE ERROR 'This application is made for Windows only!'}
{$ENDIF MSWindows}

uses
  Vcl.Forms,
  Unit1 in 'Unit1.pas{Form1},
  Vcl.Themes,
  Vcl.Styles;

{$R *.res}

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  TStyleManager.TrySetStyle('Jet');
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
Delphi-Quellcode:
unit Unit1;

{$IFNDEF MSWindows}
  {$MESSAGE ERROR 'This unit is made for Windows only!'}
{$ENDIF MSWindows}

interface

uses
  Winapi.Windows, Winapi.Messages, System.Classes,
  Vcl.Forms, Vcl.Controls, Vcl.StdCtrls, Vcl.ExtCtrls;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    CheckBox1: TCheckBox;
    procedure CheckBox1Click(Sender: TObject);
  private
    procedure WMNCHitTest(var Msg: TWMNCHitTest) ; message WM_NCHitTest;
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.WMNCHitTest(var Msg: TWMNCHitTest);
begin
  inherited;
  Self.Caption := 'WMNCHitTest aktiv!'; // diese Zeile dient nur zum Beweis ob man sich in dieser prozedur befindet.
  Panel1.Visible := False; // dies kann man testen indem man die Zeile "TStyleManager.TrySetStyle('Jet');" aus der Project1.dpr auskommentiert.
  if ((ControlAtPos(ScreenToClient(Msg.Pos), True, True, True) = nil) and (Msg.Result = htClient))
    then
      Msg.Result := htCaption;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  if (Sender as TCheckBox).Checked
    then
      Self.OnMouseDown := FormMouseDown
    else
      Self.OnMouseDown := nil;
  Panel1.SetFocus; // damit die CheckBox-Caption-Umrahmung verschwindet wenn man Vcl.Style aktiviert hat.
end;

// fix von Zarko Gajic mit Verbesserung von Frühlingsrolle
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
// SendMessage(Self.Handle, WM_SYSCOMMAND, SC_MOVE or HTCAPTION, 0); // original von Herrn Gajic
// (Sender as TControl).Perform(WM_SYSCOMMAND, SC_MOVE or HTCAPTION, 0); // original von Frühlingsrolle
  Self.Perform(WM_SYSCOMMAND, SC_MOVE or HTCAPTION, 0); // so würde ich es nun nutzen, da ein TControl.Perform wahrscheinlich die komponente anstelle des formulars verschiebt.
// SetCapture(Self.Handle); // ich bin mir nicht sicher ob man es setzen sollte/muss...?
end;

end.
Thema für mich erfolgreich abgeschlossen, Danke allen!
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat