23. november 2001 - 21:08Der er
15 kommentarer og 2 løsninger
Balloon tips fra Windows XP
Hej
I kender sikkert de der balloner i Windows XP som popper op f.eks. nede i systray\'en hvis netværksstikket bliver taget ud, eller hvis CAPS-LOCK er slået til når man skal indtaste passwords.
Jeg synes personligt de er ret fede sådan nogle hints, så jeg ville jo gerne bruge dem i mit eget program. Derfor tænkte jeg på om i ikke vidste hvordan man kunne implementere sådanne hints.
De fleste virksomheder har efterhånden bevist, at AI virker.
Pilotprojekter leverer resultater. Medarbejdere bruger generative AI-værktøjer. Nye use cases dukker op på tværs af organisationen.
Please note: The author assumes you are familiar with simple operations of inserting and removing your icons to / from the \"Tray\". If you are not, I suggest studying either, or both, of the following: 1. How to create a TrayIcon ! (ID 1567) by Bernhard Angerer 2. In the end of this article, I provide my own functions for these tasks.
Now, back to the balloons. I found out that the format of the NotifyIconData structure used to operate icons in the Tray (which, by the way, is called by Microsoft \"The Taskbar Notification Area\" :) changed significantly in Windows 2000. Those changes are NOT reflected in ShellAPI.pas unit of Delphi 5. Therefore I got the original SHELLAPI.H and translated the required declarations. Here they are:
uses Windows;
type NotifyIconData_50 = record // defined in shellapi.h cbSize: DWORD; Wnd: HWND; uID: UINT; uFlags: UINT; uCallbackMessage: UINT; hIcon: HICON; szTip: array[0..MAXCHAR] of AnsiChar; dwState: DWORD; dwStateMask: DWORD; szInfo: array[0..MAXBYTE] of AnsiChar; uTimeout: UINT; // union with uVersion: UINT; szInfoTitle: array[0..63] of AnsiChar; dwInfoFlags: DWORD; end{record};
type TBalloonTimeout = 10..30{seconds}; TBalloonIconType = (bitNone, // no icon bitInfo, // information icon (blue) bitWarning, // exclamation icon (yellow) bitError); // error icon (red)
Now we\'re ready to BALLOON!
This is the function I use:
uses SysUtils, Windows, ShellAPI;
function DZBalloonTrayIcon(const Window: HWND; const IconID: Byte; const Timeout: TBalloonTimeout; const BalloonText, BalloonTitle: String; const BalloonIconType: TBalloonIconType): Boolean; const aBalloonIconTypes : array[TBalloonIconType] of Byte = (NIIF_NONE, NIIF_INFO, NIIF_WARNING, NIIF_ERROR); var NID_50 : NotifyIconData_50; begin FillChar(NID_50, SizeOf(NotifyIconData_50), 0); with NID_50 do begin cbSize := SizeOf(NotifyIconData_50); Wnd := Window; uID := IconID; uFlags := NIF_INFO; StrPCopy(szInfo, BalloonText); uTimeout := Timeout * 1000; StrPCopy(szInfoTitle, BalloonTitle); dwInfoFlags := aBalloonIconTypes[BalloonIconType]; end{with}; Result := Shell_NotifyIcon(NIM_MODIFY, @NID_50); end;
And this is how to employ it:
DZBalloonTrayIcon(Form1.Handle, 1, 10, \'this is the balloon text\', \'title\', bitWarning);
The icon has to be already added, of course, with the same window handle and IconID (in this example, Form1.Handle and 1).
Try all three types of the inside-the-balloon-icons, they are cool!
======THE END OF THE BALLOON ARTICLE======
P.S. Now the functions I promised for adding/removing tray icons:
uses SysUtils, Windows, ShellAPI;
{just adds an icon} function DZAddTrayIcon(const Window: HWND; const IconID: Byte; const Icon: HICON; const Hint: String = \'\'): Boolean; var NID : NotifyIconData; begin FillChar(NID, SizeOf(NotifyIconData), 0); with NID do begin cbSize := SizeOf(NotifyIconData); Wnd := Window; uID := IconID; if Hint = \'\' then begin uFlags := NIF_ICON; end{if} else begin uFlags := NIF_ICON or NIF_TIP; StrPCopy(szTip, Hint); end{else}; hIcon := Icon; end{with}; Result := Shell_NotifyIcon(NIM_ADD, @NID); end;
{adds an icon with a call-back message} function DZAddTrayIconMsg(const Window: HWND; const IconID: Byte; const Icon: HICON; const Msg: Cardinal; const Hint: String = \'\'): Boolean; var NID : NotifyIconData; begin FillChar(NID, SizeOf(NotifyIconData), 0); with NID do begin cbSize := SizeOf(NotifyIconData); Wnd := Window; uID := IconID; if Hint = \'\' then begin uFlags := NIF_ICON or NIF_MESSAGE; end{if} else begin uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP; StrPCopy(szTip, Hint); end{else}; uCallbackMessage := Msg; hIcon := Icon; end{with}; Result := Shell_NotifyIcon(NIM_ADD, @NID); end;
{removes an icon} function DZRemoveTrayIcon(const Window: HWND; const IconID: Byte): Boolean; var NID : NotifyIconData; begin FillChar(NID, SizeOf(NotifyIconData), 0); with NID do begin cbSize := SizeOf(NotifyIconData); Wnd := Window; uID := IconID; end{with}; Result := Shell_NotifyIcon(NIM_DELETE, @NID); end;
A few final notes: 1. There\'s absolutely no need to use the larger ver.5.0 structure NotifyIconData_50 to add or remove icons, the old smaller structure NotifyIconData is perfect for that, even if you want to balloon them. 2. For the callback message, I suggest using WM_APP + something. 3. Using different IconIDs, it is easy to add many different icons to tray from a single parent window and operate them by their IconIDs.
Du kan da tegne det du har lyst til, kan du ikke stjæle en screen capture at den ballon og se hvordan dan de tegner den, det skulle nok kunne lade sig gøre, du kan gemme din capture og forstøre det i et tegne program, så kan man tydeligt se hvordan den er tegnet.
martinlind>>For mig lyder det som om du ikke har set WindowsXP ballon hints eller skygger for den sags skyld. Skyggerne er semi-transparente med det der er bagved, og jeg har ingen anelse om hvordan jeg skulle kunne tegne det selv.
Men jeg har fået det til at virke som dkn skrev.
Den virker som sagt dog kun nede i sys-trayen, men det kan jeg godt leve med så.
Tak for hjælpen begge 2
til stoney>>Sorry, det er ikke det jeg leder efter.
Windows vil sikkert gerne hjælpe mig med at tegne den andre steder, men jeg ved bare ikke hvordan :)
/SpEeDy
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.