unit TipTreeView;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls;
type
TInfoTipEvent = procedure(Sender: TObject; Item: TTreeNode;
var InfoTip: string) of object;
TTipTreeView = class(TTreeView)
private
FOnInfoTip: TInfoTipEvent;
published
property OnInfoTip: TInfoTipEvent read FOnInfoTip write FOnInfoTip;
public
procedure CMHintShow(var Message: TMessage); message CM_HINTSHOW;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TTipTreeView]);
end;
procedure TTipTreeView.CMHintShow(var Message: TMessage);
var
Item: TTreeNode;
ItemRect: TRect;
InfoTip: string;
begin
if Assigned(FOnInfoTip) then
with TCMHintShow(Message) do
begin
Item := GetNodeAt(HintInfo.CursorPos.X, HintInfo.CursorPos.Y);
if Item <> nil then
begin
InfoTip := Item.Text;
if Assigned(FOnInfoTip) then FOnInfoTip(Self, Item, InfoTip);
ItemRect := Item.DisplayRect(False);
ItemRect.TopLeft := ClientToScreen(ItemRect.TopLeft);
ItemRect.BottomRight := ClientToScreen(ItemRect.BottomRight);
with HintInfo^ do
begin
HintInfo^.CursorRect := ItemRect;
HintInfo^.HintStr := InfoTip;
HintPos.Y := CursorRect.Top + GetSystemMetrics(SM_CYCURSOR);
HintPos.X := CursorRect.Left + GetSystemMetrics(SM_CXCURSOR);
GetSystemMetrics(SM_CXCURSOR);
HintInfo^.HintMaxWidth := ClientWidth;
Message.Result := 0;
end
end;
end
else
inherited;
end;
end.
unit Unit1;
interface
uses CommCtrl, uProcessMemMgr,
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function ActiveCaption: string;
var
Handle: THandle;
Len: LongInt;
Title: string;
begin
Result := '';
Handle := GetForegroundWindow;
if Handle <> 0 then
begin
Len := GetWindowTextLength(Handle) + 1;
SetLength(Title, Len);
GetWindowText(Handle, PChar(Title), Len);
ActiveCaption := TrimRight(Title);
end;
end;
function GetStatusBarText(hStatusBarHandle: HWND; PanelNumber: Integer): string;
var
PMM: TProcessMemMgr;
NumberOfPanels, Len: Integer;
PrcBuf: PChar;
PartText: string;
begin
if hStatusBarHandle = 0 then Exit;
PMM := CreateProcessMemMgrForWnd(hStatusBarHandle);
try
NumberOfPanels := SendMessage(hStatusBarHandle, SB_GETPARTS, 0, 0);
if PanelNumber < NumberOfPanels then
begin
Len := LOWORD(SendMessage(hStatusBarHandle, SB_GETTEXTLENGTH, PanelNumber, 0));
if Len > 0 then
begin
PrcBuf := PMM.AllocMem(Len + 1);
SendMessage(hStatusBarHandle, SB_GETTEXT, PanelNumber, Longint(PrcBuf));
Result := PMM.ReadStr(PrcBuf);
PMM.FreeMem(PrcBuf);
end
else
begin
Result := '';
end;
end;
finally
PMM.Free;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
hWindow, hStatusBarHandle: HWND;
char1:pchar;
begin
char1 := pchar(activecaption);
hWindow:= FindWindow(nil, char1);
hStatusBarHandle := FindWindowEx(hWindow, 0, 'msctls_statusbar32', nil);
Form1.Caption := GetStatusBarText(hStatusBarHandle,0);
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,activex,shlobj,shellapi, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function SHILCreateFromPath(Path: Pointer; PIDL: PItemIDList; var Attributes: Cardinal): HResult; stdcall;
var
Form1: TForm1;
const IID_IQueryInfo: TGUID = '{DB8853E3-33CC-447E-84AA-FC319381A97B}';
// const IID_IQueryInfo: TGUID = '{84F26EA0-42A0-1069-A2E3-08002B30309D}';
implementation
const Shell32DLL = 'shell32.dll';
function SHILCreateFromPath(Path: Pointer; PIDL: PItemIDList; var Attributes: Cardinal): HResult; external Shell32DLL name 'SHILCreateFromPath';
{$R *.dfm}
function GetInfoTip( psf:IShellFolder; pidl:PItemIdList; pszText:LPTSTR; cchTextMax:integer):boolean;
var pqi:IQueryInfo;
pwszTip:PWideChar;
begin
Result:=False;
pszText:='';
if ( Assigned(pidl) )
then begin
if ( SUCCEEDED( psf.GetUIObjectOf( 0, 1, pidl, IID_IQueryInfo, nil, Pointer(pqi) ) ) )
then begin
// assuming Unicode
pqi.GetInfoTip( 0, pwszTip );
if ( Assigned(pwszTip) )
then begin
Result:=True;
lstrcpyn( pszText, pchar(pwszTip), cchTextMax );
//SHFree( pwszTip );
CoTaskMemFree(pwszTip);
end;
pqi._Release;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var infoTip:string;
var path:string[255];
shFolder:IShellFolder;
pidl:PITEMIDLIST;
a:cardinal;
begin
a:=0;
path:='c:\Design\Bird.EMB';
SHGetDesktopFolder( shFolder );
SHILCreateFromPath( @path, pidl, a );
GetInfoTip( shFolder, pidl, pchar(infoTip), 255 );
showmessage(infotip);
end;
end.
function SHFreeMem(var P: Pointer): Boolean;
var
Malloc: IMalloc;
begin
Result := False;
if P <> nil then
begin
if Succeeded(SHGetMalloc(Malloc)) and (Malloc.DidAlloc(P) > 0) then
begin
Malloc.Free(P);
P := nil;
Result := True;
end;
end;
end;
function SHGetItemInfoTip(const Folder: IShellFolder; Item: PItemIdList): string;
var
QueryInfo: IQueryInfo;
InfoTip: PWideChar;
begin
Result := '';
if (Item = nil) or (Folder = nil) then
Exit;
if Succeeded(Folder.GetUIObjectOf(0, 1, Item, IQueryInfo, nil,
Pointer(QueryInfo))) then
begin
if Succeeded(QueryInfo.GetInfoTip(0, InfoTip)) then
begin
Result := WideCharToString(InfoTip);
SHFreeMem(Pointer(InfoTip));
end;
end;
end;
if that's the step to get what you want, please indicate what's next?
Open in new window