Autor Beitrag
webmaker
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 205



BeitragVerfasst: Sa 08.03.03 15:34 
Hi Leute,
ich habe mal wieder ein Problem. Ich habe mein PRogramm in der TNA, bei Mausklick auf das Icon, wird ein Popup-Menü angezeigt. Jetzt will ich wenn auf ein Item geklickt wird, das Handle des Fensters, das vorher im Vordergrund war, bekommen (ich meine das richtige Fenster einer Anwendung, die vorher im Vordergrund und aktiviert war und durch mein Programm, durch das popup, keinen Fokus hat).
Und dann im nächsten Step soll das Fenster/Anwendung aus der Taskbar entfernt werden, es soll auch verhindert werden, dass sich die Anwendung wieder in die Taskbar einschreibt...
Das Fenster/Anwendung ist eine selbständige Anwendung und hat nicht mit meiner zu tun!....
Noch eine Frage: Wie bekomme ich Infos über das Fenster (FEnstertitel....)

Ich habe das ganze schon mal mit der Funktion GetForegroundWindow() probiert, doch ich bekomme immer 0 heraus...liegt wohl daran, dass das Fenster nich mehr aktiviert ist...
DAnke schon mal für die Hilfe....

//Nachtrag: Mir ist gerade aufgefallen, dass ich den beitrag komischerweise nach VCL gepostet habe, sollte nach API....tschuldigung

_________________
.::Wissen ist Macht, nichts wissen macht nichts::.
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Sa 08.03.03 15:51 
Zitat:
Jetzt will ich wenn auf ein Item geklickt wird, das Handle des Fensters, das vorher im Vordergrund war, bekommen (ich meine das richtige Fenster einer Anwendung, die vorher im Vordergrund und aktiviert war und durch mein Programm, durch das popup, keinen Fokus hat).


Vorschlag:

WM_MOUSEMOVE im TrayIcon abfragen
und dann mit GetForeGroundWindow() das Fenster im Vordergrund
ermitteln. (Vorschlag muss noch verfeinert werden.)

Zitat:
Und dann im nächsten Step soll das Fenster/Anwendung aus der Taskbar entfernt werden, es soll auch verhindert werden, dass sich die Anwendung wieder in die Taskbar einschreibt...


Schwierig! Nur mit Hooks zu lösen.

Vielleicht mal hier vorbeischauen:

help.madshi.net/TrayIcons.htm
webmaker Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 205



BeitragVerfasst: Sa 08.03.03 17:58 
wie genau meinst du das mit WM_Mousemove???
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
  public
     procedure WMTASKBAREVENT(var message: TMessage); message WM_TASKBAREVENT;
     procedure WM_MOUSEMOVE(var messeage: TMessage); message WM_MouseMove;
  end;
[...]
procedure TForm1.WM_MOUSEMOVE(var messeage: TMessage);
begin
  actives_fenster := GetForeGroundWindow();
end;

Und jetzt??? Wie kann ich sagen, dass es sich nur um das Icon handelt? (ich benutze keine Komponente für die TNA)

_________________
.::Wissen ist Macht, nichts wissen macht nichts::.
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Sa 08.03.03 18:16 
WM_MOUSEMOVE muss natürlich innerhalb deiner TrayIcon Klasse behandelt werden.
webmaker Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 205



BeitragVerfasst: Sa 08.03.03 18:22 
das heißt??

_________________
.::Wissen ist Macht, nichts wissen macht nichts::.
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Sa 08.03.03 18:44 
D.h, du musst die der uCallbackMessage zugewiesene Nachricht in einem
Handler (Hier: OnMessage) abfragen und dann den lParam der übergebenen TMessage Strukt. auf WM_MOUSEMOVE überprüfen.
Dann wird das Ereignis OnMouseMove ausgelöst.


ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
unit TrayIcon;
//..

const
  WM_CALLBACK_MESSAGE = WM_USER + 1;
  
type
  TTrayIcon = class(TComponent)
  private
    //...
  protected
    // ...
    procedure DoMouseMove(X, Y: Integer); virtual;
    procedure OnMessage(var Msg: TMessage); virtual;

  public
    //...
  published
    property OnMouseMove: TMouseMoveEvent read fOnMouseMove write fOnMouseMove;
  end;

procedure Register;

implementation


procedure TTrayIcon.OnMessage(var Msg: TMessage);
var
  Pt: TPoint;
  Shift: TShiftState;
begin
  case Msg.Msg of
    WM_Callback_Message: // uCallbackMessage
      case Msg.lParam of
        WM_MOUSEMOVE:
          begin
            GetCursorPos(Pt);
            DoMouseMove(Pt.X, Pt.Y);
          end;
      end;
  end;

procedure TTrayIcon.DoMouseMove(Shift: TShiftState; X, Y: Integer);
begin
  if Assigned(fOnMouseMove) then
    fOnMouseMove(Self, Shift, X, Y);
end;
webmaker Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 205



BeitragVerfasst: Sa 08.03.03 18:56 
hi danke für den source, nur wie kann ich den in meinen einbauen?

ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus, ExtCtrls, StdCtrls;

const WM_TASKBAREVENT = WM_USER+1;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    PopupMenu1: TPopupMenu;
    Image2: TImage;
    Label1: TLabel;
    close1: TMenuItem;
    N1: TMenuItem;
    add: TMenuItem;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure addClick(Sender: TObject);
    procedure close1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
     procedure WMTASKBAREVENT(var message: TMessage); message WM_TASKBAREVENT;
     procedure WM_MOUSEMOVE(var messeage: TMessage); message WM_MouseMove;
  end;

var
  Form1: TForm1;
  actives_fenster : hwnd;

implementation
uses shellapi;
var count : integer = 0;

{$R *.DFM}

procedure TForm1.WM_MOUSEMOVE(var messeage: TMessage);
begin
  actives_fenster := GetForeGroundWindow();
end;

procedure TForm1.WMTASKBAREVENT(var message: TMessage);
var point : TPoint;
begin
    case message.LParamLo of
         WM_RBUTTONDOWN   : begin
                                 GetCursorPos(point);
                                 popupmenu1.popup(point.x,point.y);
                            end;
    end;
end;


procedure TaskBarAddIcon;
var tnid : TNOTIFYICONDATA ;
begin
    tnid.cbSize := sizeof(TNOTIFYICONDATA);
    tnid.Wnd := Form1.handle;
    tnid.uID := 1;
    tnid.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
    tnid.uCallbackMessage := WM_TASKBAREVENT;
    tnid.hIcon := form1.Icon.Handle;
    strcopy(tnid.szTip,'TNA');
    Shell_NotifyIcon(NIM_ADD, @tnid);
end;

procedure TaskBarRemoveIcon;
var tnid : TNOTIFYICONDATA ;
begin
    tnid.cbSize := sizeof(TNOTIFYICONDATA);
    tnid.Wnd := Form1.handle;
    tnid.uID := 1;
    Shell_NotifyIcon(NIM_DELETE, @tnid);
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
   ShowWindow(GetWindow(handle,GW_OWNER),SW_HIDE);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
     inc(count);
     if count = 3 then begin
        self.hide;
        timer1.enabled := false;
        TaskBarAddIcon;
     end;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  TaskBarRemoveIcon;
end;

procedure TForm1.addClick(Sender: TObject);
var
  test : PChar;
begin
  ShowMessage(inttostr(actives_fenster));
//  SendMessage(actives_fenster, SW_HIDE, 0, 0);
  GetWindowText(actives_fenster, test, 4000000);
  ShowMessage(test);
end;

procedure TForm1.close1Click(Sender: TObject);
begin
  close();
end;

end.

danke schon mal für deine Mühe

_________________
.::Wissen ist Macht, nichts wissen macht nichts::.
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Sa 08.03.03 19:02 
etwa so:

ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
{...}
  private
    { Private-Deklarationen }
    procedure OnMouseMove(X, Y: Integer);
  public
    procedure WMTASKBAREVENT(var message: TMessage); message WM_TASKBAREVENT;
  end;

{...}

procedure TForm1.OnMouseMove(X, Y: Integer);
begin
  actives_fenster := GetForeGroundWindow();
end;

procedure TForm1.WMTASKBAREVENT(var message: TMessage);
var 
  point: TPoint;
begin
  case message.LParamLo of
    WM_RBUTTONDOWN: 
      begin
        GetCursorPos(point);
        popupmenu1.popup(point.x, point.y);
      end;
    WM_MOUSEMOVE:
    begin
      GetCursorPos(point);
      OnMouseMove(point.X, point.Y);
    end;
  end;
end;

{...}
webmaker Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 205



BeitragVerfasst: Sa 08.03.03 19:27 
da scheint nochwas falsch zu sein; denn ich bekomme immer den gleichen Handle (bei allen offenen Fenstern) und das aktuelle Fenster wird dan auch noch in den Hintergrundverschoben...Hast du oder auch andere ne Idee?

_________________
.::Wissen ist Macht, nichts wissen macht nichts::.
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Sa 08.03.03 19:34 
seltsam...bei mit klappts. Poste doch nochmals den ganzen Source-Code.
webmaker Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 205



BeitragVerfasst: Sa 08.03.03 19:59 
hier: home.arcor.de/alexander-franz/tna.zip gibt es das gesamte Programm. (Programm setzt sich nur in die TNA und soll halt das machen, was nicht geht ;-))
Danke für deine Mühe

_________________
.::Wissen ist Macht, nichts wissen macht nichts::.