27. maj 2000 - 13:11Der er
10 kommentarer og 1 løsning
systray igen igen
Nu har jeg fået installet rxlib som folk var så glade for, men kan ikke finde komponentet som skal hjælpe mig med at få mig program ned i systray... nogen der kan hjælpe?
jeps jeg vil gerne se det... men det skal helst ikke være så omfattende som i tidligere spørgsmål... bare hvordan man på en simpel måde får et program ned i systray.. cocio@mail.ikasths.dk
har jeg tidligere vist koden til et lille systray eksempel jeg har lavet. Hvis du vil have det som en mail er du velkommen. Bare sig til. Ellers kan du også tage det direkte fra spørgsmålet.
sjensen: ja det er sikkert udmærket... har kigget på det, men synes det er for besværligt... jeg vil gerne have det lavet med noget mindre kode.. sorry
Jeg ville nu helst hvis nogen af dem som er så glade for rxlib kunne fortælle mig hvilken komponentet jeg skal burge... hvis de da stadigvæk mener den kan bruges til opgaven!
sjensen: jeg har downloaded rxlib.. og ledt og ledt.. men kan faktisk ikke finde det... hvis du mener 30 point er for lidt kan jeg da bare sætte det lidt op...
borrisholt: jeg synes ikke dit eksampel virker som det skal... det opfører sig lidt underligt efter min mening... men ok måske kan jeg bruge det hvis jeg ikke få et andet svar!
Hør nu her kokoko, det er jo ikke så besværligt at lave det selv. Jeg indrømmer at et komponent der bare smides på ens form, og vupti har man et systray program er en rar ting, hvis man altså lige kan findes sådan et komponent. Men at lave det selv er meget enkelt og frigør dig for di bindinger til et eksternt komponent, man mange gange glemmer at få med over på en anden maskine, eller geninstalleret når delphi installeres på ny. Ved at lave det hele selv har du det i din egen source.
Der er primært kun 2 ting du skal gøre:
1. Ændre din dpr source med:
uses Windows, // husk at tilføje denne
begin ShowWindow(Application.Handle, sw_Hide); // erstat Application.Initialize; med denne linie Application.ShowMainForm := False; // og husk denne linie også Application.CreateForm(TForm1, Form1); Application.Run; end.
Hvis du absolut vil have et komponent der kan det hele for dig så prøv den her :
unit SysTray; // Implements the TSysTrayIcon component, which controls an icon in // the system tray
// Things that should've been done better: // Use one window handle for multiple instances. // Events for MouseUp messages
// Feel free to modify and use this code. // The only thing I ask, is that you leave my name in the source file.
// Please note that I provide this code as an example, and I // make no warranties whatsoever on the results of using this code. // Meaning: Whatever happens because you've used this code, is your own // responsibility.
// Also note that I have NOT tested this code very thoroughly, I just // wrote it in response to several newsgroup messages requesting information // on how to implement SysTray icons.
// Thule Air Base, Greenland, May 30. 2000 // Jens Borrisholt
const // Used to ensure that each added icon has an unique ID IconIndex : LONGINT = 0;
procedure Register; begin RegisterComponents('Samples', [TSysTrayIcon]); end;
constructor TSysTrayIcon.Create (AOwner : TComponent); begin inherited Create (AOwner); // Allocate a window handle for callback messages FHandle := AllocateHWND(WndProc); // Create the icon, and set default FIcon := TIcon.Create; FIcon.Handle := Application.Icon.Handle; // Set the internal icon id. FIconID := IconIndex; // And increment the instance count, to allow multiple systray icons inc(IconIndex); end;
destructor TSysTrayIcon.Destroy; begin // Make sure the icon is removed Visible := FALSE; // Deallocate the window handle DeallocateHWND(FHandle); // And free the icon object FIcon.Free; end;
procedure TSysTrayIcon.SetIconData(var IconData:TNotifyIconData); begin // Set the standard size of structure field IconData.cbSize := SizeOf(IconData); // Window to receive callback messages IconData.Wnd := FHandle; // Internal ID of the icon IconData.uID := FIconID; // Message we want to receive when something happens to the icon IconData.uCallbackMessage := PM_ICONCALLBACK; // Handle to the icon. IconData.hIcon := FIcon.Handle; // The tooltip StrPCopy(IconData.szTip, FToolTip); // IconData contains a valid window handle, a valid icon handle, and a valid // tooltip IconData.uFlags := NIF_MESSAGE + NIF_TIP + NIF_ICON; end;
procedure TSysTrayIcon.IconChanged; var IconData : TNotifyIconData; begin // No need to do anything, if the icon ain't visible if not Visible then exit; // Set the IconData fields SetIconData(IconData); // And tell systray the icon's changed Shell_NotifyIcon(NIM_MODIFY, ADDR(IconData)); end;
procedure TSysTrayIcon.SetIcon (value : TIcon); begin // Copy the passed icon. FIcon.Assign(value); // Update the icon (if visible) IconChanged; end;
procedure TSysTrayIcon.SetVisible (value : BOOLEAN); var IconData : TNotifyIconData; begin if value=FVisible then exit; // We don't want systray icons while designing the form. This check // could be removed, but then two icons would be visible when running // the app from the Delphi IDE if not (csDesigning in ComponentState) then begin // Set the icondata fields SetIconData(IconData); // Add or remove the icon if value then FVisible := Shell_NotifyIcon(NIM_ADD, ADDR(IconData)) else FVisible := not Shell_NotifyIcon(NIM_DELETE, ADDR(IconData)); end else FVisible := value; end;
procedure TSysTrayIcon.SetToolTip (value : STRING); begin if FToolTip=value then exit; // Set the new tooltip FToolTip := value; // Update the icon (if visible) IconChanged; end;
procedure TSysTrayIcon.WndProc (var message : TMessage); var pt : TPoint; begin // Could also include ButtonUp messages // Should use GetMessagePos, but ain't always working correctly. if message.msg = PM_ICONCALLBACK then begin // lParam contains the actual message. case message.lParam of WM_LBUTTONDOWN: if Assigned (FOnLeftClick) then begin GetCursorPos (pt); FOnLeftClick(Self, pt.X, pt.Y); end; WM_LBUTTONDBLCLK: if Assigned (FOnLeftDblClick) then begin GetCursorPos (pt); FOnLeftDblClick(Self, pt.X, pt.Y); end; WM_RBUTTONDOWN: if Assigned (FOnRightClick) then begin GetCursorPos (pt); FOnRightClick(Self, pt.X, pt.Y); end; WM_RBUTTONDBLCLK: if Assigned (FOnRightDblClick) then begin GetCursorPos (pt); FOnRightDblClick(Self, pt.X, pt.Y); end; WM_MOUSEMOVE : if Assigned (FOnMouseMove) then begin GetCursorPos (pt); FOnMouseMove(Self, pt.X, pt.Y); end; end; end; end;
initialization end.
Får jeg så 150 point ?
Jens B
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.