Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Position von Dialog (https://www.delphipraxis.net/109244-position-von-dialog.html)

SaFu 26. Feb 2008 22:42


Position von Dialog
 
Hi

und zwar hatte ich gestern ne Frage wie man die Messagedialogs in der Mitte meiner Form aufgehen lässt.

Jetzt ist mir aufgefallen das ich die ganzen Dialogs (Open-, Picture-, Printdialog usw) auch in der Mitte aufgehen lassen muss gibt es da auch eine möglichkeit die Position zu bestimmen

Gruß Sascha

stahli 27. Feb 2008 15:54

Re: Position von Dialog
 
Eine "Idee von Pascal Enz" zu den "richtigen" Dialogen findest Du hier

Zur mittigen Positionierung habe ich es so abgewandelt:
Delphi-Quellcode:
// OldProcfuerOpendialog1: Dword globale Variable
//Idee von Pascal Enz
function DialogProc(Handle: HWND; Msg: DWORD; wParam, lParam: Integer):Integer; stdcall;
const
  W = 683;
  H = 512;
begin
  if MSG = WM_SHOWWINDOW then Begin
    SendMessage(Handle, WM_COMMAND, $A004, 0);
    SendMessage(Handle, WM_COMMAND, $A004, 0);
    SetWindowPos(Handle, 0,
    Form.Left + (Form.Width div 2) - (W div 2),
    Form.Top + (Form.Height div 2) - (H div 2),
    W,
    H,
    0);
  End;
  Result := CallWindowProc(Pointer(OldProcForOpenSaveDialog), Handle, Msg, wParam, lParam);
end;

Zu den MessageDialogen habe ich keine Lösung gefunden - würde mich aber auch noch interessieren.

stahli

SaFu 27. Feb 2008 15:58

Re: Position von Dialog
 
Zu den MessageBoxen gabe

War vom Dani und Funzt sehr gut selbst beim verkleinern der Form (logisch)

Delphi-Quellcode:
function MessageDlgPos2(const Msg: string; DlgType: TMsgDlgType;
  Buttons: TMsgDlgButtons; ParentForm: TForm = nil; HelpCtx: Longint = -1;
  const HelpFileName: string = ''): Integer;
begin
  with CreateMessageDialog(Msg, DlgType, Buttons) do
    try
      HelpContext := HelpCtx;
      HelpFile := HelpFileName;
      if Assigned(ParentForm) then begin
        Position := poDesigned;
        //0 div 2 -> 0, also kein Problem.
        Left := ParentForm.Left + ((ParentForm.Width - Width) div 2);
        Top := ParentForm.Top + ((ParentForm.Height - Height) div 2);
      end else begin
        Position := poScreenCenter;
      end;
      Result := ShowModal;
    finally
      Free;
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  MessageDlgPos2('Dies ist ein Test', mtInformation, [mbOK], Self);
end;

stahli 27. Feb 2008 18:27

Re: Position von Dialog
 
so hier nochmal komplett:

Delphi-Quellcode:
implementation

uses
  Windows, Messages;

var
  OldProcForOpenSaveDialog: DWord;

// OldProcfuerOpendialog1: Dword globale Variable
//Idee von Pascal Enz
function DialogProc(Handle: HWND; Msg: DWORD; wParam, lParam: Integer):Integer; stdcall;
const
  W = 683;
  H = 512;
begin
  if MSG = WM_SHOWWINDOW then Begin
    SendMessage(Handle, WM_COMMAND, $A004, 0);
    SendMessage(Handle, WM_COMMAND, $A004, 0);
    SetWindowPos(Handle, 0,
    FormXyz.Left + (FormXyz.Width div 2) - (W div 2),
    FormXyz.Top + (FormXyz.Height div 2) - (H div 2),
    W,
    H,
    0);
  End;
  Result := CallWindowProc(Pointer(OldProcForOpenSaveDialog), Handle, Msg, wParam, lParam);
end;


// und folgende Ereignisbehandlungen den Dialogen zuweisen...


procedure TFormXyz.OpenDialogClose(Sender: TObject);
var
  Handle: HWND;
begin
  Handle := GetParent((Sender as TOpenDialog).Handle);
  SetWindowLong(Handle, DWL_DLGPROC, Integer(OldProcForOpenSaveDialog));
  OldProcForOpenSaveDialog := 0;
end;

procedure TFormXyz.OpenDialogShow(Sender: TObject);
var
  Handle: HWND;
begin
  Handle := GetParent((Sender as TOpenDialog).Handle);
  OldProcForOpenSaveDialog := GetWindowLong(Handle, DWL_DLGPROC);
  SetWindowLong(Handle, DWL_DLGPROC, Integer(@DialogProc));
end;

procedure TFormXyz.SaveDialogClose(Sender: TObject);
var
  Handle: HWND;
begin
  Handle := GetParent((Sender as TSaveDialog).Handle);
  SetWindowLong(Handle, DWL_DLGPROC, Integer(OldProcForOpenSaveDialog));
  OldProcForOpenSaveDialog := 0;
end;

procedure TFormXyz.SaveDialogShow(Sender: TObject);
var
  Handle: HWND;
begin
  Handle := GetParent((Sender as TSaveDialog).Handle);
  OldProcForOpenSaveDialog := GetWindowLong(Handle, DWL_DLGPROC);
  SetWindowLong(Handle, DWL_DLGPROC, Integer(@DialogProc));
end;
stahli

SaFu 27. Feb 2008 19:18

Re: Position von Dialog
 
Mach ich da was falsch habe es jetzt mal mit dem Color dialog versuch aber irgenwie will das net so

Delphi-Quellcode:

var
  Form6: TForm6;
  OldProcForOpenSaveDialog: DWord;

implementation
.
.
.
.

function DialogProc(Handle: HWND; Msg: DWORD; wParam, lParam: Integer):Integer; stdcall;
const
  W = 683;
  H = 512;
begin
  if MSG = WM_SHOWWINDOW then Begin
    SendMessage(Handle, WM_COMMAND, $A004, 0);
    SendMessage(Handle, WM_COMMAND, $A004, 0);
    SetWindowPos(Handle, 0,
    Form6.Left + (Form6.Width div 2) - (W div 2),
    Form6.Top + (Form6.Height div 2) - (H div 2),
    W,
    H,
    0);
  End;
  Result := CallWindowProc(Pointer(OldProcForOpenSaveDialog), Handle, Msg, wParam, lParam);
end;

procedure TForm6.ColorDialog1Close(Sender: TObject);
var Handle: HWND;
begin
  Handle := GetParent((Sender as TColorDialog).Handle);
  SetWindowLong(Handle, DWL_DLGPROC, Integer(OldProcForOpenSaveDialog));
  OldProcForOpenSaveDialog := 0;
end;

procedure TForm6.ColorDialog1Show(Sender: TObject);
var Handle: HWND;
begin
  Handle := GetParent((Sender as TColorDialog).Handle);
  OldProcForOpenSaveDialog := GetWindowLong(Handle, DWL_DLGPROC);
  SetWindowLong(Handle, DWL_DLGPROC, Integer(@DialogProc));
end;

stahli 27. Feb 2008 19:24

Re: Position von Dialog
 
Was geht denn genau nicht?
Hast Du das mal schrittweise angesehen?

SaFu 27. Feb 2008 19:26

Re: Position von Dialog
 
Es plobt nicht in der mitte der Form auf auch wenn ich Sie verschiebe.

Immer nur in der mitte vom screen

stahli 27. Feb 2008 19:36

Re: Position von Dialog
 
Werden die Prozeduren korrekt abgearbeitet?
Was steht in Form6.Left und Width?

SaFu 27. Feb 2008 19:47

Re: Position von Dialog
 
Die proceduren Arbeiten

Im OI Top = 0 und Left = 0

aber das ändert sich ja zur laufzeit immerwieder wenn man die Form verschiebt

stahli 27. Feb 2008 19:56

Re: Position von Dialog
 
... soll sich ja auch ändern ;-)

Hier
Form6.Left + (Form6.Width div 2) - (W div 2),
Form6.Top + (Form6.Height div 2) - (H div 2),
kannst Du Dir doch ansehen, was genau zugewiesen wird...

Sonst weiß ich auch nicht...

stahli


Alle Zeitangaben in WEZ +1. Es ist jetzt 03:46 Uhr.
Seite 1 von 2  1 2      

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