Hallo,<br><br>normalerweise wird bei FormStyle=fsStayOnTop das entsprechende Fenster in den Vordergrund der eigenen Anwendung gesetzt. Wenn eine andere Anwendung (nicht der selbe Prozess) durch einen Benutzer in den Vordergrund gebracht wird, dann befindet sich meine Form vor den Fenstern der anderen Anwendung.<br><br>Dieses Problem tritt auf, da ich CreateMessageDialog (aus MessageDlg) ähnlich aufrufe, wie aus MessageDlg. Hier habe ich FormStyle nach CreateMessageDlg auf fsStayOnTop gesetzt, da mein Meldungsfenster auch sichbar sein sollte, wenn ich bei einer anderen Form FormStyle auf fsStayOnTop gesetzt habe.<br><br>Weiß jemand, wieso meine Routine nicht funktioniert?<br><br>Stephan Hartmann<br>D5 Ent. mit SP
Announcement
Collapse
No announcement yet.
fsStayOnTop verdeckt Fenster von anderen Anwendungen
Collapse
X
-
Hier noch meine Routine:
<PRE>{ aus Deklaration aus Dialogs.pas kopiert, da diese nur innerhalb von Dialogs sichtbar ist: }
var
ButtonNames: array[TMsgDlgBtn] of string = (
'Yes', 'No', 'OK', 'Cancel', 'Abort', 'Retry', 'Ignore', 'All', 'NoToAll',
'YesToAll', 'Help');
function suMessageDlg(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint = 0; DefaultButton : TMsgDlgBtn = mbYes;
Beep : boolean = False): Integer;
begin
if Beep then
case DlgType of
mtWarning : MessageBeep(mb_IconExclamation);
mtError : MessageBeep(mb_IconHand);
mtInformation : MessageBeep(mb_IconAsterisk);
mtConfirmation : MessageBeep(mb_IconQuestion);
end;
with CreateMessageDialog(Msg, DlgType, Buttons) do
try
HelpContext := HelpCtx;
HelpFile := Application.HelpFile;
Position := poScreenCenter;
FormStyle := fsStayOnTop;
if (DefaultButton <> mbYes) and (DefaultButton in Buttons) then
ActiveControl := FindComponent(ButtonNames[DefaultButton]) as TButton;
Result := ShowModal;
finally
Free;
end;
end;
</PRE>
-
Hallo,<br>
<br>
<pre>
habe da mal ne function ausgegraben...<br>
<br>
function SetTopWindow(hwnd: THandle): boolean;
const
SPI_GETFOREGROUNDLOCKTIMEOUT = $2000;
SPI_SETFOREGROUNDLOCKTIMEOUT = $2001;
var
ForegroundThreadID: DWORD;
ThisThreadID : DWORD;
timeout : DWORD;
// a : LPDWORD;
begin
if GetForegroundWindow = hwnd then Result := true
else begin
if ((Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion > 4)) or
((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and
((Win32MajorVersion > 4) or ((Win32MajorVersion = 4) and (Win32MinorVersion > 0)))) then
begin
Result := false;
ForegroundThreadID := GetWindowThreadProcessID(GetForegroundWindow,nil);
ThisThreadID := GetWindowThreadPRocessId(hwnd,nil);
if AttachThreadInput(ThisThreadID, ForegroundThreadID, true) then begin
BringWindowToTop(hwnd);
SetForegroundWindow(hwnd);
AttachThreadInput(ThisThreadID, ForegroundThreadID, false);
Result := (GetForegroundWindow = hwnd);
end;
if not Result then begin
SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @timeout, 0);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(0), SPIF_SENDCHANGE);
BringWindowToTop(hwnd);
SetForegroundWindow(hWnd);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(timeout), SPIF_SENDCHANGE);
end;
end
else begin
BringWindowToTop(hwnd);
SetForegroundWindow(hwnd);
end;
Result := (GetForegroundWindow = hwnd);
end;
end;
<br>
und in deiner kannst du an der stelle von FormStyle := fsStayOnTop; ja <br>
<br>
if not SetTopWindow(handle) then begin
FormStyle := fsStayOnTop;
SetForegroundWindow(Handle);
FormStyle := fsNormal;
end;
<br>
einfügen...
<br>
</pre>
<br>
H. Leesc
Comment
Comment