AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

Fenster Form immer aktiv????

Ein Thema von akoeh · begonnen am 10. Apr 2006 · letzter Beitrag vom 10. Apr 2006
Antwort Antwort
akoeh

Registriert seit: 10. Apr 2006
4 Beiträge
 
#1

Fenster Form immer aktiv????

  Alt 10. Apr 2006, 12:36
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:
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
[edit=sakura] [delphi]-Tag Mfg, sakura[/edit]
  Mit Zitat antworten Zitat
Benutzerbild von Loki77
Loki77

Registriert seit: 21. Feb 2006
Ort: Trier
132 Beiträge
 
Delphi XE2 Enterprise
 
#2

Re: Fenster Form immer aktiv????

  Alt 10. Apr 2006, 12:48
Stay On Top wäre ´ne möglichkeit und nach bestimmter Zeit/Aktion Fokus auf die Komponente
zur Texteingabe...

Form1.FormStyle := fsStayOnTop; zb.

Edit1.SetFocus;
Philipp
"What I cannot create, I do not understand."
-Richard P. Feynman
  Mit Zitat antworten Zitat
akoeh

Registriert seit: 10. Apr 2006
4 Beiträge
 
#3

Re: Fenster Form immer aktiv????

  Alt 10. Apr 2006, 12:52
Wohin damit???
  Mit Zitat antworten Zitat
Benutzerbild von Loki77
Loki77

Registriert seit: 21. Feb 2006
Ort: Trier
132 Beiträge
 
Delphi XE2 Enterprise
 
#4

Re: Fenster Form immer aktiv????

  Alt 10. Apr 2006, 12:55
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)
"What I cannot create, I do not understand."
-Richard P. Feynman
  Mit Zitat antworten Zitat
akoeh

Registriert seit: 10. Apr 2006
4 Beiträge
 
#5

Re: Fenster Form immer aktiv????

  Alt 10. Apr 2006, 13:11
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é!
  Mit Zitat antworten Zitat
Benutzerbild von Loki77
Loki77

Registriert seit: 21. Feb 2006
Ort: Trier
132 Beiträge
 
Delphi XE2 Enterprise
 
#6

Re: Fenster Form immer aktiv????

  Alt 10. Apr 2006, 13:31
Bereit zur Eingabe bedeutet ja dass der Fokus auf einer Komponente liegen muss,
die Eingaben verarbeiten kann, zb. das Edit.
Wie gesagt,
Edit1.SetFocus; müsste klappen....
"What I cannot create, I do not understand."
-Richard P. Feynman
  Mit Zitat antworten Zitat
Fuchtel

Registriert seit: 9. Nov 2005
Ort: Bamberg
53 Beiträge
 
Delphi 2005 Personal
 
#7

Re: Fenster Form immer aktiv????

  Alt 10. Apr 2006, 13:36
Hallo,

also ich habe mir schon länger mal folgendes zusammengebastelt:


Delphi-Quellcode:
{*************************************************************************************************}
{*  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 }
So bleibt Dein Fenster immer an oberster Stelle und es kann den Focus behalten

Fuchtel
  Mit Zitat antworten Zitat
akoeh

Registriert seit: 10. Apr 2006
4 Beiträge
 
#8

Re: Fenster Form immer aktiv????

  Alt 10. Apr 2006, 13:57
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...
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:20 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz