![]() |
Fenster Form immer aktiv????
Hallo, ich bin ein absolutes GreenHorn
und hab folgendes Problem. Ich habe ein Fenster welches unbedingt aktiv bleiben soll, egal was gescheit. Das Fenster wartet nur auf eingaben von der Tastatur. Falls irgendeine Anwendung aufpopt und mein Fenster "grau" macht, also deaktiviert soll es sofort wieder in den Vordergrund poppen und aktiv sein. Geht das Irgendwie. Hier meine Form definition. Was soll ich tun??
Delphi-Quellcode:
[edit=sakura] [delphi]-Tag Mfg, sakura[/edit]
type
TForm1 = class(TForm) Edit1: TEdit; Timer1: TTimer; Button1: TButton; procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); {procedure Edit1Change(Sender: TObject);} procedure Button1Click(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } published end; var Form1: TForm1; implementation |
Re: Fenster Form immer aktiv????
Stay On Top wäre ´ne möglichkeit und nach bestimmter Zeit/Aktion Fokus auf die Komponente
zur Texteingabe...
Delphi-Quellcode:
zb.
Form1.FormStyle := fsStayOnTop;
Delphi-Quellcode:
Edit1.SetFocus;
Philipp |
Re: Fenster Form immer aktiv????
Wohin damit???
|
Re: Fenster Form immer aktiv????
Was machst Du denn mit dem Timer?
Hast Du da keine Procedure? Stay on Top kann in die Procedure Form1.OnCreate... (Nach Doppelklick auf Form in IDE) |
Re: Fenster Form immer aktiv????
OK, also das stayontop funktioniert soweit.
procedure TForm1.FormCreate(Sender: TObject); begin Timer1.Interval := _IDLETIME; Edit1.MaxLength := _PINLENGTH; OutPort(_PORT,_OFF); Form1.FormStyle := fsStayOnTop; end; Zur Erklärung, der Timer macht einen _Port, 5 Sekunden auf und dann wieder zu. Dies geschieht nachdem eine Eingabe in Edit1 erfolgt ist und ne Berchnung TRUE war. Kann mann nicht beim Ereigniss:OnDeactivate einfach wieder irgendwas sagen dass das Fenster wieder aktiv werden soll. Also nicht nur onTop sonder auch "bereit zur Eingabe"? Ich kann gern mal die ganzen Units Posten wenns hilft. mfg, André! |
Re: Fenster Form immer aktiv????
Bereit zur Eingabe bedeutet ja dass der Fokus auf einer Komponente liegen muss,
die Eingaben verarbeiten kann, zb. das Edit. Wie gesagt,
Delphi-Quellcode:
müsste klappen....
Edit1.SetFocus;
|
Re: Fenster Form immer aktiv????
Hallo,
also ich habe mir schon länger mal folgendes zusammengebastelt:
Delphi-Quellcode:
So bleibt Dein Fenster immer an oberster Stelle und es kann den Focus behalten
{*************************************************************************************************}
{* ForceForegroundWindow {*************************************************************************************************} {* Manchmal funktioniert die SetForeGroundWindow Funktion nicht so, wie sie sollte; besonders un- {* ter Windows 98/ME/2000/XP, schraenkt das Betriebssystem ein, welcher Prozess in den Fordergrund {* kommen darf, wenn ein anderes Fenster den Fokus hat. {* ForceForegroundWindow ist eine "verbesserte" Version von der SetForeGroundWindow API-Funktion, {* um ein Fenster in den Vordergrund zu bringen. {*************************************************************************************************} {* Das ganze funzt nur unter Windows NT4/98/ME/2000/XP bei Start aus dem Explorer heraus. {* Sobald das Programm von einer BatchDatei aus erneut gestartet wird funzt es nur noch unter {* Win NT4!! {*************************************************************************************************} //# V2.84.8 function ForceForegroundWindow(hwnd: THandle): Boolean; var ForegroundThreadID : DWORD; ThisThreadID : DWORD; timeout : DWORD; begin if IsIconic(hwnd) then ShowWindow(hwnd, SW_RESTORE); if GetForegroundWindow = hwnd then Result := True // Hurra, es klappte sofort! else begin // Windows Version ermitteln 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 //----------------------------------------------------------- // Erster Versuch (-> Delphi Magazine 55, page 16) //----------------------------------------------------------- Result := False; ForegroundThreadID := GetWindowThreadProcessID(GetForegroundWindow, nil); ThisThreadID := GetWindowThreadPRocessId(hwnd, nil); if AttachThreadInput(ThisThreadID, ForegroundThreadID, True) then begin //----------------------------------------------------------------------------- // Siehe auch in der MSDN Library "BringWindowToTop": // // The BringWindowToTop function brings the specified window to the top of the Z order. // If the window is a top-level window, it is activated. If the window is a child window, // the top-level parent window associated with the child window is activated. // Use the BringWindowToTop function to uncover any window that is partially or completely // obscured by other windows. // Calling this function is similar to calling the SetWindowPos function to change a wind- // ow's position in the Z order. BringWindowToTop does not make a window a top-level window. //----------------------------------------------------------------------------- BringWindowToTop(hwnd); // IE 5.5 related hack SetForegroundWindow(hwnd); AttachThreadInput(ThisThreadID, ForegroundThreadID, False); Result := (GetForegroundWindow = hwnd); // Testen ob Erfolg end; //----------------------------------------------------------------------------- // Zweiter Versuch (Code von Daniel P. Stasinski) //----------------------------------------------------------------------------- if not Result then begin //----------------------------------------------------------------------------- // Siehe auch in der MSDN Library "SetForegroundWindow": // // To have SetForegroundWindow behave the same as it did on Windows 95 and MS // Windows NT 4.0, change the foreground lock timeout value when the applica- // tion is installed. This can be done from the setup or installation applica- // tion with the following function call: // // SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID)0, // SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE); // // This method allows SetForegroundWindow on Windows 98/Windows Me and Windows // 2000/Windows XP to behave the same as Windows 95 and Windows NT 4.0, respec- // tively, for all applications. The setup application should warn the user // that this is being done so that the user isn't surprised by the changed be- // havior. On Windows Windows 2000 and Windows XP, the call fails unless the // calling thread can change the foreground window, so this must be called // from a setup or patch application. For more information, see Foreground // and Background Windows. //----------------------------------------------------------------------------- // Siehe auch in der MSDN Library "SystemParametersInfo": // // SPI_SETFOREGROUNDLOCKTIMEOUT: // Sets the amount of time following user input, in milliseconds, during which // the system does not allow applications to force themselves into the fore- // ground. Set pvParam to the new timeout value. // The calling thread must be able to change the foreground window, otherwise // the call fails. // Windows NT and Windows 95: This value is not supported. // SPIF_SENDCHANGE: // Broadcasts the WM_SETTINGCHANGE message after updating the user profile. //----------------------------------------------------------------------------- SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @timeout, 0); SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(0), SPIF_SENDCHANGE); BringWindowToTop(hwnd); // IE 5.5 related hack SetForegroundWindow(hWnd); SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(timeout), SPIF_SENDCHANGE); end; end else begin // Win 95 / Win NT 4.0 BringWindowToTop(hwnd); // IE 5.5 related hack SetForegroundWindow(hwnd); end; Result := (GetForegroundWindow = hwnd); end; end; { ForceForegroundWindow } Fuchtel |
Re: Fenster Form immer aktiv????
Das sieht ja alles sehr gut aus, nur hilft es mir nicht weiter, da ich
1. mein Programm aus ner Batchdatei raus starte. Da ansonsten beim hochfahren und über autostart das Programm sowieso im Hintergrund landet weil irgendwie andere Progs langsamer starten und mir den Focus dann wegschnappen. Mit der Batch warte ich 30 Sekunden nach dem Start und dann lass ich mein Prog starten. 2. Ich schau mir heute zum 2. mal dieses Mysteriösum an. Wie um (gotteswillen) soll ich n das in mein Programm reinzaubern? :-) Vieleicht sollte ich was in C schreiben was ich dann auf DOS laufen lasse. Da gibts nur einen Focus<commandline... :-) |
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:09 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz