How to show CStatic control using Gdiplus::Graphics class on to a ScrollView in MFC application

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left Hello members,<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left I am using MFC for my project in visual studio 2008.<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left I have a scroll view.<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left I am showing bmp/jpg files on it by using Graphics class provided by Gdiplus namespace.<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left The code for that is as below.<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left //----------------------------------------------------------------<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<div style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left; margin:5px 20px 20px
<div style="font-size:11px; color:gray; margin-bottom:2px <abbr title="C++ or C plus plus CPP</abbr> / <abbr title="C++ Programming Language C++</abbr> / <abbr title="C Programming Language C</abbr> Code:
<code style="margin:0px
<pre class="x_gid x_cpp" style="border-style:solid; border-width:6px 2px 2px; padding:5px 15px; font-size:13px; width:612px; color:#603913; background-color:#fbfaf4; border-color:navy <span class="x_k" style="color:#800080; font-weight:bold void CLayer::MyDrawTransparent(CDC* pDC, <span class="x_k" style="color:#800080; font-weight:bold int XDest, <span class="x_k" style="color:#800080; font-weight:bold int YDest, <span class="x_k" style="color:#800080; font-weight:bold int nDestWidth, <span class="x_k" style="color:#800080; font-weight:bold int nDestHeight)
{
Graphics graphics(pDC->GetSafeHdc());

<span class="x_c" style="color:#009900 // Create a Rect object that specifies the destination of the image.
Rect destRect(XDest, YDest, nDestWidth, nDestHeight);
graphics.DrawImage(m_pGDIPlusBitmap->m_pBitmap, destRect);
}[/code]
[/code]
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left CLayer is my user defined class.<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left I am receiving CDC in this function.<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left m_pGDIPlusBitmap->m_pBitmap populated by bmp or jpg file during runtime.<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left //-----------------------------------------------------------------<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left Now I want to show an animated gif file. After a lot of search, I found a class called CPictureEx derived from CStatic
class. This CPictureEx class is responsible for loading given gif file and play it. Code for this is as below.<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left //------------------------------------------------------------------<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left //declare object of this class in header file.<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<div style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left; margin:5px 20px 20px
<div style="font-size:11px; color:gray; margin-bottom:2px <abbr title="C++ or C plus plus CPP</abbr> / <abbr title="C++ Programming Language C++</abbr> / <abbr title="C Programming Language C</abbr> Code:
<code style="margin:0px
<pre class="x_gid x_cpp" style="border-style:solid; border-width:6px 2px 2px; padding:5px 15px; font-size:13px; width:612px; color:#603913; background-color:#fbfaf4; border-color:navy CPictureEx m_Picture;[/code]
[/code]
<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left //In cpp file<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<div style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left; margin:5px 20px 20px
<div style="font-size:11px; color:gray; margin-bottom:2px <abbr title="C++ or C plus plus CPP</abbr> / <abbr title="C++ Programming Language C++</abbr> / <abbr title="C Programming Language C</abbr> Code:
<code style="margin:0px
<pre class="x_gid x_cpp" style="border-style:solid; border-width:6px 2px 2px; padding:5px 15px; font-size:13px; width:612px; color:#603913; background-color:#fbfaf4; border-color:navy <span class="x_k" style="color:#800080; font-weight:bold void CMyScrollView::OnDraw(CDC* pDC)
{
m_Picture.Create(_T(<span class="x_q" style="color:#5555ff "Present"), WS_CHILD | WS_VISIBLE | SS_BLACKFRAME,CRect(<span class="x_n" style="color:navy 200, <span class="x_n" style="color:navy 100, <span class="x_n" style="color:navy 0, <span class="x_n" style="color:navy 0),cwnd);
<span class="x_k" style="color:#800080; font-weight:bold if (m_Picture3.Load(_T(<span class="x_q" style="color:#5555ff "D:\eyes.gif")))
m_Picture3.Draw();
}[/code]
[/code]
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left I am using a Boolean variable to make the control created once.<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left Here it is working fine, and I am able to see gif file on scroll view with animation. <br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left //------------------------------------------------------------------ <br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left Now I am facing problem how to load m_Picture by using Gdiplus::Graphics class inside the below function.<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<div style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left; margin:5px 20px 20px
<div style="font-size:11px; color:gray; margin-bottom:2px <abbr title="C++ or C plus plus CPP</abbr> / <abbr title="C++ Programming Language C++</abbr> / <abbr title="C Programming Language C</abbr> Code:
<code style="margin:0px
<pre class="x_gid x_cpp" style="border-style:solid; border-width:6px 2px 2px; padding:5px 15px; font-size:13px; width:612px; color:#603913; background-color:#fbfaf4; border-color:navy <span class="x_k" style="color:#800080; font-weight:bold void CLayer::MyDrawTransparent(CDC* pDC, <span class="x_k" style="color:#800080; font-weight:bold int XDest, <span class="x_k" style="color:#800080; font-weight:bold int YDest, <span class="x_k" style="color:#800080; font-weight:bold int nDestWidth, <span class="x_k" style="color:#800080; font-weight:bold int nDestHeight)
{
}[/code]
[/code]
<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left Any guidance shall he highly appreciated.<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left Thank you very much.<br style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left Alvin
<span style="font-family:verdana,geneva,lucida,lucida grande,arial,helvetica,sans-serif; font-size:13px; line-height:normal; text-align:left

View the full article
 
Back
Top