program SongTickerProf;
{$APPTYPE GUI}
uses
Windows,
Messages,
ShellApi;
{$R Resource\icon.res}
{$INCLUDE Include\nonVCL.pas}
const
WM_TRAY = 66672;
ClassName = '
ST_Root_Wnd_Class';
width = 400;
height = 300;
var
WndClassMain: TWndClassEx;
msg: TMSG;
rgnConfig,
rgnTray,
rgnExit: hRgn;
trayIco: TNotifyIconData;
////////////////////////////////////////////////////////////////////////////////
// Funktion : AddTrayIcon
// Kommentar : Trayicon erstellen
function AddTrayIcon(wnd: HWND): Bool;
begin
Result := False;
// Iconinformationen setzen
trayIco.cbSize := SizeOf(TNotifyIconData);
trayIco.Wnd := wnd;
trayIco.uFlags := NIF_MESSAGE
or NIF_ICON
or NIF_TIP;
trayIco.uCallbackMessage := WM_TRAY;
trayIco.hIcon := LoadIcon(hInstance, MakeIntResource(1));
trayIco.szTip := '
Song Ticker Beta for WinAmp';
// Icon setzen
if Shell_NotifyIcon(NIM_ADD, @trayIco)
then
Result := True;
end;
////////////////////////////////////////////////////////////////////////////////
// Funktion : RemoveTrayIcon
// Kommentar : Trayicon entfernen
function RemoveTrayIcon(wnd: HWND): Bool;
begin
Result := False;
// Iconinformationen setzen
trayIco.cbSize := SizeOf(TNotifyIconData);
trayIco.Wnd := wnd;
// Icon entfernen
if Shell_NotifyIcon(NIM_DELETE, @trayIco)
then
Result := True;
end;
////////////////////////////////////////////////////////////////////////////////
// Funktion : WndFunc
// Kommentar : Nachrichtenschleife des Hauptfensters
function WndFunc(hwnd: HWND; uMsg: UINT; wParam: WPARAM;
lParam: LPARAM): LResult;
stdcall;
var
wnd : THandle;
rec : TRect;
rgn : hRgn;
hBmp : hBitmap;
style : Cardinal;
p : TPoint;
begin
case uMsg
of
WM_CREATE:
begin
// Fenster zentrieren
wnd := FindWindow('
Progman',
nil);
CenterWindow(wnd, hwnd, HWND_TOP);
// Fenster style richtig einstellen
style := GetWindowLong(hwnd, GWL_STYLE);
SetWindowLong(hwnd, GWL_STYLE, style
and (
not WS_BORDER)
and (
not WS_DLGFRAME));
// Static für den Hintergrund erstellen
CreateWindow('
STATIC',
nil, WS_VISIBLE
or WS_CHILD
or SS_BITMAP,
0, 0, width, 55, hwnd, 100, hInstance,
nil);
// Hintergrund laden
hBmp := LoadImage(hInstance, '
BG\BG.bmp', IMAGE_BITMAP,
width, height, LR_LOADFROMFILE);
SendMessage(GetDlgItem(hwnd, 100), STM_SETIMAGE, IMAGE_BITMAP, hBmp);
// Rund ecken rulez :D
rgn := CreateRoundRectRgn(0, 0, width, height, 20, 20);
SetWindowRgn(hwnd, rgn, True);
// Regionen für "Controls" erstellen
rgnConfig := CreateRectRgn(6, 272, 76, 289);
rgnTray := CreateRectRgn(93, 272, 163, 289);
rgnExit := CreateRectRgn(286, 274, 357, 391);
end;
WM_LBUTTONUP:
begin
// Klick auf "Controls" abfangen
GetWindowRect(hwnd, rec);
GetCursorPos(p);
p.X := p.X - rec.Left - 5;
p.Y := p.Y - rec.Top - 5;
// Config Button
if PtInRegion(rgnConfig, p.X, p.Y)
then
MessageBox(hwnd, '
CONFIG',
nil, MB_OK);
// TODO: Configuration !!! <----
// Tray Button
if PtInRegion(rgnTray, p.X, p.Y)
then
begin
ShowWindow(hwnd, SW_HIDE);
AnimateToTray(hwnd);
AddTrayIcon(hwnd);
end;
// Exit Button
if PtInRegion(rgnExit, p.X, p.Y)
then
SendMessage(hwnd, WM_CLOSE, 0, 0);
end;
WM_MOUSEMOVE:
begin
ReleaseCapture;
SendMessage(hwnd, WM_SYSCOMMAND, $F012, 0);
end;
WM_TRAY:
begin
if lParam = WM_LBUTTONDBLCLK
then
begin
ShowWindow(hwnd, SW_SHOW);
RemoveTrayIcon(hwnd);
end;
end;
WM_CLOSE:
begin
RemoveTrayIcon(hwnd);
PostQuitMessage(0);
end;
else
Result := DefWindowProc(hwnd, uMsg, wParam, lParam);
end;
end;
begin
RegisterWindowClass(WndClassMain, @WndFunc, ClassName,
IDC_ARROW, LoadIcon(hInstance, MakeIntResource(1)), COLOR_WINDOW);
CreateWindow(ClassName, '
SongTicker', WS_VISIBLE
or WS_SYSMENU,
0, 0, width, height, 0, 0, hInstance,
nil);
MessageLoop(msg);
end.