vc打开多个图片 然后点击按钮显示下一张 或上一张 100

一共3个按钮,“打开”上一张“”“下一张”,点击打开按钮选择要打开的图片显示在picture控件中,点击上一张显示上一张,点击下一张显示下一张。求代码~~~~~~~点击打... 一共3个按钮,“打开”上一张“ ”“下一张”,点击打开按钮选择要打开的图片显示在picture控件中,点击上一张显示上一张,点击下一张 显示下一张。求代码~~~~~~~ 点击打开按钮时有多张图片,选择一张,其余的都选中了,然后点击上一张实现其功能。求代码 展开
 我来答
任明星Ming
2013-07-18 · TA获得超过798个赞
知道小有建树答主
回答量:1061
采纳率:100%
帮助的人:1149万
展开全部
PictureControl就是类CStatic,下面是VC++ WTL的编程用法,你着重看下WM_PAINT及设置图片的函数就能知道,如何用在MFC里了。关于Load图片的函数AtlLoadGdiplusImage(nRes, pstrType),我没贴出来,主要是为了方便你了解。

当你切换图片时,就调用SetBitmap(HBITMAP hBitmap)函数,就可以切换图片了。SizeToFit()函数是根据你设定的图片,自动调整控件窗口大小。

#ifndef _THEMEDIMAGE_H_INCLUDE_
#define _THEMEDIMAGE_H_INCLUDE_
#pragma once

//////////////////////////////////////////////////////////////////////
// Themed Image control
//

class CThemedImageCtrl : public CWindowImpl<CThemedImageCtrl, CStatic>
{
public:
CWindow m_wndThemeParent;
CBrush m_brBack;
CBitmap m_bmpImage;

// Operations

BOOL SubclassWindow(HWND hWnd)
{
ATLASSERT(m_hWnd==NULL);
ATLASSERT(::IsWindow(hWnd));
BOOL bRet = CWindowImpl<CThemedImageCtrl, CStatic>::SubclassWindow(hWnd);
if( bRet ) Init();
return bRet;
}

void Init()
{
m_wndThemeParent = GetParent();
Invalidate();
}

void SetThemeParent(HWND hWnd)
{
ATLASSERT(::IsWindow(hWnd));
m_wndThemeParent = hWnd;
if( !m_brBack.IsNull() ) m_brBack.DeleteObject();
}

void SetBitmap(HBITMAP hBitmap)
{
m_bmpImage = (HBITMAP) ::CopyImage(hBitmap, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
if( IsWindow() ) Invalidate();
}

void SetBitmap(UINT nRes, LPCTSTR pstrType)
{
m_bmpImage = AtlLoadGdiplusImage(nRes, pstrType);
if( IsWindow() ) Invalidate();
}

void SizeToFit()
{
ATLASSERT(!m_bmpImage.IsNull());
BITMAP BmpInfo = { 0 };
m_bmpImage.GetBitmap(&BmpInfo);
ResizeClient(BmpInfo.bmWidth, BmpInfo.bmHeight);
if( IsWindow() ) Invalidate();
}

// Message map and handlers

BEGIN_MSG_MAP(CThemedImageCtrl)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
MESSAGE_HANDLER(WM_MOVE, OnSize)
MESSAGE_HANDLER(WM_SIZE, OnSize)
MESSAGE_HANDLER(WM_PAINT, OnPaint)
MESSAGE_HANDLER(WM_PRINTCLIENT, OnPaint)
END_MSG_MAP()

LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
Init();
bHandled = FALSE;
return 0;
}

LRESULT OnSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
if( !m_brBack.IsNull() ) m_brBack.DeleteObject();
return TRUE;
}

LRESULT OnEraseBkgnd(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
return 1;
}

LRESULT OnPaint(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
if( wParam != NULL )
{
DoPaint((HDC) wParam);
}
else
{
CPaintDC dc(m_hWnd);
DoPaint(dc.m_hDC);
}
return 0;
}

// Implementation

void DoPaint(CDCHandle dc)
{
CRect rcClient;
GetClientRect(&rcClient);

// Preserve background
if( m_brBack.IsNull() ) m_brBack = AtlGetBackgroundBrush(m_hWnd, m_wndThemeParent);
HBRUSH hOldBrush = dc.SelectBrush(m_brBack);
dc.PatBlt(rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), PATCOPY);
dc.SelectBrush(hOldBrush);

// Paint image (assume that it is a 32bit with alpha-pr-pixel)...
CDC dcCompat;
dcCompat.CreateCompatibleDC(dc);
BITMAP BmpInfo = { 0 };
m_bmpImage.GetBitmap(&BmpInfo);
BLENDFUNCTION bf = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
HBITMAP hOldBitmap = dcCompat.SelectBitmap(m_bmpImage);
dc.AlphaBlend(0, 0, rcClient.Width(), rcClient.Height(), dcCompat, 0, 0, BmpInfo.bmWidth, BmpInfo.bmHeight, bf);
dcCompat.SelectBitmap(hOldBitmap);
}

};
#endif //_THEMEDIMAGE_H_INCLUDE_
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式