How to manage PNG's in a Docklet?

I am developing a Docklet for stardock's ObjectDock, based on the samples provided in their SDK.

The problem I am facing is that I want to display a "windows" when the user clicks on the docklet icon so I might be able to show additional information (In my case, Wifi connection data like SSID and Authentication and Encryption details).

Right now I am using a modal dialog where the information is displayed, my first question is:

How could I place a PNG image in that dialog? I believe that the standard MFC C++ Picture Control only support BMP's, but I need to dynamically choose between several PNG's at run time so the right one is shown.

My second question is:

I would rather use a "custom" paint windows that might use some alpha tranparency and custom drawn "styled" text instead of the Windows Modal Dialog... how could I accomplish this?

I am not an experienced C++/MFC programmer (specially not at manipulating Windows and graphical elements), Where could I found information so I can get started with both tasks? Are there any Docklet programmers out there who would like to give me some advice?

Thank everybody.

#500372

Manipulation of PNGs under XP/C++ is best achieved with the GdiPlus library available at the MSDN. You'll need recent platform SDK headers for the transparency stuff if you stick to VC++6, but not newer than 2002 since the library format changed.

If you go the VC++7/8/9 way, MFC should contain everything you need for displaying Alpha blended windows.

#500558

@herd,

Thank you, I have been googling around the last several days... and found exaclty what you mention. Problem is that I am really a newbie MFC/GDI+ Programmer.

After reading a lot, I finally gave GDI+ a try (since my docklet already uses GDI+ for rendering some text and icons)... my docklet is right now a mix from the ObjectDock SDK sample (Weather sample) and the WLAN API sample from the Windows SDK 6.1.

So I decided to try to adapt Joe Woodbury's code (http://www.codeproject.com/KB/GDI-plus/cgdiplusbitmap.aspx) to my docklet environment. What I want to do right now is to update a dialog box with a PNG determined at run time (depending on the signal strength of the configured network connection).

In my setup, I respond to the user's click event by loading a Modal Dialog (that was declared as a resource in my code). What I want to do is to draw the icon at run time on the canvas of that dialog... a bit of my code is:

int CALLBACK InfoDocklet(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)

{

DOCKLET_DATA *lpData = (DOCKLET_DATA *) GetProp(hDlg, "lpData");

switch(iMsg)

{

case WM_INITDIALOG:

{

SetProp(hDlg, "lpData", (HANDLE) (char*) lParam);

lpData = (DOCKLET_DATA *) GetProp(hDlg, "lpData");

if(!lpData)

return TRUE;

// Do stuff to update Dialogs text controls...

//Determine image file image to use

wchar_t *pFile; // will store the PNG path & name

CGdiPlusBitmap *bitmap; // From the codeproject project

bitmap = new CGdiPlusBitmap;

if (bitmap->Load(pFile))

{

Gdiplus::Graphics graphics(hDlg);

graphics.DrawImage(*bitmap, 0, 0);

}

delete bitmap;

break;

}

case WM_COMMAND:

switch(LOWORD(wParam))

{

case IDOK:

EndDialog(hDlg, 0);

return TRUE;

}

break;

case WM_DESTROY:

break;

}

return FALSE;

}

Although the code compiles without problems It does not draw the bitmap at all. I am not sure if I am missing something...

#500586

Read even more MSDN ;)

case WM_INITDIALOG: is where you create your controls, give one of 'em the focus and never be called again. Load the Image there but keep it as a member variable of DOCKLET_DATA. Create a child window, e.g. a label with a nice border.

Open a new case WM_PAINT: for doing the actual drawing; graphics(hDlg) will likely fail - a dialog resource is definitely not a device context.

hth,

herd

#500609

@herd,

Well, I think I will have to spend more time at reading... thanks for your advice.

Looking at some samples it seems that they override the OnPaint method for a class based on the DIALOG Template, this is by running the MFC class wizard at the Dialog Resource. then adding a private member (for the bitmap).

I think this is what you are talking about, don`t you?

My docklet code will then instantiate a class of this "CMyDialog" class and call it´s showmodal method... I think.

Well sorry, but I am really a newbie on "PAINTING" windows directly.

#500624

Yes exactly... MFC is a nice shortcut to getting things done; it will turn WM_INITDIALOG into OnInitDialog and cast the w/lParams for you.

Override OnPaint instead of WM_PAINT but be aware that there is the old C-Style underneath --

If you know C++ to the template level, maybe diving into ATL/WTL is more of your liking than MFC.

#500793

Where could I found more info (I mean newbie posts or articles) on this subjects... I ran the MCF class wizard on my Dialog resource and now the program will not compile. So I believe that, 1st, I need to understand what I am supposed to do, and not just get code from a sample and try to mix it with mine.

Thanks for being so helpful.

#500824

I'd rather suggest turning off the computer while reading a book on the subject (at a public library) or doing real-world talking to someone who is knowledgeable but not too far away from yourself.

From your mates, best kind of learning is.

#500835

What book (or books) would you advice would be a good starting point... there are no such books on libraries here in Mexico, but there's always an Amazon web page near us!

#500898