Thema: Delphi TNA

Einzelnen Beitrag anzeigen

maximi

Registriert seit: 9. Jun 2003
217 Beiträge
 
Delphi 7 Personal
 
#1

TNA

  Alt 10. Sep 2003, 10:44
Hallo!
Da ich noch nicht so viel von tna verstehe, habe ich mir mal nen Tutorial runtergeldaden und festegestellt, dass es nicht funktioniert.
Kann mir jemand helfen?


Delphi-Quellcode:
program TaskbarIcon;

{.$DEFINE BALLONNOTIFICATION}


uses
  Windows,
  Messages,
  DllVersion in '..\..\Common~1\DllVersion.pas',
  ShellAPI
{$IFDEF VER130}
  ,ShellAPI_Fragment in '..\..\Common~1\ShellAPI_Fragment.pas'
{$ENDIF}
  ;

const
  szClassname = 'TaskbarIcon-Demo';
  IDM_ABOUT = 1;
  IDM_CLOSE = 2;
  WM_TRAYMSG = WM_USER + 10;

var
  hm : HMENU;
  p : TPoint;
  shell32_ver : dword = 400; // Standardversion 4.0 der "shell32.dll"
  dll : DWORD = 0;
  ver : TDllVersionInfo;

var
  NID : TNotifyIconData = (
    uID : 1052002;
    uFlags : NIF_MESSAGE or NIF_ICON or NIF_TIP;
    uCallbackMessage : WM_TRAYMSG;
    hIcon : 0;
    szTip : szClassname;
  );


//
// "WndProc"
//
function WndProc(wnd: HWND; uMsg: UINT; wp: wParam; lp: LParam): LRESULT; stdcall;
begin
  Result := 0;

  case uMsg of
    WM_CREATE:
      begin
        // Version der "shell32.dll" herausfinden
        dll := LoadLibrary('shell32.dll');
        if(dll <> 0) then
          begin
            DllGetVersion := GetProcAddress(dll,'DllGetVersion');
            if(@DllGetVersion <> nil) then
              begin
                fillchar(ver,sizeof(TDllVersionInfo),0);
                ver.cbSize := sizeof(TDllVersionInfo);
                if(DllGetVersion(@ver) = NOERROR) then
                  shell32_ver := (ver.dwMajorVersion * 100) + ver.dwMinorVersion;
              end;

            FreeLibrary(dll);
          end;

        // abhängig von der "shell32.dll" die Strukturgröße setzen!
        if(shell32_ver = 600) then NID.cbSize := sizeof(TNotifyIconData)
          else if(shell32_ver >= 500) then NID.cbSize := NOTIFYICONDATA_V2_SIZE
            else NID.cbSize := NOTIFYICONDATA_V1_SIZE;

        NID.wnd := wnd;
        NID.hIcon := LoadIcon(0,IDI_INFORMATION);

        // Balloon-Tipps nur ab "shell32.dll" Version 5.0
        if(shell32_ver >= 500) then
          begin
            NID.uFlags := NID.uFlags or NIF_INFO;
            NID.szInfo := 'Ein Beispiel für einen neuen Balloon-Tipp,' +
              #13#10 + 'der auch mehrzeilig sein kann.';
            NID.szInfoTitle := szClassname;
            NID.dwInfoFlags := NIIF_INFO;
          end;

        Shell_NotifyIcon(NIM_ADD,@NID);
        DestroyIcon(NID.hIcon);
      end;
    WM_TRAYMSG:
      case lp of
{$IFDEF BALLOONNOTIFICATION}
        NIN_BALLOONSHOW:
          MessageBox(0,'I see the balloon! :o)',szClassname,MB_OK or MB_ICONINFORMATION);
        NIN_BALLOONHIDE:
          MessageBox(0,'It´s gone ... :o(',szClassname,MB_OK or MB_ICONINFORMATION);
        NIN_BALLOONTIMEOUT:
          MessageBox(0,'KAWOOOM',szClassname,MB_OK or MB_ICONINFORMATION);
        NIN_BALLOONUSERCLICK:
          MessageBox(0,'U clicked the balloon',szClassname,MB_OK or MB_ICONINFORMATION);
{$ENDIF}
        WM_RBUTTONUP:
          begin
            hm := CreatePopupMenu;
            AppendMenu(hm,MF_STRING,IDM_ABOUT,'Information');
            AppendMenu(hm,MF_STRING,IDM_CLOSE,'Beenden');

            GetCursorPos(p);
            SetForegroundWindow(wnd);
            TrackPopupMenu(hm,TPM_RIGHTALIGN,p.X,p.Y,0,wnd,nil);

            DestroyMenu(hm);
          end;
        WM_LBUTTONDBLCLK:
          begin
            NID.hIcon := LoadIcon(0,IDI_WARNING);
            NID.szTip := 'geänderter Tooltipp-Text';

            if(shell32_ver >= 500) then
              begin
                NID.szInfo := 'Hier hat sich der Balloon-Tipp geändert';
                NID.szInfoTitle := szClassname;
                NID.dwInfoFlags := NIIF_WARNING;
              end;

            Shell_NotifyIcon(NIM_MODIFY,@NID);
          end;
      end;
    WM_COMMAND:
      case wp of
        IDM_ABOUT:
          if(shell32_ver >= 500) then
            begin
              NID.szInfo := 'TaskbarIcon-Demo, © 2002 Simmi.';
              NID.szInfoTitle := szClassname;
              NID.dwInfoFlags := NIIF_INFO;
              Shell_NotifyIcon(NIM_MODIFY,@NID);
            end
          else
            MessageBox(0,'TaskbarIcon-Demo, © 2002 Simmi.',szClassname,
              MB_OK or MB_ICONINFORMATION);
        IDM_CLOSE:
          SendMessage(wnd,WM_CLOSE,0,0);
      end;
    WM_DESTROY:
      begin
        Shell_NotifyIcon(NIM_DELETE,@NID);
        PostQuitMessage(0);
      end;
    else
      Result := DefWindowProc(wnd,uMsg,wp,lp);
  end;
end;

//
// MAIN
//
var
  wc: TWndClassEx = (
    cbSize : sizeof(TWndClassEx);
    Style : 0;
    lpfnWndProc : @WndProc;
    cbClsExtra : 0;
    cbWndExtra : 0;
    hIcon : 0;
    hCursor : 0;
    hbrBackground : 0;
    lpszMenuName : nil;
    lpszClassName : szClassname;
    hIconSm : 0;
  );
  msg: TMsg;
  tMutex : THandle;
  aWnd : HWND;

begin
  // nur eine Instanz des Programms darf aktiv sein
  tMutex := CreateMutex(nil,false,szClassname);
  if(GetLastError = ERROR_ALREADY_EXISTS) then
    begin
      MessageBox(0,'Die Demo läuft bereits.',szClassname,MB_OK or MB_ICONWARNING);
      Halt;
    end;

  // Fensterklasse registrieren, & Fenster erzeugen
  wc.hInstance := hInstance;
  if(RegisterClassEx(wc) = 0) then exit;
  aWnd := CreateWindowEx(0,szClassname,szClassname,
    0,0,0,0,0,0,0,hInstance,nil);
  if(aWnd = 0) then exit;
  ShowWindow(aWnd,SW_HIDE);
  UpdateWindow(aWnd);

  // Nachrichtenschleife
  while(GetMessage(msg,0,0,0)) do
    begin
      TranslateMessage(msg);
      DispatchMessage(msg);
    end;

  // Mutex freigeben
  CloseHandle(tMutex);
end.
  Mit Zitat antworten Zitat