I'm working on a windows program whose's goal is to display image buttons using GDIPlus and the Windows header file.
The images are attached to an global CAutoPtr array. Inside the button callback, I handle the WM_PAINT message by searching the image array (imageList) using the button's identifier (GetDlgCtrlID(hWnd)).
I am able to paint with the first image in imageList, however, when I try to paint the next button with imageList[2], it does not show any image.
Where exactly is the problem and why can I not display any image besides whatever's in the first slot of imageList?
Thank you!
This handles all of the button messages.
CAutoPtr<Gdiplus::Image> typedef GdiplusImagePtr;
GdiplusImagePtr imageList[50];
Rect imagePositions[50];
LRESULT CALLBACK CustomButtonProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
switch (msg) {
case WM_CREATE:
{
// Same as WM_PAINT
break;
}
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC newDC = BeginPaint(hWnd, &ps);
Gdiplus::Graphics newGraphics(hWnd);
newGraphics.DrawImage(imageList[GetDlgCtrlID(hWnd)], imagePositions[GetDlgCtrlID(hWnd)]);
EndPaint(hWnd, &ps);
ReleaseDC(hWnd, GetDC(hWnd));
DeleteDC(newDC);
break;
}
return CallWindowProc(customButtonProc, hWnd, msg, wp, lp);
}
I use this line of code to attach an image to imageList. I confirmed that imageList does hold the other images; I just can not display them.
imageList[1].Attach(new Gdiplus::Bitmap(L"TestImage.png"));