[WARNING!] Long Post! [/WARNING!]

I have recently got a Pocket PC phone and have managed to cobble together a DLL to display a simple text message on the Today Screen. What I really would like is the time displayed in a large font as I had on my SmartPhone 2002.

Here is my effort so far...

#include <windows.h>  // Standard Header
#include <todaycmn.h> // Today API
#include <aygshell.h> // Shell Functions

const TCHAR g_szWndClass[] = _T("myToday2003ItemWnd");
const TCHAR g_szDisplayString[] = _T("My Time Today Item");

HINSTANCE g_hInstance = NULL;

HWND APIENTRY InitializeCustomItem(TODAYLISTITEM *ptli, HWND hParent)
{
	HWND hwnd = NULL;

	if(ptli->fEnabled)
	{
		hwnd = CreateWindow(
			g_szWndClass,
			_T(""),
			WS_VISIBLE | WS_CHILD,
			0,
			0,
			GetSystemMetrics(SM_CXSCREEN),
			50,
			hParent,
			NULL,
			g_hInstance,
			NULL);
	}
	return hwnd;
}

BOOL APIENTRY CustomItemOptionsDlgProc(HWND hwnd, UINT msg, UINT wParam, LONG lParam)
{
	switch(msg) 
	{
		case WM_INITDIALOG:
		{
			SHINITDLGINFO shidi;
			shidi.dwMask = SHIDIM_FLAGS;
			shidi.hDlg = hwnd;
			shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIZEDLGFULLSCREEN;
			SHInitDialog(&shidi);
		}
		break;

		case WM_COMMAND:
			switch(LOWORD(wParam)) 
			{
				case IDOK:
					EndDialog(hwnd, LOWORD(wParam));
				break;
			}
		break;

		default:
			return FALSE;
   }
   return TRUE;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg) 
	{
		case WM_PAINT:
		{
			PAINTSTRUCT ps;
			HDC hdc = BeginPaint(hwnd, &ps);

			COLORREF crText = SendMessage(GetParent(hwnd), TODAYM_GETCOLOR,	TODAYCOLOR_TEXT, 0);
			SetTextColor(hdc, crText);

			RECT rcClient;
			GetClientRect(hwnd, &rcClient);
			SetBkMode(hdc, TRANSPARENT);
//*** Would Like to display the time here ***
			DrawText(hdc, g_szDisplayString, -1, &rcClient, DT_WORDBREAK | DT_CENTER);			
			EndPaint(hwnd, &ps);
		}
		break;

		case WM_ERASEBKGND:
		{
			TODAYDRAWWATERMARKINFO dwi;

			dwi.hwnd = hwnd;
			dwi.hdc = (HDC)wParam;

			GetClientRect(hwnd, &dwi.rc);
			SendMessage(GetParent(hwnd), TODAYM_DRAWWATERMARK, 0, 
				(LPARAM)&dwi);
		}
		return TRUE;
		
		case WM_LBUTTONUP:
		{
			MessageBox(hwnd, _T("You clicked my Today Item!"),_T("Today 2003"), MB_OK | MB_ICONINFORMATION);
		}
		break;
		
		case WM_TODAYCUSTOM_QUERYREFRESHCACHE:
		{
			TODAYLISTITEM *ptli = (TODAYLISTITEM*)wParam;

			BOOL bUpdated = FALSE;
			RECT rcText = {0, 0, GetSystemMetrics(SM_CXSCREEN), 0};

			HDC hdc = GetDC(hwnd);
//*** Would Like to display the time here ***
			DrawText(hdc, g_szDisplayString, -1, &rcText, DT_WORDBREAK | DT_CALCRECT);
			ReleaseDC(hwnd, hdc);

			if(ptli->cyp != (ULONG)rcText.bottom)
			{
				ptli->cyp = rcText.bottom;
				bUpdated = TRUE;
			}

			return bUpdated;
		}
		break;
		
		case WM_TODAYCUSTOM_CLEARCACHE:
			// Here you can free up any additional resources 
			// that you may have allocated, such as bitmaps.
		break;
		
		default:
			return DefWindowProc(hwnd, msg, wParam, lParam);
	}
	return 0;
}

BOOL WINAPI DllMain(HANDLE hInstance, DWORD dwReason, LPVOID pvUnused)
{
	switch(dwReason)
	{
		case DLL_PROCESS_ATTACH:
		{
			g_hInstance = (HMODULE)hInstance;

			WNDCLASS wc;
			ZeroMemory(&wc, sizeof(wc));

			wc.style = CS_HREDRAW | CS_VREDRAW;
			wc.lpfnWndProc = (WNDPROC)WndProc;
			wc.hInstance = g_hInstance;
			wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
			wc.lpszClassName = g_szWndClass;

			return (RegisterClass(&wc) != NULL);
		}
		break;

		case DLL_PROCESS_DETACH:
		{
			UnregisterClass(g_szWndClass, g_hInstance);
		}
		break;
	}
	return FALSE;
}

I've tried SYSTEMTIME st, GetSystemTime(&st) but the members I'm interested in (wHour and wMinute) are refusing all attempts to convert into a form I can use with the DrawText() function. Coersion throws up errors - pointers to unsigned. Conversion throws up possible data loss.

Help!

Any hints/pointers(Noooo! hate them! <G>) gratefully received

TIA

Si

PS It's just ocurred to me that I'll need to trigger CALLBACK WndProc to update the time displayed...any ideas? Thanks!

Well, in the absence of a proper library, you can write a specialized conversion yourself without any trouble:

void wtos ( WORD w, PTCHAR s )
{
  s[2] = '\0';
  s[1] = w % 10 + '0';
  s[0] = w / 10 % 10 + '0';
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.