Форум: "WinAPI";
Текущий архив: 2007.04.29;
Скачать: [xml.tar.bz2];
ВнизBallonHint Найти похожие ветки
← →
RealGanj (2006-12-03 19:33) [0]Есть пример, как создавать BallonHint для WinXP в Delphi:
................................
{define the callback message}
TRAY_CALLBACK = WM_USER + $7258;
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;
....................
{AddSysTrayIcon procedure add an icon to notification area}
procedure TForm1.AddSysTrayIcon;
begin
IconData.cbSize := SizeOf(IconData);
IconData.Wnd := AllocateHWnd(SysTrayIconMsgHandler);
{SysTrayIconMsgHandler is then callback message" handler}
IconData.uID := 0;
IconData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
IconData.uCallbackMessage := TRAY_CALLBACK; //user defined callback message
IconData.hIcon := Application.Icon.Handle; //an Icon"s Handle
IconData.szTip := "Please send me email.";
if not Shell_NotifyIcon(NIM_ADD, @IconData) then
ShowMessage("add fail");
end;
{ShowBalloonTips procedure carry out the new feature: Balloon Tips}
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; //NIIF_ERROR; //NIIF_WARNING;
Shell_NotifyIcon(NIM_MODIFY, @IconData);
{in my testing, the following code has no use}
IconData.DUMMYUNIONNAME.uVersion := NOTIFYICON_VERSION;
if not Shell_NotifyIcon(NIM_SETVERSION, @IconData) then
ShowMessage("setversion fail");
end;
{here"s the deletion procedure}
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.
Мне нужно перенести его на С++Builder. Пишу:
#include <vcl.h>
#pragma hdrstop
#include "MainUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
const TRAY_CALLBACK = WM_USER + 0x7258;
//---------------------------------------------------------------------------
struct TDummyUnionName{
UINT uTimeout;
UINT uVersion;
};
struct TNewNotifyIconData{
TDummyUnionName DummyUnionName;
DWORD cbSize;
HWND Wnd;
UINT uID;
UINT uFlags;
UINT uCallbackMessage ;
HICON hIcon;
//Version 5.0 is 128 chars, old ver is 64 chars
char szTip[127];
DWORD dwState; //Version 5.0
DWORD dwStateMask; //Version 5.0
char szInfo[255]; //Version 5.0
char szInfoTitle[63]; //Version 5.0
DWORD dwInfoFlags; //Version 5.0 */
}*NEWPNOTIFYICONDATA;;
typedef TNewNotifyIconData* PNewNotifyIconData;
TNewNotifyIconData IconData;
void AddNIM()
{
IconData.cbSize = sizeof(IconData);
IconData.Wnd = AllocateHWnd(Form1->SysTrayIconMsgHandler);
IconData.uID = 0;
IconData.uFlags = NIF_ICON || NIF_MESSAGE || NIF_TIP;
IconData.uCallbackMessage = TRAY_CALLBACK; //user defined callback message
IconData.hIcon = Application->Icon->Handle; //an Icon"s Handle
AnsiString tmp="Please send me email.";
StrPLCopy(IconData.szTip, tmp, sizeof(IconData.szTip) - 1);
NOTIFYICONDATA* dt=reinterpret_cast <NOTIFYICONDATA*>(&IconData);
if (!Shell_NotifyIcon(NIM_ADD, dt))
ShowMessage("add fail");
}
void ShowBalloonTips()
{
AnsiString TipInfo, TipTitle;
IconData.cbSize=sizeof(IconData);
IconData.uFlags=NIF_INFO;
TipInfo = "My test";
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;
NOTIFYICONDATA* dt=reinterpret_cast <NOTIFYICONDATA*>(&IconData);
if (!Shell_NotifyIcon(NIM_ADD,dt)) ShowMessage("Bad");
IconData.DummyUnionName.uVersion = NOTIFYICON_VERSION;
//if (!Shell_NotifyIcon(NIM_SETVERSION, dt))
// ShowMessage("setversion fail");
}
void DeleteIcon()
{
DeallocateHWnd(IconData.Wnd);
NOTIFYICONDATA* dt=reinterpret_cast <NOTIFYICONDATA*>(&IconData);
if (!Shell_NotifyIcon(NIM_DELETE, dt))
ShowMessage("delete fail");
}
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
AddNIM();
//ShowBalloonTips();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SysTrayIconMsgHandler(TMessage &Msg )
{
;
}
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
DeleteIcon();
}
Проблема в вызове Shell_NotifyIcon(NIM_MODIFY, &IconData);
[C++ Error] MainUnit.cpp(107): E2034 Cannot convert "TNewNotifyIconData *" to "_NOTIFYICONDATAA *"
Делаю так:NOTIFYICONDATA* dt=reinterpret_cast <NOTIFYICONDATA*>(&IconData);
if (!Shell_NotifyIcon(NIM_MODIFY, dt))
ShowMessage("mod fail");
условие истина и показывается сообщение:
mod fail.
я понял, что проблема в переводеTDUMMYUNIONNAME = record
case Integer of
0: (uTimeout: UINT);
1: (uVersion: UINT);
end;
на с++.
Как это можно обойти?
← →
RealGanj (2006-12-03 19:55) [1]Все. разобрался сам.
← →
Psychedelic © (2006-12-04 17:56) [2]Ну понаписали. Создается как обычный хинт, но ставим класс ballon
CreateWindowEx(0, TOOLTIPS_CLASS, "",
WS_POPUP{ or WS_BORDER}{0} or TTS_BALLOON, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, AParent.Handle, 0, HInstance, nil);
← →
Psychedelic © (2006-12-04 17:57) [3]TTS_BALLOON = $40;
Страницы: 1 вся ветка
Форум: "WinAPI";
Текущий архив: 2007.04.29;
Скачать: [xml.tar.bz2];
Память: 0.47 MB
Время: 0.045 c