whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

55 Visitors Online


 
...position a messagebox over a form?
Autor: Thomas Stutz
[ Print tip ]  

Tip Rating (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;


 

Rate this tip:

poor
very good


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