I am developing a docklet for stardock using it's SDK.
When the dock starts (during onCreate), I setup a timer to update the icon every second (since it will be a clock docklet).
This timer fires a function called UpdateClockData which in turn retrieves the current time and creates an Overlay Image to combine it with the clock background...
Gdiplus::Image *CreateClockOverlayImage(struct tm *tmCurrentTime, PDOCKLET_DATA lpData)
{
// Some initialization stuff
CHAR szBuffer[PRINT_BUFFER];
Gdiplus::Bitmap *imageReturn = new Bitmap(128, 128, PixelFormat32bppARGB);
Gdiplus::Status result;
Gdiplus::Graphics graphics(imageReturn);
graphics.SetInterpolationMode(InterpolationModeHighQuality);
graphics.SetSmoothingMode(SmoothingModeAntiAlias);
// Set the folder name where icons reside
char szFolderName[MAX_PATH];
_tcscpy_s(szFolderName, lpData->szFolderName);
// Set the full path to the image repository
char szImagePath[MAX_PATH];
DockletGetRelativeFolder(lpData->hwndDocklet, szImagePath);
strcat_s(szImagePath, szFolderName);
strcat_s(szImagePath, "");
// Retrieve the image (of the digit to be shown)
char szImageName[MAX_PATH];
// Hour's 1st digit
int iHH1 = (lpData->bShow12HourFormat && (tmCurrentTime->tm_hour > 12)) ? (tmCurrentTime->tm_hour-12)/10 : tmCurrentTime->tm_hour/10;
sprintf_s(szImageName, "%s%d.png", szImagePath, iHH1);
// Open the PNG file
wchar_t *pFile;
pFile = ConvertToWCharString(szImageName);
Gdiplus::Bitmap *bitmap;
bitmap = Gdiplus::Bitmap::FromFile(pFile, FALSE);
result = bitmap->GetLastStatus();
// Draw the PNG
if (result == Gdiplus::Ok)
graphics.DrawImage(bitmap, Gdiplus::Rect(26, 31, bitmap->GetWidth()/2, bitmap->GetHeight()/2));
else
{
char szLabel[LABEL_SIZE];
sprintf_s(szLabel, "Error loading digit: %S, %d", pFile, result);
DockletSetLabel(lpData->hwndDocklet, szLabel);
}
delete bitmap;
// Ohter digits processed the same way ...
return imageReturn;
}
This code is called from my update tread which is invokead on each timer event:
DWORD WINAPI UpdateClockDataThread(LPVOID lpInput)
{
PDOCKLET_DATA lpData = (PDOCKLET_DATA) lpInput;
if (!lpData)
return 0;
// Retrieve the time & date parameters
_tsetlocale(LC_ALL, _T(""));
time_t currentTime = time(NULL);
struct tm tmCurrentTime;
localtime_s(&tmCurrentTime, ¤tTime);
// Set the docklet label to current date & time
char szLabel[LABEL_SIZE];
strftime(szLabel, sizeof(szLabel), "%x, %X", &tmCurrentTime);
DockletSetLabel(lpData->hwndDocklet, szLabel);
//Create an overlay image and set it on top of our loaded file image.
DockletSetImageOverlay(lpData->hwndDocklet, CreateClockOverlayImage(&tmCurrentTime, lpData));
//Exit the thread
CloseHandle(lpData->hUpdateThread);
lpData->hUpdateThread = NULL;
ExitThread(0);
return 0;
}
The problem I am facing is that whenever the docklet loads with ObjectDock for the fist time (during session start - since object dock is configured to start automatically), I am getting the "Error loading digit:..." error, with result = 2, which means "invalid parameter". If I close object dock, and open it again, then the docklet loads the PNG files without problems, configuring stardock not to open automatically, will work too.
Only if objectdock is started automatically, then de docklet will not load well.
You can download my (under development docklet) from:
http://www.feterspace.com.mx/downloads/DigitalClock.zip
So you can test what I have tried to explain.
Am I doing something wrong here? It is odd that removing the docklet and adding it again, or simply restarting objectdock will not yield the error. I have checked on the image path and it is not wrong!
Any tips?
Aqua-Soft Forums