Re: i need Slideshow control
Here is another version. This version resizes the images to fit the static
control.
Place static control on your dialog box, give it an ID, attach a variable to
it, change the variable type from CStatic to CSlideShowCtrl
#pragma once
#include <atlimage.h>
// CSlideShowCtrl
class CSlideShowCtrl : public CStatic
{
DECLARE_DYNAMIC(CSlideShowCtrl)
public:
CSlideShowCtrl();
virtual ~CSlideShowCtrl();
void Start(CString Dir,UINT Interval);
void Stop();
protected:
afx_msg void OnTimer(UINT nIDEvent);
DECLARE_MESSAGE_MAP()
private:
CFileFind m_Finder;
BOOL m_Ret;
CString m_Dir;
CImage m_CurImage;
afx_msg void OnPaint();
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
};
// SlideShowCtrl.cpp : implementation file
//
#include "stdafx.h"
#include "SlideShowCtrl.h"
// CSlideShowCtrl
IMPLEMENT_DYNAMIC(CSlideShowCtrl, CStatic)
CSlideShowCtrl::CSlideShowCtrl()
{
}
CSlideShowCtrl::~CSlideShowCtrl()
{
}
BEGIN_MESSAGE_MAP(CSlideShowCtrl, CStatic)
ON_WM_TIMER()
ON_WM_PAINT()
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
// CSlideShowCtrl message handlers
void CSlideShowCtrl::Start(CString Dir,UINT Interval)
{
m_Dir = Dir;
m_Ret = m_Finder.FindFile(Dir+"\\*.*");
while (m_Ret)
{
m_Ret = m_Finder.FindNextFile();
if (!m_Finder.IsDirectory())
{
CImage Image;
if (Image.Load(m_Finder.GetFilePath()) == S_OK)
{
m_CurImage.Destroy();
m_CurImage.Attach(Image.Detach());
Invalidate();
UpdateWindow();
break;
}
}
}
SetTimer(100,Interval,NULL);
}
void CSlideShowCtrl::Stop()
{
KillTimer(100);
}
void CSlideShowCtrl::OnTimer(UINT nIDEvent)
{
if (nIDEvent == 100)
{
if (!m_Ret)
{
m_Ret = m_Finder.FindFile(m_Dir+"\\*.*");
}
while (m_Ret)
{
m_Ret = m_Finder.FindNextFile();
if (!m_Finder.IsDirectory())
{
CImage Image;
if (Image.Load(m_Finder.GetFilePath()) == S_OK)
{
m_CurImage.Destroy();
m_CurImage.Attach(Image.Detach());
Invalidate();
UpdateWindow();
break;
}
}
}
}
CStatic::OnTimer(nIDEvent);
}
void CSlideShowCtrl::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect Rect;
GetClientRect(&Rect);
double Ratio = 1.0;
if (m_CurImage.GetWidth() > Rect.Width())
{
Ratio = (double)Rect.Width() / (double)m_CurImage.GetWidth();
}
if (m_CurImage.GetHeight() > Rect.Height())
{
double Temp = Rect.Height() / (double)m_CurImage.GetHeight();
if (Temp < Ratio)
{
Ratio = Temp;
}
}
int X = (int)(Rect.Width() - (m_CurImage.GetWidth()*Ratio)) / 2;
int Y = (int)(Rect.Height() - (m_CurImage.GetHeight()*Ratio)) / 2;
m_CurImage.Draw(dc.GetSafeHdc(),X,Y,m_CurImage.GetWidth()*Ratio,m_CurImage.GetHeight()*Ratio);
}
BOOL CSlideShowCtrl::OnEraseBkgnd(CDC* pDC)
{
CRect Rect;
GetClientRect(&Rect);
pDC->FillSolidRect(Rect,RGB(127,127,127));
return TRUE;
}
AliR.
"AliR (VC++ MVP)" <AliR@online.nospam> wrote in message
news:bNOMi.11115$JD.3684@newssvr21.news.prodigy.net...
Here is a very simple one I wrote in 10 minutes.
It doesn't do scaling, you want to scale the images so that they are all
the same size you will have to Draw the Image yourself.
#pragma once
// CSlideShowCtrl
class CSlideShowCtrl : public CStatic
{
DECLARE_DYNAMIC(CSlideShowCtrl)
public:
CSlideShowCtrl();
virtual ~CSlideShowCtrl();
void Start(CString Dir);
void Stop();
protected:
afx_msg void OnTimer(UINT nIDEvent);
DECLARE_MESSAGE_MAP()
private:
CFileFind m_Finder;
BOOL m_Ret;
CString m_Dir;
};
// SlideShowCtrl.cpp : implementation file
//
#include "stdafx.h"
#include "SlideShowCtrl.h"
#include <atlimage.h>
// CSlideShowCtrl
IMPLEMENT_DYNAMIC(CSlideShowCtrl, CStatic)
CSlideShowCtrl::CSlideShowCtrl()
{
}
CSlideShowCtrl::~CSlideShowCtrl()
{
}
BEGIN_MESSAGE_MAP(CSlideShowCtrl, CStatic)
ON_WM_TIMER()
END_MESSAGE_MAP()
// CSlideShowCtrl message handlers
void CSlideShowCtrl::Start(CString Dir)
{
m_Dir = Dir;
m_Ret = m_Finder.FindFile(Dir+"\\*.*");
while (m_Ret)
{
m_Ret = m_Finder.FindNextFile();
if (!m_Finder.IsDirectory())
{
CImage Image;
if (Image.Load(m_Finder.GetFilePath()) == S_OK)
{
SetBitmap(Image.Detach());
break;
}
}
}
SetTimer(100,1000,NULL);
}
void CSlideShowCtrl::Stop()
{
KillTimer(100);
}
void CSlideShowCtrl::OnTimer(UINT nIDEvent)
{
if (nIDEvent == 100)
{
if (!m_Ret)
{
m_Ret = m_Finder.FindFile(m_Dir+"\\*.*");
}
while (m_Ret)
{
m_Ret = m_Finder.FindNextFile();
if (!m_Finder.IsDirectory())
{
CImage Image;
if (Image.Load(m_Finder.GetFilePath()) == S_OK)
{
SetBitmap(Image.Detach());
break;
}
}
}
}
CStatic::OnTimer(nIDEvent);
}
AliR.
"Neel" <urneel@gmail.com> wrote in message
news:1191406667.879154.320480@g4g2000hsf.googlegroups.com...
Hi all,
Iam doing dialog based application with VS VC++6.0 MFC.
is there any control/ActivX which can do slidshow from selected
picture folder.
folder may contain images with any format(.bmp, .jpeg, .png, .tiff)
and also i shld give option transition effects.
thanks in adv