was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

57 Visitors Online


 
...eine MessageBox über einer Form positionieren?
Autor: Thomas Stutz
[ Tip ausdrucken ]  

Tip Bewertung (19):  
     


const
  
mbMessage = WM_USER + 1024;

type
  private
     procedure 
ChangeMessageBoxPosition(var Msg: TMessage); message mbMessage;
  end;


var
  
Form1: TForm1;
  msgCaption: PChar;  // variable to hold the caption

implementation


{$R *.DFM}

procedure TForm1.ChangeMessageBoxPosition(var Msg: TMessage);
var
  
MbHwnd: longword;
  MbRect: TRect;
  x, y, w, h: integer;
begin
  
MbHwnd := FindWindow(MAKEINTRESOURCE(WC_DIALOG), msgCaption);
  if (MbHwnd <> 0) then
  begin
    
GetWindowRect(MBHWnd, MBRect);
    with MbRect do
    begin
      
w := Right - Left;
      h := Bottom - Top;
    end;
    // center horzontal
    
x := Form1.Left + ((Form1.Width - w) div 2);
    // keep on screen
    
if x < 0 then
      
x := 0
    else if x + w > Screen.Width then x := Screen.Width - w;
    //center vertical
    
y := Form1.Top + ((Form1.Height - h) div 2);
    // keep on screen
    
if y < 0 then y := 0
    else if y + h > Screen.Height then y := Screen.Height - h;
    // set new windows position
    
SetWindowPos(MBHWnd, 0, x, y, 0, 0, SWP_NOACTIVATE or SWP_NOSIZE or SWP_NOZORDER);
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  
PostMessage(Handle, WM_USER + 1024, 0, 0);
  msgCaption := 'Confirm';
  MessageBox(Handle, 'Has our MessageBox moved ?', msgCaption,
    MB_ICONQUESTION or MB_YESNO);
end;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners