Форум: "WinAPI";
Текущий архив: 2006.11.12;
Скачать: [xml.tar.bz2];
ВнизКак обработать события клика по balloon tips (вспл. посдк.win xp) Найти похожие ветки
← →
pioner85 (2006-06-28 13:56) [0]сами всплывающие подсказки сделал.. подскажите как теперь отловить кликнули по ней или закрыли и выполнять при этом нужные действия
← →
jonni © (2006-06-28 16:31) [1]a eto zavisit ot togo kak i iz chego ti sdelal всплывающие подсказки
← →
pioner85 (2006-06-29 06:23) [2]вот код:
uses ShellAPI;
..
const
MYWM_NOTIFYICON = WM_USER + 300;
MyIconID = 300;
WM_TRAYMSG = WM_USER + 400;
NIIF_NONE = $00000000;
NIIF_INFO = $00000001;
NIIF_WARNING = $00000002;
NIIF_ERROR = $00000003;
NIF_STATE = $00000008;
NIF_INFO = $00000010;
NIF_GUID = $00000020;
type
TBalloonHintIcon = (bitNone, bitInfo, bitWarning, bitError);
TBalloonHintTimeOut = 10..60;
TTimeoutOrVersion = record
case Integer of
0: (uTimeout: UINT);
1: (uVersion: UINT);
end;
TNotifyIconDataEx = record
cbSize: DWORD;
Wnd: HWND;
uID: UINT;
uFlags: UINT;
uCallbackMessage: UINT;
hIcon: HICON;
szTip: array[0..127] of AnsiChar; // Previously 64 chars, now 128
dwState: DWORD;
dwStateMask: DWORD;
szInfo: array[0..255] of AnsiChar;
TimeoutOrVersion: TTimeoutOrVersion;
szInfoTitle: array[0..63] of AnsiChar;
dwInfoFlags: DWORD;
{$IFDEF _WIN32_IE_600}
guidItem: TGUID;
{$ENDIF}
end;
...
var
...
TrayData : TNotifyIconDataEx;
TrayEnabled : Boolean = false;
...
function MakeTrayIcon(ParentWnd: HWND; uID: integer; Icon: HICON; Hint : String) : boolean;
VAR tnid: TNOTIFYICONDATA;
begin
ZeroMemory(@TrayData, SizeOf(TNotifyIconData{Ex}));
with TrayData do begin
cbSize := SizeOf(TrayData);
Wnd := ParentWnd;
uID := MyIconID;
uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
uCallbackMessage := WM_TRAYMSG;
hIcon := Icon;
Move(PChar(Hint)^, szTip, length(Hint));
end;
TrayEnabled := Shell_NotifyIcon(NIM_ADD, @TrayData);
Result := TrayEnabled;
end;
FUNCTION UpdateTrayHint(wnd: HWND; uID: integer; Icon: HICON; const newHint : String): Boolean;
VAR tnid: TNOTIFYICONDATA;
BEGIN
tnid.cbSize := SizeOf(TNOTIFYICONDATA);
Move(PChar(newHint)^, TrayData.szTip, length(newHint));
tnid.Wnd := wnd;
tnid.uID := uID;
tnid.uFlags := NIF_MESSAGE OR NIF_ICON OR NIF_TIP;
tnid.uCallbackMessage := MYWM_NOTIFYICON;
tnid.hIcon := Icon;
Lstrcpyn(tnid.szTip, PChar(newHint), SizeOf(tnid.szTip));
Result := Shell_NotifyIcon(NIM_MODIFY, @tnid);
end;
function HideBalloonHint(const ParentWnd : HWND) : boolean;
var
NID : TNotifyIconData{Ex};
begin
NID.cbSize := SizeOf(NID);
NID.Wnd := ParentWnd;
NID.uID := MyIconID;
NID.uFlags := NIF_INFO;
NID.szInfo := "";
Result := Shell_NotifyIcon(NIM_MODIFY, @NID);
end;
function ShowBalloonHint(const ParentWnd : HWND;
const Title, Text: String;
const IconType: TBalloonHintIcon;
const TimeoutSecs: TBalloonHintTimeOut): boolean;
const
aBalloonIconTypes: array[TBalloonHintIcon] of Byte = (NIIF_NONE, NIIF_INFO, NIIF_WARNING, NIIF_ERROR);
var
NID : TNotifyIconData{Ex};
begin
HideBalloonHint(ParentWnd);
NID.cbSize := SizeOf(NID);
NID.Wnd := ParentWnd;
NID.uID := MyIconID;
NID.uFlags := NIF_INFO;
StrLCopy(NID.szInfo, PChar(Text), SizeOf(NID.szInfo)-1);
StrLCopy(NID.szInfoTitle, PChar(Title), SizeOf(NID.szInfoTitle)-1);
NID.TimeoutOrVersion.uTimeout := TimeoutSecs *1000 ;
NID.dwInfoFlags := aBalloonIconTypes[IconType];
Result := Shell_NotifyIcon(NIM_MODIFY, @NID);
end;
← →
pioner[72ru] © (2006-06-30 10:32) [3]Удалено модератором
← →
jonni © (2006-06-30 14:11) [4]to: pioner85
ya skinul na milo
← →
pioner[72ru] © (2006-07-03 09:23) [5]вот если кому интересно, может пригодится:
...
const
NIF_INFO = $10;
NIF_MESSAGE = 1;
NIF_ICON = 2;
NOTIFYICON_VERSION = 3;
NIF_TIP = 4;
NIM_SETVERSION = $00000004;
NIM_SETFOCUS = $00000003;
NIIF_INFO = $00000001;
NIIF_WARNING = $00000002;
NIIF_ERROR = $00000003;
NIN_BALLOONSHOW = WM_USER + 2;
NIN_BALLOONHIDE = WM_USER + 3;
NIN_BALLOONTIMEOUT = WM_USER + 4;
NIN_BALLOONUSERCLICK = WM_USER + 5;
NIN_SELECT = WM_USER + 0;
NINF_KEY = $1;
NIN_KEYSELECT = NIN_SELECT or NINF_KEY;
{define the callback message}
TRAY_CALLBACK = WM_USER + $7258;
{new NotifyIconData structure definition}
type
PNewNotifyIconData = ^TNewNotifyIconData;
TDUMMYUNIONNAME = record
case Integer of
0: (uTimeout: UINT);
1: (uVersion: UINT);
end;
TNewNotifyIconData = record
cbSize: DWORD;
Wnd: HWND;
uID: UINT;
uFlags: UINT;
uCallbackMessage: UINT;
hIcon: HICON;
//Version 5.0 is 128 chars, old ver is 64 chars
szTip: array [0..127] of Char;
dwState: DWORD; //Version 5.0
dwStateMask: DWORD; //Version 5.0
szInfo: array [0..255] of Char; //Version 5.0
DUMMYUNIONNAME: TDUMMYUNIONNAME;
szInfoTitle: array [0..63] of Char; //Version 5.0
dwInfoFlags: DWORD; //Version 5.0
end;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
IconData: TNewNotifyIconData;
procedure SysTrayIconMsgHandler(var Msg: TMessage); message TRAY_CALLBACK;
procedure AddSysTrayIcon;
procedure ShowBalloonTips;
procedure DeleteSysTrayIcon;
public
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses ShellAPI;
procedure TForm1.SysTrayIconMsgHandler(var Msg: TMessage);
begin
case Msg.lParam of
WM_MOUSEMOVE:;
WM_LBUTTONDOWN:;
WM_LBUTTONUP:;
WM_LBUTTONDBLCLK:;
WM_RBUTTONDOWN:;
WM_RBUTTONUP:;
WM_RBUTTONDBLCLK:;
NIN_BALLOONSHOW:
ShowMessage("NIN_BALLOONSHOW");
NIN_BALLOONHIDE:
ShowMessage("NIN_BALLOONHIDE");
NIN_BALLOONTIMEOUT:
ShowMessage("NIN_BALLOONTIMEOUT");
NIN_BALLOONUSERCLICK:
ShowMessage("NIN_BALLOONUSERCLICK");
end;
end;
procedure TForm1.AddSysTrayIcon;
begin
IconData.cbSize := SizeOf(IconData);
IconData.Wnd := AllocateHWnd(SysTrayIconMsgHandler);
IconData.uID := 0;
IconData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
IconData.uCallbackMessage := TRAY_CALLBACK; message
IconData.hIcon := Application.Icon.Handle;
IconData.szTip := "Please send me email.";
if not Shell_NotifyIcon(NIM_ADD, @IconData) then
ShowMessage("add fail");
end;
procedure TForm1.ShowBalloonTips;
var
TipInfo, TipTitle: string;
begin
IconData.cbSize := SizeOf(IconData);
IconData.uFlags := NIF_INFO;
TipInfo := "Please send me email.";
strPLCopy(IconData.szInfo, TipInfo, SizeOf(IconData.szInfo) - 1);
IconData.DUMMYUNIONNAME.uTimeout := 3000;
TipTitle := "Happyjoe@21cn.com";
strPLCopy(IconData.szInfoTitle, TipTitle, SizeOf(IconData.szInfoTitle) - 1);
IconData.dwInfoFlags := NIIF_INFO;
Shell_NotifyIcon(NIM_MODIFY, @IconData);
IconData.DUMMYUNIONNAME.uVersion := NOTIFYICON_VERSION;
if not Shell_NotifyIcon(NIM_SETVERSION, @IconData) then
ShowMessage("setversion fail");
end;
procedure TForm1.DeleteSysTrayIcon;
begin
DeallocateHWnd(IconData.Wnd);
if not Shell_NotifyIcon(NIM_DELETE, @IconData) then
ShowMessage("delete fail");
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
AddSysTrayIcon;
ShowBalloonTips;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
DeleteSysTrayIcon;
end;
end.
Страницы: 1 вся ветка
Форум: "WinAPI";
Текущий архив: 2006.11.12;
Скачать: [xml.tar.bz2];
Память: 0.48 MB
Время: 0.049 c