win7, vc6;  新建一个对话框工程;界面;

添加按钮单击函数;

为控件添加成员变量;

添加列表框消息处理函数;

搞几个测试图片;

对话框头文件手动添加成员函数 ShowJpg;

// Construction
public:
    CTestjpgDlg(CWnd* pParent = NULL);    // standard constructor
    bool ShowJpg(CDC* ,CString , int , int);

对话框Cpp文件全部代码如下;

// testjpgDlg.cpp : implementation file
//#include "stdafx.h"
#include "testjpg.h"
#include "testjpgDlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/
// CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog
{
public:CAboutDlg();// Dialog Data//{{AFX_DATA(CAboutDlg)enum { IDD = IDD_ABOUTBOX };//}}AFX_DATA// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CAboutDlg)protected:virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support//}}AFX_VIRTUAL// Implementation
protected://{{AFX_MSG(CAboutDlg)//}}AFX_MSGDECLARE_MESSAGE_MAP()
};CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{//{{AFX_DATA_INIT(CAboutDlg)//}}AFX_DATA_INIT
}void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CAboutDlg)//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)//{{AFX_MSG_MAP(CAboutDlg)// No message handlers//}}AFX_MSG_MAP
END_MESSAGE_MAP()/
// CTestjpgDlg dialogCTestjpgDlg::CTestjpgDlg(CWnd* pParent /*=NULL*/): CDialog(CTestjpgDlg::IDD, pParent)
{//{{AFX_DATA_INIT(CTestjpgDlg)m_names = _T("");//}}AFX_DATA_INIT// Note that LoadIcon does not require a subsequent DestroyIcon in Win32m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}void CTestjpgDlg::DoDataExchange(CDataExchange* pDX)
{CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CTestjpgDlg)DDX_Control(pDX, IDC_LIST1, m_list1);DDX_Text(pDX, IDC_EDIT1, m_names);//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CTestjpgDlg, CDialog)//{{AFX_MSG_MAP(CTestjpgDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BUTTON1, OnButton1)ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)//}}AFX_MSG_MAP
END_MESSAGE_MAP()/
// CTestjpgDlg message handlersBOOL CTestjpgDlg::OnInitDialog()
{CDialog::OnInitDialog();// Add "About..." menu item to system menu.// IDM_ABOUTBOX must be in the system command range.ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX < 0xF000);CMenu* pSysMenu = GetSystemMenu(FALSE);if (pSysMenu != NULL){CString strAboutMenu;strAboutMenu.LoadString(IDS_ABOUTBOX);if (!strAboutMenu.IsEmpty()){pSysMenu->AppendMenu(MF_SEPARATOR);pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);}}// Set the icon for this dialog.  The framework does this automatically//  when the application's main window is not a dialogSetIcon(m_hIcon, TRUE);            // Set big iconSetIcon(m_hIcon, FALSE);     // Set small icon// TODO: Add extra initialization herereturn TRUE;  // return TRUE  unless you set the focus to a control
}void CTestjpgDlg::OnSysCommand(UINT nID, LPARAM lParam)
{if ((nID & 0xFFF0) == IDM_ABOUTBOX){CAboutDlg dlgAbout;dlgAbout.DoModal();}else{CDialog::OnSysCommand(nID, lParam);}
}// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.void CTestjpgDlg::OnPaint()
{if (IsIconic()){CPaintDC dc(this); // device context for paintingSendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);// Center icon in client rectangleint cxIcon = GetSystemMetrics(SM_CXICON);int cyIcon = GetSystemMetrics(SM_CYICON);CRect rect;GetClientRect(&rect);int x = (rect.Width() - cxIcon + 1) / 2;int y = (rect.Height() - cyIcon + 1) / 2;// Draw the icondc.DrawIcon(x, y, m_hIcon);}else{CDialog::OnPaint();}
}// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CTestjpgDlg::OnQueryDragIcon()
{return (HCURSOR) m_hIcon;
}void CTestjpgDlg::OnButton1()
{// TODO: Add your control notification handler code hereCString sFolderPath;BROWSEINFO bi;char Buffer[MAX_PATH];bi.hwndOwner = NULL;bi.pidlRoot =NULL;bi.pszDisplayName = Buffer;bi.lpszTitle = "选择目录";//bi.ulFlags = BIF_BROWSEINCLUDEFILES;//包括文件bi.ulFlags = BIF_EDITBOX;//包括文件bi.lpfn = NULL;bi.iImage=IDR_MAINFRAME;LPITEMIDLIST pIDList = SHBrowseForFolder(&bi);//显示选择对话框if(pIDList){SHGetPathFromIDList(pIDList, Buffer);//取得文件夹路径到Buffer里sFolderPath = Buffer;//将文件夹路径保存在一个CString对象里}LPMALLOC lpMalloc;if(FAILED(SHGetMalloc(&lpMalloc)))return;lpMalloc->Free(pIDList);lpMalloc->Release();m_names = sFolderPath;UpdateData(FALSE);SetCurrentDirectory(sFolderPath);CFileFind finder;BOOL bw = finder.FindFile("*.jpg");while(bw){bw=finder.FindNextFile();         m_list1.AddString(finder.GetFileName());}}void CTestjpgDlg::OnSelchangeList1()
{// TODO: Add your control notification handler code hereCString strText;int nCurSel;          nCurSel = m_list1.GetCurSel();m_list1.GetText(nCurSel, strText); CDC* pDC1 = GetDlgItem(IDC_STATIC)->GetDC();ShowJpg(pDC1,m_names + "\\" + strText ,0,0);
}bool CTestjpgDlg::ShowJpg(CDC* pDC,CString strPath, int x, int y)
{IStream *pStm; CFileStatus fstatus; CFile file; LONG cb;//MessageBox(strPath,"选择的文件is:",MB_OK);if (file.Open(strPath,CFile::modeRead)&&file.GetStatus(strPath,fstatus)&&((cb = fstatus.m_size) != -1)) { HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb); LPVOID pvData = NULL; if (hGlobal != NULL) { pvData = GlobalLock(hGlobal);if (pvData != NULL) { file.Read(pvData, cb); GlobalUnlock(hGlobal); CreateStreamOnHGlobal(hGlobal, TRUE, &pStm); }}}else{return false;}IPicture *pPic = NULL;if(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size,TRUE,IID_IPicture,(LPVOID*)&pPic))){OLE_XSIZE_HIMETRIC hmWidth; OLE_YSIZE_HIMETRIC hmHeight; pPic->get_Width(&hmWidth); pPic->get_Height(&hmHeight); double fX,fY;//get image height and widthfX = (double)pDC->GetDeviceCaps(HORZRES)*(double)hmWidth/((double)pDC->GetDeviceCaps(HORZSIZE)*100.0); fY = (double)pDC->GetDeviceCaps(VERTRES)*(double)hmHeight/((double)pDC->GetDeviceCaps(VERTSIZE)*100.0);         //use render function display imageif(FAILED(pPic->Render(*pDC,x,y,(DWORD)fX,(DWORD)fY,0,hmHeight,hmWidth,-hmHeight,NULL))) {pPic->Release();return false;}pPic->Release();} else return false; return true;
}

运行;如下二图;

有时间再继续;

VC++开发一个简易图片浏览器 - 含目录浏览功能相关推荐

  1. 使用vb6绿色版做一个简易图片浏览器

    在win10下看一下vb6能不能用: 在设计界面:在窗体上添加一个Drive控件,一个Dir控件,一个File控件,一个PictureBox控件: Private Sub Dir1_Change()F ...

  2. 一个简易的网盘目录列表PanIndex

    网盘的目录文件列表应用非常多,老苏之前也写过一些,有的支持多种网盘 支持天翼云的在线文件目录ShareList 在线文件目录Z-file 而有的只支持某一种网盘 阿里云盘的目录文件列表程序Alist ...

  3. python的Tkinter库简单应用——开发一个简易计算器

    利用python的Tkinter库开发一个简易计算器 文章目录 利用python的Tkinter库开发一个简易计算器 前言 一.实验准备 二.开发步骤步骤 1.引入库 2.界面设计 3.关键--实现T ...

  4. 【181122】VC++基于MFC的图片浏览器(有多种特效)源代码

    源码下载简介 一个完整的毕业设计+论文+PPT演示,VC++基于MFC的图片浏览器,在进行图片浏览或打开.关闭.切换的时候都带有多种特效,实现PCX.BMP.TGA.GIF.JPEG的读写显示,并可以 ...

  5. 稳扎稳打Silverlight(18) - 2.0视频之详解MediaElement, 开发一个简易版的全功能播放器...

    [索引页] [×××] 稳扎稳打Silverlight(18) - 2.0视频之详解MediaElement, 开发一个简易版的全功能播放器 作者:webabcd 介绍 Silverlight 2.0 ...

  6. java 防篡改_用JAVA二十分钟撸一个简易图片防篡改

    看到有个毕设是搞图片防篡改的,就自己撸了一个简易图片防止篡改. 原理 将图片字节生成字符串使用摘要算法加密,将加密生成的字节写到图片最后.验证时,首先读取末尾的加密字节,读取完成以后删除,再通过摘要算 ...

  7. Winform初学 ---01设计一个简易的浏览器

    1.说明: 最近想利用winform设计一个简易的浏览器.winform自带一个WebBrowser组件,但是WebBrowser具有非常大的局限性,用的是IE的内核,使用该组件打开网址后非常地不美观 ...

  8. php 怎么支持中文图片显示,利用php怎么实现一个给图片添加中文水印的功能

    利用php怎么实现一个给图片添加中文水印的功能 发布时间:2021-01-21 15:13:48 来源:亿速云 阅读:88 作者:Leah 这篇文章给大家介绍利用php怎么实现一个给图片添加中文水印的 ...

  9. ubuntu 安装nginx 并开启目录浏览功能

    首先 如果安装apache  应该卸载 sudo apt-get --purge remove apache2 sudo apt-get --purge remove apache2.2-common ...

最新文章

  1. SyntaxError: Non-ASCII character ‘\xe5‘ in file(xxlrt_1.py) on line 7, but no encoding declared;
  2. getElementById 使用
  3. java银行柜面发起授权功能_java银行自主柜员程序设计
  4. 斯坦福iOS7公开课4-6笔记及演示Demo
  5. Bitcoin 中的挖矿算法(2) 难度值说明
  6. 组合逻辑与lamda算子的历史 英文
  7. 博图注册表删除方法_技成周报40期 | 三菱、西门子软件安装常见出错解决方法...
  8. SQL语句修改主键列
  9. Matlab中plot函数绘图基本用法
  10. CF1548A Web of Lies
  11. C++:43---派生类向基类转换、静态/动态的类变量
  12. 45 张图深度解析 Netty 架构与原理
  13. 【数据库题型大总结】应用题总结
  14. swag您的装置不支持_209P型铁路客车转向架之轮对轴箱弹簧定位装置简介
  15. codeforces 451C. Predict Outcome of the Game 解题报告
  16. Presto 即席查询
  17. Masked GCN论文解读
  18. 两款浏览器去广告插件,让你舒心上网
  19. 201871010134-周英杰《面向对象程序设计(java)》第一周学习总结
  20. android开启照相功能,Android--启动拍照功能并返回结果

热门文章

  1. Ubuntu 9.10下在右键中添加以管理员身份打开,在终端中打开
  2. python的数值类型和运算符_python的数值类型和运算符
  3. 用python pandas按块读取超大csv/txt
  4. Python 技术篇-使用pygame库播放音乐没有声音问题解决办法
  5. Java 7 并发编程指南
  6. MFRC522开发笔记
  7. markdown数学公式写法和数学符号
  8. CTFshow php特性 web149
  9. Bag-of-words model
  10. [SOJ1006] Team Rankings