Forum
Grundkurs
»Introduktion
»Snabbguide
»Komponenter
»Händelser
»Strängar
»Räkna med Delphi »Egna
typer
»Selektion
»Iteration
»Menyer
»Funktioner
»Arraystrukturer
Tips & Tricks
»Nya tips
»Blandat
»Databaser
»Filer
»Forms
»Grafik
»Internet
»Komponenter
»Matematik
»Multimedia
»Objekt/ActiveX
»Skrivare
»Strängar
»System
»Mest lästa tips
Artiklar
»Delphi och ADO
»Bygga en DLL
»Skapa en enkel rapport
»Hantera registret
»Enheter, units
»Klassen TCanvas
»Använd LookUp Controls
Nya
tips
Lägg
till tips
Delphilänkar
Gästbok
|
|
|
|
Positionera en MessageBox över ett formulär
|
Kategori: Forms
Inlagt: 2005-06-11
Läst: 1346
Inlagt av: Staffan Berg
|
Beskrivning |
Med hjälp av detta exempel kan du styra var på formuläret en meddelanderuta ska uppenbara sig.
|
Kod |
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;
|
|
|