Implemented Tooltip Popup for Clock to display current date

svn path=/trunk/; revision=5875
This commit is contained in:
Martin Fuchs 2003-08-26 22:37:20 +00:00
parent 51b70de9b7
commit 2d0cf5cb61
5 changed files with 57 additions and 1 deletions

View file

@ -15,3 +15,4 @@ _NO_COMUTIL
*.aps
*.ncb
*.plg
*.suo

View file

@ -29,6 +29,7 @@
#include "../utility/utility.h"
#include "../explorer.h"
#include "../globals.h"
#include "traynotify.h"
@ -277,10 +278,13 @@ NotifyIconSet::iterator NotifyArea::IconHitTest(const POINT& pos)
ClockWindow::ClockWindow(HWND hwnd)
: super(hwnd)
: super(hwnd),
_tooltip(hwnd)
{
*_time = _T('\0');
FormatTime();
_tooltip.add(_hwnd, _hwnd);
}
HWND ClockWindow::Create(HWND hwndParent)
@ -306,6 +310,23 @@ LRESULT ClockWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
return 0;
}
int ClockWindow::Notify(int id, NMHDR* pnmh)
{
if (pnmh->code == TTN_GETDISPINFO) {
LPNMTTDISPINFO pdi = (LPNMTTDISPINFO)pnmh;
SYSTEMTIME systime;
TCHAR buffer[64];
GetLocalTime(&systime);
GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &systime, NULL, buffer, 64);
_tcscpy(pdi->szText, buffer);
}
return 0;
}
void ClockWindow::TimerTick()
{
if (FormatTime())

View file

@ -114,9 +114,11 @@ struct ClockWindow : public Window
protected:
LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam);
int Notify(int id, NMHDR* pnmh);
bool FormatTime();
void Paint();
TCHAR _time[16];
ToolTip _tooltip;
};

View file

@ -653,3 +653,12 @@ void PictureButton::DrawItem(LPDRAWITEMSTRUCT dis)
DrawFocusRect(dis->hDC, &rect);
}
}
ToolTip::ToolTip(HWND owner)
: super(CreateWindowEx(WS_EX_NOPARENTNOTIFY, TOOLTIPS_CLASS, 0,
TTS_ALWAYSTIP, CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
owner, 0, g_Globals._hInstance, 0))
{
activate();
}

View file

@ -448,3 +448,26 @@ protected:
HICON _hIcon;
bool _flat;
};
struct ToolTip : public WindowHandle
{
typedef WindowHandle super;
ToolTip(HWND owner);
void activate(BOOL active=TRUE)
{
SendMessage(_hwnd, TTM_ACTIVATE, active, 0);
}
void add(HWND hparent, HWND htool, LPCTSTR txt=LPSTR_TEXTCALLBACK)
{
TOOLINFO ti = {
sizeof(TOOLINFO), TTF_SUBCLASS|TTF_IDISHWND/*|TTF_TRANSPARENT*/, hparent, (UINT)htool, 0, 0, 0, 0, 0, 0, 0
};
ti.lpszText = (LPTSTR) txt;
SendMessage(_hwnd, TTM_ADDTOOL, 0, (LPARAM)&ti);
}
};