Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mo 14.03.05 15:12 
ich hab ausm delphi-helper von delphisource.de folgende code (auszug)(die reihenfolge ist natürlich anders) und er sagt bei private bei der procedure wmtaskbarevents undefinierter bezeichner "WM_TASKBAREVENT" (nach message) dabei hab ich ihn doch bei const deklariert. Was sol ich tun? hat einer vielleicht das gleiche problem und kann mir helfen?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure TForm1.WMTaskbarEvent(var Message: TMessage);
var
  Point: TPoint;
begin
  case Message.LParamLo of
     WM_LBUTTONDOWN: application.Restore;
     WM_RBUTTONDOWN: begin
                          SetForegroundWindow(Handle);
                          GetCursorPos(point);
                          popupmenu1.popup(point.x,point.y);
                     end;
  end;
end;


const
 WM_TASKBAREVENT = WM_USER + 1;

private
   procedure WMTaskbarEvent(var Message: TMessage); message WM_TASKBAREVENT;


Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt.
EUOCheffe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 124



BeitragVerfasst: Mo 14.03.05 17:26 
Wieso postest du nicht einfach den ganzen Code oder nen Link zum Code? Wäre einfacher als jetzt alle möglichen Dinge aufzuzählen, die vielleicht schief gelaufen sind.
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mo 14.03.05 18:01 
Titel: Hier nun der ganze code
ausblenden Delphi-Quelltext
1:
2:
const
 WM_TASKBAREVENT = WM_USER + 1;


Es folgt die Deklaration des Prozedurkopfes dieser Botschaft.

ausblenden Delphi-Quelltext
1:
2:
Private
procedure WMTaskbarEvent(var Message: TMessage); message WM_TASKBAREVENT;


Über die folgenden Prozeduren wird das Icon im Systray angezeigt (TaskbarAddIcon) und wieder entfernt (TaskBarRemoveIcon):

ausblenden volle Höhe Delphi-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:
procedure TaskBarAddIcon;
var
  tnid: TNotifyIconData;
  Owner: HWnd;
begin
  with tnid do
  begin
    cbSize := SizeOf(TNotifyIconData);
    Wnd := Form1.Handle;
    uID := 1;
    uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
    uCallbackMessage := WM_TASKBAREVENT;
    hIcon := Application.Icon.Handle;
  end;
  StrCopy(tnid.szTip, 'Tooltipp');
  Shell_NotifyIcon(NIM_ADD, @tnid);

  Owner:=GetWindow(Form1.Handle,GW_OWNER);
  If Owner<>0 Then
    ShowWindow(Owner,SW_HIDE);
end;

procedure TaskBarRemoveIcon;
var
  tnid: TNotifyIconData;
  Owner: HWnd;
begin
  tnid.cbSize := SizeOf(TNotifyIconData);
  tnid.Wnd := Form1.Handle;
  tnid.uID := 1;
  Shell_NotifyIcon(NIM_DELETE, @tnid);
  Owner:=GetWindow(Form1.Handle,GW_OWNER);
  If Owner<>0 Then Begin
    ShowWindow(Owner,SW_Show);
    ShowWindow(Owner,SW_Normal);
  End;
end;


Nun folgt noch die Implementation unserer oben deklarierten Botschaft:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.WMTaskbarEvent(var Message: TMessage);
var 
  Point: TPoint;
begin
  case Message.LParamLo of
     WM_LBUTTONDOWN: TaskBarRemoveIcon;
     WM_RBUTTONDOWN: begin
                          SetForegroundWindow(Handle);
                          GetCursorPos(point);
                          popupmenu1.popup(point.x,point.y);
                     end;
  end;
end;


Klickt man mit der linken Maustaste auf das Icon (WM_LBUTTONDOWN), wird dieses entfernt. Mit einem Rechtsklick wird an der Stelle ein Kontextmenu (Popupmenu1) geöffnet.

Da die Anwendung in diesem Beispiel nur im minimierten Zustand in SysTray erscheinen soll, muss zusätzlich noch folgende Zeile in das Application-Ereignis OnMinimize:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.ApplicationEvents1Minimize(Sender: TObject);
begin
 TaskBarAddIcon;
end;

Seit Delphi 5 ist dieses Ereignis in der Komponente TApplicationEvents gekapselt. Arbeitest du mit einer kleineren Version, musst du das Ereignis manuell zuweisen. Im Private-Abschnitt muss dazu zusätzlich noch folgende Procedure deklariert werden:

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt.
EUOCheffe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 124



BeitragVerfasst: Mo 14.03.05 18:48 
Dein Code klappt bei mir prima. Da muss irgendwas anderes verbockt sein. Probier mal, ob mein Code bei dir läuft. Falls ja, vergleiche die Beiden und du solltest das Problem finden.

ausblenden volle Höhe Delphi-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:
unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
     Dialogs, Menus, StdCtrls, ShellApi;

const
 WM_TASKBAREVENT = WM_USER + 1;

type
  TForm1 = class(TForm)
    PopupMenu1: TPopupMenu;
    Test1: TMenuItem;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    procedure WMTaskbarEvent(var Message: TMessage); message WM_TASKBAREVENT;
  end;

var
  Form1: TForm1;

implementation
{$R *.dfm}

////////////////////////////////////////////////////////////////////////////////
procedure TaskBarAddIcon;
var
  tnid: TNotifyIconData;
  Owner: HWnd;
begin
  with tnid do
  begin
    cbSize := SizeOf(TNotifyIconData);
    Wnd := Form1.Handle;
    uID := 1;
    uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
    uCallbackMessage := WM_TASKBAREVENT;
    hIcon := Application.Icon.Handle;
  end;
  StrCopy(tnid.szTip, 'Tooltipp');
  Shell_NotifyIcon(NIM_ADD, @tnid);

  Owner:=GetWindow(Form1.Handle,GW_OWNER);
  If Owner<>0 Then
    ShowWindow(Owner,SW_HIDE);
end;

////////////////////////////////////////////////////////////////////////////////
procedure TaskBarRemoveIcon;
var
  tnid: TNotifyIconData;
  Owner: HWnd;
begin
  tnid.cbSize := SizeOf(TNotifyIconData);
  tnid.Wnd := Form1.Handle;
  tnid.uID := 1;
  Shell_NotifyIcon(NIM_DELETE, @tnid);
  Owner:=GetWindow(Form1.Handle,GW_OWNER);
  If Owner<>0 Then Begin
    ShowWindow(Owner,SW_Show);
    ShowWindow(Owner,SW_Normal);
  End;
end;

////////////////////////////////////////////////////////////////////////////////
procedure TForm1.WMTaskbarEvent(var Message: TMessage);
var
  Point: TPoint;
begin
  case Message.LParamLo of
     WM_LBUTTONDOWN: TaskBarRemoveIcon;
     WM_RBUTTONDOWN: begin
                          SetForegroundWindow(Handle);
                          GetCursorPos(point);
                          popupmenu1.popup(point.x,point.y);
                     end;
  end;
end;

////////////////////////////////////////////////////////////////////////////////
procedure TForm1.Button1Click(Sender: TObject);
begin
  TaskBarAddIcon;
end;

end.