Draw a GDI+ PNG in a control?

Questions regarding game mechanics and graphic programming should go here.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Draw a GDI+ PNG in a control?

Postby I_want_to_learn » Wed Dec 24, 2008 8:48 pm

How can i draw a transparent PNG to a control with GDI+?

I know how to draw a PNG to the Dialog box but not to a control.

This is what i use to draw a PNG to the dialog Box
Code: Select all
#include <gdiplus.h>

#pragma comment (lib,"gdiplus.lib")

using namespace Gdiplus;

... all MFC stuff

void CAppName::OnPaint()
       CPaintDC dc(this); // device context for painting

   if (IsIconic())

      SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

      // Center icon in client rectangle
      int cxIcon = GetSystemMetrics(SM_CXICON);
      int cyIcon = GetSystemMetrics(SM_CYICON);
      CRect rect;
      int x = (rect.Width() - cxIcon + 1) / 2;
      int y = (rect.Height() - cyIcon + 1) / 2;

      // Draw the icon
      dc.DrawIcon(x, y, m_hIcon);

      //heres where i put the code to paint a PNG on runtime

       Rect rect(20,20,50,50);
       Graphics grpx(dc);
       Image * Img = Image::FromFile(L"DriveIcon.png",FALSE);

How can i use that to draw to a Control?
Posts: 7
Joined: Thu Dec 11, 2008 10:00 pm

Return to Games and Graphics

Who is online

Users browsing this forum: No registered users and 1 guest