Access编程交流网
  • 设为首页|收藏本站|繁体中文|手机版
  •     
  • Access培训-Access开发平台-Access行业开发

  • 首页
  • 资讯
  • 技巧
  • 源码
  • 行业
  • 资源
  • 活动
  • 关于

培训

Access企业培训(现场)
Access在线培训

Access中级培训

Access高级培训

Access定制培训

Access树控件与BOM高级技巧

Access公开课
Access免费公开课视频
Access培训(VIP)
Access培训优惠信息

热门文章

最新文章

联系方式

Access交流网(免费Access交流)

QQ:18449932 

网  址:www.access-cn.com

当前位置:首页 > 培训 > Access培训(VIP)
Access培训(VIP)

access图片分页展示及选择功能-Access经典源码剖析

 
Access主题 主题:Access图片分页展示及选择功能-高手之路                  听课人数:163人      
Access主讲

 主讲:王宇虹                        演讲时间:2014-12-17 15:30 至 2014-12-17 16:30

                                                                2014-12-24 15:30 至 2014-12-24 16:30

Access培训内容 讲课内容简介:                   Access培训报名: http://www.office-cn.net/thread-118946-1-1.html
  讲解关于access处理图片的功能,包括图片预览和选择、图片分页处理、图片上传到数据库等等内容。适合产品需要多图展示的效果。可以根据需求分页数量、边框设置等常用功能
 培训优势:使用新版Access2013+思维导图模式+Access源码剖析+在线课堂+PPT课件  培训
 培训目标:让你 听得懂 学得会 记得住 用得上             要求:有一定的Access 或 VBA的基础 
 

 

clip0058

Access图片分页展示及选择功能


 

 

application_key 功能描述:

 

  • access分页展示图片

  • access图片选择与预览

  • access上传图片和下载图片

 

 

application_key  行业应用场景:

 
  • 多图片展示

           产品的图片

  • 大量图片选择

  • 界面图标选择

  • 图片文档预览

 

application_key  界面预览:

 

     access数据库

     

 

application_key  源码思维导图(脑图):

 

     access数据库

 

Access教程视频Access图片分页展示及选择功能 -- Access经典源码剖析思维导图在线播放

可直接展开和收缩思维导图中的每个节点来浏览,也可使用下面的放大 缩小 折叠 定位焦点 全页显示 查找关键字等功能
 

 

 

application_key  Access培训笔记:

 

 经典源码剖析系列 图片分页展示与选择 Office中国-王宇虹

1 应用场景

1.1 多图片展示

1.1.1 产品的图片

1.2 大量图片选择

1.3 界面图标选择

1.4 图片文档预览

2 模块 源码剖析

2.1 搜索目录下所有图片

2.1.1 设置边框

2.1.2 Search函数

2.1.2.1 参数 strPath

2.1.2.2 先清除表上一次搜索的结果

2.1.2.2.1 delete * from tblSysImageTmp

2.1.2.3 Dir(strPath, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly)

2.1.2.3.1 搜索文件和目录

2.1.2.3.1.1 隐藏

2.1.2.3.1.2 正常

2.1.2.3.1.3 只读

2.1.2.4 如果找到的是目录

2.1.2.4.1 排除掉父目录(..)和当前目录(.)

2.1.2.4.2 其它正常目录保存到数组

2.1.2.5 如果找到是文件,就把这个文件添加到表中

2.1.2.5.1 添加到表

2.1.2.5.1.1 insert into

2.1.2.5.1.2 ado addnew

2.1.2.6 如果当前目录有子目录

2.1.2.6.1 递归搜索子目录

2.1.2.6.1.1 Call search(strPath + strFileDir(i), strSearch) '递归搜索子目录

2.2 加载图片

2.2.1 根据图片总数进行自动分页

2.2.1.1 根据每页显示的图片数量 6 张

2.2.2 取图片的总数

2.2.2.1 DCount("*", "tblSysImageTmp")

2.2.2.1.1 图片总数量

2.2.2.2 intPerPagNum

2.2.2.2.1 每页可放多少张图片

2.2.2.3 Mod

2.2.2.3.1 取余

2.2.2.3.1.1 如果刚好除尽

2.2.2.3.1.1.1 页数=商数

2.2.2.3.1.2 如果除不尽

2.2.2.3.1.2.1 页数=结果+1

2.2.3 把窗体6张图片控件先隐藏

2.2.4 数据分页

2.2.4.1 strSql = "select top " & intPerPagNum & " FFileName from tblSysImageTmp "

2.2.4.1.1 select top

2.2.5 判断是否图片文件

2.2.5.1 strExt = ".BMP" Or strExt = ".GIF" Or strExt = ".JPG"

2.2.6 组合成一个完整的图片路径

2.2.6.1 CurrentProject.Path & "\res\image\" & strFileName

2.2.6.2 D:\tony\超级经典源码\图片分页展示与选择\

2.2.6.2.1 Res\Image

2.2.6.2.1.1 test.jpg

2.2.6.3 D:\tony\超级经典源码\图片分页展示与选择\Res\Image\test.jpg

2.2.6.3.1 赋给图片的picture

2.2.6.3.2 Controls("img" & i).Picture

2.2.7 把有图的图片控件和标签显示出来

2.2.7.1 Controls("img" & i).Visible = True            Controls("lblID" & i).Visible = True

2.3 页切换

2.3.1 上一页

2.3.2 下一页

2.3.3 首页

2.3.4 末页

2.3.5 去到指定页

2.3.6 页切换的函数

2.3.6.1 changePage

2.3.6.1.1 True

2.3.6.1.1.1 往前翻页

2.3.6.1.1.1.1 如果当前是第1页

2.3.6.1.1.1.1.1 Nz(txtCurrPage.Value) = 1

2.3.6.1.1.1.1.2 提示已经是第一页

2.3.6.1.1.1.1.3 直接退出

2.3.6.1.1.1.2 如果当前页是第2页

2.3.6.1.1.1.2.1 txtCurrPage.Value=2

2.3.6.1.1.1.2.2 select top 6

2.3.6.1.1.1.3 如果是其它页

2.3.6.1.1.1.3.1 "select top " & intPerPagNum & " FFileName from tblSysImageTmp where " & _                                "FFileName not in (select top " & (Nz(txtCurrPage.Value) - 2) * intPerPagNum & " FFileName from tblSysImageTmp)"

2.3.6.1.1.1.4 当前的页码-1

2.3.6.1.1.1.4.1 txtCurrPage.Value = Nz(txtCurrPage.Value) - 1

2.3.6.1.2 False

2.3.6.1.2.1 往后翻页

2.3.6.1.2.1.1 如果当前是最后一页

2.3.6.1.2.1.1.1 Nz(txtCurrPage.Value) = Nz(txtTotlePage.Value)

2.3.6.1.2.1.1.2 提示已经是最后一页

2.3.6.1.2.1.1.3 直接退出

2.3.6.1.2.1.2 如果是其它页

2.3.6.1.2.1.2.1 "select top " & intPerPagNum & " FFileName from tblSysImageTmp where " & _                    "FFileName not in (select top " & Nz(txtCurrPage.Value) * intPerPagNum & " FFileName from tblSysImageTmp)"

2.3.6.1.2.1.3 当前的页码+1

2.3.6.1.2.1.3.1 txtCurrPage.Value = Nz(txtCurrPage.Value) +1

2.3.6.1.3 加载图片

2.4 图片选择框及预览

2.4.1 图片边框设置

2.4.1.1 setBorder 2

2.4.1.2 Controls("img" & rintSeq).BorderStyle = 1

2.4.2 设置选择图片的对像

2.4.2.1 LoadPicture

2.4.3 预览

2.4.3.1 把图片路径再赋给预览控件

3 知识点

3.1 Dir

3.1.1 获取目录下的文件或子目录

3.2 GetAttr

4 程序要求

4.1 准确性

4.2 友好性

4.2.1 用户体验

4.2.1.1 用户满意度高

4.3 优化

4.4 稳定性

4.5 安全性

 

 

 

application_key  相关链接:

 

1. 直接超值购买:

       点击购买:  Button 

       包含:Access示例完整源码+实现思路与代码讲解高清视频+Access培训课件    绝对低价超值

 

2. 购买前咨询:

    

    在线咨询QQ:1918333016

    企业热线QQ:4008553990 (使用QQ搜索: 搜索服务)

    更多联系方式:http://www.office-cn.net/t/training/officecontact.htm

 

application_key  部分源码预览:

 

  access数据库

 

Option Compare Database
Option Explicit
Public Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
 
Public Type Size
   cx As Long
   cy As Long
End Type
 
Public Type PointAPI  '  8 Bytes
    X As Long
    Y As Long
End Type
 
 
Public Const HORZSIZE = 4                                 '  Horizontal size in millimeters
Public Const VERTSIZE = 6                                 '  Vertical size in millimeters
Public Const HORZRES = 8                                  '  Horizontal width in pixels
Public Const VERTRES = 10                                 '  Vertical width in pixels
Public Const LOGPIXELSY = 90                           '  Logical pixels/inch in X
Public Const LOGPIXELSX = 88                           '  Logical pixels/inch in Y
Public Const BITSPIXEL = 12         '  Number of bits per pixel
      Public Declare Function apiSelectObject Lib "gdi32" Alias "SelectObject" (ByVal hdc As Long, ByVal hObject As Long) As Long
    Public Declare Function apiDeleteObject Lib "gdi32" Alias "DeleteObject" (ByVal hObject As Long) As Long
    Public Declare Function apiGetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
    Public Declare Sub apiCopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
  
    Public Declare Function apiGetDC Lib "user32" Alias "GetDC" (ByVal Hwnd As Long) As Long
    Public Declare Function apiReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal Hwnd As Long, ByVal hdc As Long) As Long
    Public Declare Function apiDeleteDC Lib "gdi32" Alias "DeleteDC" (ByVal hdc As Long) As Long
 
     Public Declare Function apiGetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps" (ByVal hdc As Long, ByVal nIndex As Long) As Long
 
    Private Declare Function apiCopyEnhMetaFile Lib "gdi32" Alias "CopyEnhMetaFileA" (ByVal hemfSrc As Long, ByVal lpszFile As String) As Long
    Private Declare Function apiPlayEnhMetaFile Lib "gdi32" Alias "PlayEnhMetaFile" (ByVal hdc As Long, ByVal hEMF As Long, lpRect As RECT) As Long
    Private Declare Function apiCloseEnhMetaFile Lib "gdi32" Alias "CloseEnhMetaFile" (ByVal hdc As Long) As Long
    'Private Declare Function apiCreateEnhMetaFile Lib "gdi32" Alias "CreateEnhMetaFileA" (ByVal hDCref As Long, ByVal lpFileName As String, ByVal lpRect As Any, ByVal lpDescription As String) As Long
    '' lprect as RECT changed to as BYVAL as Any to allow for NULL
    Private Declare Function apiCreateEnhMetaFileRECT Lib "gdi32" Alias "CreateEnhMetaFileA" (ByVal hDCref As Long, ByVal lpFileName As String, ByRef lpRect As RECT, ByVal lpDescription As String) As Long
    Private Declare Function apiDeleteEnhMetaFile Lib "gdi32" Alias "DeleteEnhMetaFile" (ByVal hEMF As Long) As Long
    Private Declare Function apiGetEnhMetaFileBits Lib "gdi32" Alias "GetEnhMetaFileBits" (ByVal hEMF As Long, ByVal cbBuffer As Long, lpbBuffer As Byte) As Long
     
    Private Declare Function apiGetStockObject Lib "gdi32" Alias "GetStockObject" (ByVal nIndex As Long) As Long
    Private Declare Function apiSetStretchBltMode Lib "gdi32" Alias "SetStretchBltMode" (ByVal hdc As Long, ByVal nStretchMode As Long) As Long
    Private Declare Function apiSetMapMode Lib "gdi32" Alias "SetMapMode" (ByVal hdc As Long, ByVal nMapMode As Long) As Long
    Private Declare Function apiSetViewportExtEx Lib "gdi32" Alias "SetViewportExtEx" (ByVal hdc As Long, ByVal nX As Long, ByVal nY As Long, lpSize As Size) As Long
    Private Declare Function apiSetViewportOrgEx Lib "gdi32" Alias "SetViewportOrgEx" (ByVal hdc As Long, ByVal nX As Long, ByVal nY As Long, lpPoint As PointAPI) As Long
    Private Declare Function apiSetWindowOrgEx Lib "gdi32" Alias "SetWindowOrgEx" (ByVal hdc As Long, ByVal nX As Long, ByVal nY As Long, lpPoint As PointAPI) As Long
    Private Declare Function apiSetWindowExtEx Lib "gdi32" Alias "SetWindowExtEx" (ByVal hdc As Long, ByVal nX As Long, ByVal nY As Long, lpSize As Size) As Long
    Private Declare Function apiSetBkMode Lib "gdi32" Alias "SetBkMode" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
 
 
 
 
' StretchBlt() Modes
Private Const BLACKONWHITE = 1
Private Const WHITEONBLACK = 2
Private Const COLORONCOLOR = 3
Private Const HALFTONE = 4
Private Const MAXSTRETCHBLTMODE = 4
 
 
 
'  Ternary raster operations
Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
 
' Predefined Clipboard Formats
Private Const CF_TEXT = 1
Private Const CF_BITMAP = 2
Private Const CF_METAFILEPICT = 3
Private Const CF_SYLK = 4
Private Const CF_DIF = 5
Private Const CF_TIFF = 6
Private Const CF_OEMTEXT = 7
Private Const CF_DIB = 8
Private Const CF_PALETTE = 9
Private Const CF_PENDATA = 10
Private Const CF_RIFF = 11
Private Const CF_WAVE = 12
Private Const CF_UNICODETEXT = 13
Private Const CF_ENHMETAFILE = 14
 
'  Mapping Modes
Private Const MM_TEXT = 1
Private Const MM_LOMETRIC = 2
Private Const MM_HIMETRIC = 3
Private Const MM_LOENGLISH = 4
Private Const MM_HIENGLISH = 5
'........................
'........................
 
 
 
' Stock Logical Objects
Private Const WHITE_BRUSH = 0
Private Const LTGRAY_BRUSH = 1
Private Const GRAY_BRUSH = 2
Private Const DKGRAY_BRUSH = 3
Private Const BLACK_BRUSH = 4
Private Const NULL_BRUSH = 5
Private Const HOLLOW_BRUSH = NULL_BRUSH
Private Const WHITE_PEN = 6
Private Const BLACK_PEN = 7
Private Const NULL_PEN = 8
'........................
'........................
 
 
 
' Background Modes
Private Const TRANSPARENT = 1
Private Const OPAQUE = 2
Private Const BKMODE_LAST = 2
 
 
' How many Twips in 1 inch
Private Const TWIPSPERINCH = 1440
 
 
'*******************************************
'DEVELOPED AND TESTED UNDER MICROSOFT ACCESS 97, 2K and 2K2
'
'
'Copyright: Lebans Holdings 1999 Ltd.
'           May not be resold in whole or part by itself, or as part of a collection.
'           Please feel free to use any/all of this code within your
'           own applications, whether private or commercial, without cost or obligation.
'           Please include the one line Copyright notice if you use this function in your own code.
'
'Version:  Ver 5.0
'
'Name:      Public Function fLoadPicture(ctl As Access.Image,
'            Optional strfName As String = "", Optional AutoSize As Boolean = False) As Boolean
'Inputs:
'           ctl -> Access Image control
'           strfName -> Optional name of Image file to load and bypass File Dialog
'           Autosize -> flag to signify whether to autosize the control to its contents
'
'Purpose:   Provides functionality to load JPG,GIF,BMP,EMF,WMF,CUR and ICO
'           files on systems without the Office Graphics Filters loaded.
'           Originally developed for Systems with Access Runtime only.
'           Supports transparency in Transparent Gifs.
'           Allows you to resize Images on Forms/Reports at runtime
'           with no loss of Image quality.
'
'Author:    Stephen Lebans
'Email:     Stephen@lebans.com
'Date:      April 12, 2003, 11:12:13 AM
'
'Called by: Anybody that wants to!
'
'How to use:See inline documentation within each function call.
'
'Notes:
 
' *************************************************************
' Version 5.0 Notes
' April 5, 2003
' Finally got around to fixing the resizing issues when control's
' SizeMode prop is set to Zoom or Stretch. With A97 any format other
' than Bitmap would resize correctly. With A2K and higher the issue was
' reversed and only Bitmap images would resize properly.
' Solution was to use Use StretchBlt with SetStretchBltMode instead
' of BitBlt in the Enhanced Metafile records.
' This current version now works in all versions of Access for
' both Forms and Reports.
' Found a silly bug/feature. Access use the Office Graphics filters
' for Bitmap and Metafile images is dependant on the letter case
' of the file extensions. I'm serious!
' Will document this and other Image handling anomolies on my Web site.
'
'
 
' Version 3.2 Notes
' The function was performing perfectly until I changed the Image
' Control's Size Mode property from CLIP to either ZOOM or STRETCH.
' After experimenting I've reached the following conclusions
' pertaining to a standard Image control in A97.
' 1) Any BMP or DIB file will only display properly with a Size Mode prop
' of CLIP. This statement is directed towards Bitmap files of 16 bits or
' higher. The results vary depending on the number of colors in the Image
' and how large the blocks of solid colors are. Your mileage may vary!
'
' 2) All other graphic file types will display properly with any Size Mode
' property setting.
 
' Why? BMP's and DIB's are an OS native file format. They are
' loaded/stored as DIB's. All other graphics formats are loaded and
' converted to DIB's and stored within a Metafile wrapper.
'
' It seems that the resizing algorithm works better on Metafiles than
' DIB's. Visually, it looks to be more of a Palette issue then the actual
' resizing routines but I haven't take the time to explore further. If
' anyone knows I would appreciate hearing from you.
 
' The workaround is to simply package my Bitmap within a Metafile ,
' which is the core logic employed by this function.
 
'Credits:
'Everyone I ever talked to in the whole world!
'
'BUGS:
'No serious bugs notices at this point in time.
'Please report any bugs to my email address.
'There is a GDI Resource leak if you play back
'several hundred Metafiles in one session. Should not showup as
'a problem in the normal course of events.
'
'What's Missing:
'Oh I'm sure there is something...there always is!
'
'HOW TO USE:
' See Example Form for how to call these functions.
 
'HISTORY
 
' Version 5.0
' Use the Render method of the StdPicture object to render the
' Image into the EMF. The load function now handles
' JPG, GIF,BMP,EMF,WMF,CUR and ICO
 
' Version 4.0
' Modified code that builds the EMF. Use StretchBlt with
' SetStretchBltMode to allow for smooth resizing when
' control's SizeMode prop is set to Zoom or Stretch
 
' Version 3.2
' Added code to simulate Magnification for the Image control.
' Autosizing of Image control to match dimensions of loaded picture.
' ScrollBars return to TOP and LEFT when CLIP is selected.
 
' Version 3.
' Added code to simulate ScrollBars for the Image Control.
'
' Version 2.
' Added code to have cursor change to HourGlass during the
' process to load/display the Jpeg or Gif file. Certain large
' JPEG's can take several seconds to load depending on
' the performance of the system.
 
' Version 1
' No stones yet!
 
'Enjoy
'Stephen Lebans
 '*******************************************
 
        
 
 
' ***************************************
' Called by the fLoadPicture function to copy the bits of the
' selected Image from a StdPicture object into our
' memory Enahnced Metafile.
' Changed to use StretchBlt and SetStretchBltMode
 
Function gf_CopyStdPicToImageData(hStdPic As Object, ctl As Access.Image, _
Optional FileNamePath As String = "", Optional AutoSize As Boolean = False) As Boolean
 
Dim frm As Form
On Error Resume Next
'........................
'........................
 
 
   End If
Else
   Set frm = ctl.Parent
End If
 
 
' Changed all references to StdPicture to Object
' I'm going with late binding as this is a  sample database
' and many users may not be comfortable setting references.
 
' If you need the faster performance you can use Early binding and declare
' hStdPic as StdPicture.  Requires a Reference to Standard OLE Types.
' This file, OLEPRO32.DLL
' is usually found in your System folder. Goto the Menu Tools->References
' and set a reference to the above file.
 
On Error GoTo ERR_SHOWPIC
 
' Temp Device Context for EMF creation
Dim hDCref As Long
 
' DC/Window extents
Dim sz As Size
Dim pt As PointAPI
Dim rc As RECT
 
' Temp var to hold API returns
Dim lngRet As Long
Dim s As String
 
' handle to EMF
Dim hMetafile As Long
 
' handle to Metafile DC
Dim hDCMeta As Long
 
' Array to hold binary copy of Enhanced Metafile
' we will create.
Dim arrayMeta() As Byte
 
' Vars to calculate resolution
Dim sngConvertX As Single
Dim sngConvertY As Single
Dim ImageWidth As Long
Dim ImageHeight As Long
Dim Xdpi As Single
Dim Ydpi As Single
Dim TwipsPerPixelX As Single
Dim TwipsPerPixely As Single
Dim sngHORZRES As Single
Dim sngVERTRES As Single
Dim sngHORZSIZE As Single
Dim sngVERTSIZE As Single
 
 
' It must be GetDC not CreateCompatibleDC!!!
hDCref = apiGetDC(0)
 
' Make sure user has selected a valid supported Image type
If hStdPic.Type = 0 Then
 Err.Raise vbObjectError + 523, "gf_CopyStdPicToImageData.modStdPic", _
    "Sorry...This function can only read Image files." & vbCrLf & "Please Select a Valid Supported Image File"
End If
 
' Calculate the current Screen resolution.
' I used to simply use GetDeviceCaps and
' LOGPIXELSY/LOGPIXELSX. Unfortunately this does not yield accurate results
' with Metafiles.  LOGPIXELSY will return the value of 96dpi or 120dpi
' depending on the current Windows setting for Small Fonts or Large Fonts.
' Thanks to Feng Yuan's book "Windows Graphics Programming" for
' explaining the correct method to ascertain screen resolution.
 
' Let's grab the current size and resolution of our Screen DC.
'........................
'........................
 
 
 
' Convert Image dimensions to Twips and Pixels
' For fun let's not convert pixels to TWIPS since
' we always do it that way. Let's be different and
' convert the StdPicture Height & Width props directly.
' These are in a Map Mode of HiMetric units, expressed in .01 mm units.
 
' Convert to CM
'........................
'........................
 
 
 
' Convert to pixels
ImageWidth = sngConvertX / TwipsPerPixelX
ImageHeight = sngConvertY / TwipsPerPixely
 
 
' Create our Enhanced Metafile - Memory Based
' Set our bounding rectangle to match that of the StdPicture object
rc.Right = hStdPic.Width
rc.Bottom = hStdPic.Height
 
' Since this EMF may be copied to disk let's included come creator info.
s = "Stephen Lebans" & Chr(0) & Chr(0) & "www.lebans.com" & Chr(0) & Chr(0)
hDCMeta = apiCreateEnhMetaFileRECT(hDCref, vbNullString, rc, s)
 
' Was the EMF creation successful?
If hDCMeta = 0 Then
    Err.Raise vbObjectError + 525, "gf_CopyStdPicToImageData.modStdPic", _
    "Sorry...cannot Create Enhanced Metafile"
End If
 
' Setup our Metafile Device Context
' Set our mapping mode
lngRet = apiSetMapMode(hDCMeta, MM_TEXT) 'ANISOTROPIC) 'TEXT)
' Setup the extents for our DC
lngRet = apiSetWindowExtEx(hDCMeta, ImageWidth, ImageHeight, sz)
lngRet = apiSetWindowOrgEx(hDCMeta, 0&, 0&, pt)
lngRet = apiSetWindowExtEx(hDCMeta, ImageWidth, ImageHeight, sz)
' Setup the basics
'........................
'........................
 
 
' Fixes resizing issue.
lngRet = apiSetStretchBltMode(hDCMeta, COLORONCOLOR)
 
' Use the Render method of the StdPicture object.
' Boy the MS docs on this method are not easy to digest.
' I actually found a german web site that explained it in better detail
' with examples. My problem is that I could not find a sample
' of Rendering to a Metafile DC. The MS Docs state that you must supply
' a bounding rectangle as the last argument. No matter how I tried,
' I could not get the method to accept this parameter in any condiguration.
' Nearly ready to give up, by mistake I set the param to NULL and it worked.
' Go figure!
 
' The documentation regarding the Render method is not accurate.
' You do not need to suplly a bounding RECT when rendering
' to a Metafile DC.
hStdPic.Render CLng(hDCMeta), 0&, 0&, CLng(ImageWidth), CLng(ImageHeight), _
0&, hStdPic.Height, hStdPic.Width, -hStdPic.Height, vbNull
 
' You just never know...better safe than sorry!
DoEvents
 
' I have seen the following call fail on WIndos 98 systems.
' This happens when you have a report with a lot of Images
' and is due to a bug in the GDI with respect to Metafiles.
' Full details are on my web site in the Image handling FAQ.
hMetafile = apiCloseEnhMetaFile(hDCMeta)
If hMetafile = 0 Then
    gf_CopyStdPicToImageData = False
    Exit Function
End If
 
 
' Grab the contents of the Metafile
lngRet = apiGetEnhMetaFileBits(hMetafile, 0, ByVal 0&)
If lngRet = 0 Then
    gf_CopyStdPicToImageData = False
    Exit Function
End If
 
 
ReDim arrayMeta((lngRet - 1) + 8)
lngRet = apiGetEnhMetaFileBits(hMetafile, lngRet, arrayMeta(8))
 
' Delete EMF memory footprint.
lngRet = apiDeleteEnhMetaFile(hMetafile)
 
' If the first 40 bytes of a PictureData prop are
' not a BITMAPINFOHEADER structure then we will find
' a ClipBoard Format structure of 8 Bytes in length
' signifying whether a Metafile or Enhanced Metafile is present.
' The first 8 Bytes of a PictureData prop signify
' that the data is structured as one of the
' following ClipBoard Formats.
' CF_ENHMETAFILE
' CF_METAFILEPICT
' So the first 4 bytes tell us the format of the data.
' The next 4 bytes point to handle for a Memory Metafile.
' This is not needed for our construction purposes.
arrayMeta(0) = CF_ENHMETAFILE
 
' Copy our created PictureData bytes over to the Image Contol.
ctl.PictureData = arrayMeta
 
' Do we auto size the Image control to the
' dimensions of its the loaded image?
If AutoSize Then
    ' Error check to ensure we do not exceed
    ' SubForm boundaries
 '........................
'........................
 
 
    
'    If sngConvertY < ctl.Parent.Detail.Height Then
'        ctl.Height = sngConvertY '+ 15
'    Else
'        ctl.Height = ctl.Parent.Detail.Height - 200
'    End If
     ctl.SizeMode = acOLESizeStretch
    
End If
 
EXIT_SHOWPIC:
' Release our reference DC
lngRet = apiReleaseDC(0&, hDCref)
Exit Function
 
ERR_SHOWPIC:
gf_MsgBox "出现错误", vbOKOnly + vbCritical, , Err
 
Resume EXIT_SHOWPIC
 
End Function
 
 
 
 
' This function only works if the contents of the Image control
' are an Enhanced Metafile, which it will always be in
' this project. There is a general purpose solution
' for all formats on my site that uses the Clipboard to convert formats.
Public Function fSaveImagetoDisk(ctl As Access.Image) As Boolean
 
' User selected FileName from our File Dialog window
Dim sName As String
' Junk var
Dim lngRet As Long
 
' handle to Clipboard memory EMF
Dim hEMF As Long
 
' handle to our Disk based Metafile
Dim hMetafile As Long
 
' Array to hold binary copy of Enhanced Metafile
' we will create.
Dim arrayMeta() As Byte
 
' Open File Dialog
sName = fSavePicture
    If Len(sName & vbNullString) = 0 Then
    fSaveImagetoDisk = False
    Exit Function
End If
 
' resize our byte array to match length of PictureData prop
'........................
'........................
 
 
 
' Grab a local copy of the memory EMF
apiCopyMemory hEMF, arrayMeta(4), 4
' Create a disk based copy of the Metafile
hMetafile = apiCopyEnhMetaFile(hEMF, sName)
 
' Delete EMF memory footprint.
lngRet = apiDeleteEnhMetaFile(hMetafile)
 
 
End Function
 
 
 
Public Function fSavePicture(Optional strfName As String = "") As String
' Inputs
' strfName -> Optional name of Image file to Save
On Error GoTo Err_fSavePicture
' Temp Vars
Dim lngRet As Long
Dim blRet As Boolean
 
' Were we passed the Optional FileName and Path
'If Len(strfName & vbNullString) = 0 Then
'    ' Call the File Common Dialog Window
'    Dim clsDialog As Object
'    Dim strTemp As String
'
'    Set clsDialog = New clsSysCommonDialog
'
'    ' Fill in our structure
'    ' ***********************************************
'    ' WARNING
'    ' You must specify lowercase "emf" for the file extension. I will explain this
'    ' and how it is related to the office graphics filters in detail on my web site.
'       clsDialog.Filter = clsDialog.Filter & "Enhanced Metafile (*.emf)" & Chr$(0) & "*.emf" & Chr$(0)
'    clsDialog.hDC = 0
'    clsDialog.MaxFileSize = 256
'    clsDialog.Max = 256
'    clsDialog.FileTitle = vbNullString
'    clsDialog.DialogTitle = "Please Enter a Valid FileName"
'    clsDialog.InitDir = vbNullString
'    clsDialog.DefaultExt = ".emf" 'vbNullString
'
'    ' Display the File Dialog
'    clsDialog.ShowSave
'
'    ' See if user clicked Cancel or even selected
'    ' the very same file already selected
'    strfName = clsDialog.Filename
'    If Len(strfName & vbNullString) = 0 Then
'    ' Raise the exception
'      Err.Raise vbObjectError + 513, "fSavePicture.modStdPic", _
'      "Please Enter a Valid EMF Filename"
'    End If
'
'' If we jumped to here then user supplied a FileName
'End If
' Cleanup
 
fSavePicture = strfName
Exit_SavePic:
Err.Clear
'Set clsDialog = Nothing
Exit Function
 
Err_fSavePicture:
fSavePicture = strfName
gf_MsgBox "出现错误", vbOKOnly + vbCritical, , Err
Resume Exit_SavePic
 
End Function
 
 
 
 
 
' Here are some notes I attach to every
' project I do that include Metafiles and StdPicture object.
'Notes:
'1) When creating compatible DC's and Compatible Bitmaps
' make sure you use a REAL DC, not one you created!
' Had this problem before with CreateEnhancedMetafile.
 
'2) You cannot write directly to the Bitmap of a StdPicture
' This cost me hours to figure out. :-(
' So all you have to do is create another Memory DC and Bitmap and
' copy the StdPicture's Bitmap into that!
 
 
 
' Here two other methods to save the contents of an Image control to disk.
' This wonly works when the Image control contains an EMF but this is the case
' when you load any Image type other than WMF or BITMAP.
 
' ********************************************************************
'#1
' ********************************************************************
                 
' We are stripping off the first 8 Bytes of the
' Image1.PictureData prop and saving this to a
' disk based EMF file.
 
' Hold next File#
'Dim fNum As Integer
'Dim sName As String
'
'' Byte arrays to hold the PictureData prop
'Dim bArray() As Byte
'Dim cArray() As Byte
'
'' Temp var
'Dim lngRet As Long
'
'' Ensure there is data in the PcitureData prop
''If LenB(Me.JGSForm.Form.Image1.PictureData) < 108 Then Exit Sub
'
'If IsNull(Me.JGSForm.Form.Image1.PictureData) Then Exit Sub
'
'' Call the standard WIndows File Dialog
'sName = fSavePicture()
'If Len(sName & vbNullString) = 0 Then Exit Sub
'
'' Resize to hold entire PictureData prop
'ReDim bArray(LenB(Me.JGSForm.Form.Image1.PictureData) - 1)
'' Resize to hold the EMF wrapped in the PictureData prop
'ReDim cArray(LenB(Me.JGSForm.Form.Image1.PictureData) - (1 + 8))
'
'' Copy to our array
'bArray = Me.JGSForm.Form.Image1.PictureData
'
'' Copy the embedded EMF - SKIP first 8 bytes
'For lngRet = 8 To UBound(cArray) ' - (1) '+ 8)
'    cArray(lngRet - 8) = bArray(lngRet)
'Next
'
'' Get next avail file handle
'fNum = FreeFile
'
'
'' Let's Create/Open our new EMF File.
'Open sName For Binary As fNum
'
'' Write out the EMF
'Put fNum, , cArray
'
'' Close the File
'Close fNum
 
 
 
' ********************************************************************
'#2
' ********************************************************************
 
' Original Save Image control's contents to disk as an EMF
'Public Function fSaveImagetoDisk(ctl As Access.Image) As Boolean
'Dim sName As String
'Dim lngRet As Long
'Dim hEMF As Long
'' handle to Clipboard memory EMF
'Dim hMetafile As Long
'
'' handle to Metafile DC
''Dim hDCMeta As Long
'
'' Array to hold binary copy of Enhanced Metafile
'' we will create.
'Dim arrayMeta() As Byte
'
'' Open File Dialog
'sName = fSavePicture
'    If Len(sName & vbNullString) = 0 Then
'    fSaveImagetoDisk = False
'    Exit Function
'End If
'
'lngRet = FPictureDataToClipBoard(ctl)
'' Geta handle to an EMF from the Clipboard
'hMetafile = GetClipBoard(CF_ENHMETAFILE)
'
'' Grab the contents of the Metafile
'lngRet = apiGetEnhMetaFileBits(hMetafile, 0, ByVal 0&)
'ReDim arrayMeta((lngRet - 1) + 8)
'lngRet = apiGetEnhMetaFileBits(hMetafile, lngRet, arrayMeta(8))
'
'' Delete EMF memory footprint.
'lngRet = apiDeleteEnhMetaFile(hMetafile)
'
'' If the first 40 bytes of a PictureData prop are
'' not a BITMAPINFOHEADER structure then we will find
'' a ClipBoard Format structure of 8 Bytes in length
'' signifying whether a Metafile or Enhanced Metafile is present.
'' The first 8 Bytes of a PictureData prop signify
'' that the data is structured as one of the
'' following ClipBoard Formats.
'' CF_ENHMETAFILE
'' CF_METAFILEPICT
'' So the first 4 bytes tell us the format of the data.
'' The next 4 bytes point to handle for a Memory Metafile.
'' This is not needed for our construction purposes.
'arrayMeta(0) = CF_ENHMETAFILE
'
'
'' Save to disk
'Dim fNum As Integer
'
'
'' Byte arrays to hold the PictureData prop
'Dim bArray() As Byte
'Dim cArray() As Byte
'
'
'
'' Resize to hold entire PictureData prop
''ReDim bArray(LenB(Me.JGSForm.Form.Image1.PictureData) - 1)
'' Resize to hold the EMF wrapped in the PictureData prop
'ReDim cArray(UBound(arrayMeta) - (8))
'
'' Copy to our array
''bArray = Me.JGSForm.Form.Image1.PictureData
'
'' Copy the embedded EMF - SKIP first 8 bytes
'For lngRet = 8 To UBound(cArray) ' - (1) '+ 8)
'    cArray(lngRet - 8) = arrayMeta(lngRet)
'Next
'
'' Get next avail file handle
'fNum = FreeFile
'
'
'' Let's Create/Open our new EMF File.
'Open sName For Binary As fNum
'
'' Write out the EMF
'Put fNum, , cArray
'
'' Close the File
'Close fNum
'
'
'
'
'End Function
'
 
 
 
Public Function gf_LoadPicture(ctl As Access.Image, Optional strfName As String = "", Optional AutoSize As Boolean = False) As Boolean
' Inputs
' ctl -> Access Image control
' strfName -> Optional name of Image file to load and bypass File Dialog
On Error GoTo Err_fLoadPicture
 
' Temp Vars
Dim lngRet As Long
Dim blRet As Boolean
 
'燨ur StdPicture object returned by LoadPicture
Dim hPic As Object
 
' Were we passed the Optional FileName and Path
'If Len(strfName & vbNullString) = 0 Then
'    ' Call the File Common Dialog Window
'    Dim clsDialog As Object
'    Dim strTemp As String
'
'    Set clsDialog = New clsSysCommonDialog
'
'    ' Fill in our structure
'    clsDialog.Filter = "All (*.*)" & Chr$(0) & "*.*" & Chr$(0)
'    clsDialog.Filter = clsDialog.Filter & "JPEG (*.JPG)" & Chr$(0) & "*.JPG" & Chr$(0)
'    clsDialog.Filter = clsDialog.Filter & "Gif (*.GIF)" & Chr$(0) & "*.GIF" & Chr$(0)
'    clsDialog.Filter = clsDialog.Filter & "Bitmap (*.BMP)" & Chr$(0) & "*.BMP" & Chr$(0)
'    clsDialog.Filter = clsDialog.Filter & "Enhanced Metafile (*.EMF)" & Chr$(0) & "*.EMF" & Chr$(0)
'    clsDialog.Filter = clsDialog.Filter & "Windows Metafile (*.WMF)" & Chr$(0) & "*.WMF" & Chr$(0)
'    clsDialog.Filter = clsDialog.Filter & "Icon (*.ICO)" & Chr$(0) & "*.ICO" & Chr$(0)
'    clsDialog.Filter = clsDialog.Filter & "Cursor (*.CUR)" & Chr$(0) & "*.CUR" & Chr$(0)
'
'
'    clsDialog.hDC = 0
'    clsDialog.MaxFileSize = 256
'    clsDialog.Max = 256
'    clsDialog.FileTitle = vbNullString
'    clsDialog.DialogTitle = "Please Select an Image File"
'    clsDialog.InitDir = vbNullString
'    clsDialog.DefaultExt = vbNullString
'
'    ' Display the File Dialog
'    clsDialog.ShowOpen
'
'    ' See if user clicked Cancel or even selected
'    ' the very same file already selected
'    strfName = clsDialog.Filename
'    If Len(strfName & vbNullString) = 0 Then
'    ' Raise the exception
'      Err.Raise vbObjectError + 513, "LoadJpegGif.modStdPic", _
'      "Please Select a Valid JPEG or GIF File"
'    End If
'
'' If we jumped to here then user supplied a FileName
'End If
 
' It may take a few seconds to render larger JPEGs.
' Set the MousePointer to "HOURGLASS"
Application.Screen.MousePointer = 11
  
'■oad the Picture as a StandardPicture object
Set hPic = LoadPicture(strfName)
'........................
'........................
 
 
 
'烫all our function to convert the StdPicture object
' into a DIB wrapped within an Enhanced Metafile
blRet = gf_CopyStdPicToImageData(hPic, ctl, , AutoSize)
' need error handling here
 
 
' Cleanup
gf_LoadPicture = True
 
Exit_LoadPic:
 
' Set the MousePointer back to Default
Application.Echo True
Application.Screen.MousePointer = 0
Err.Clear
Set hPic = Nothing
'Set clsDialog = Nothing
Exit Function
 
Err_fLoadPicture:
gf_LoadPicture = False
Application.Screen.MousePointer = 0
gf_MsgBox "出现错误", vbOKOnly + vbCritical, , Err
 
Resume Exit_LoadPic
 
End Function
 
Option Compare Database
 
 Const intPerPagNum = 6
 
Private mnodSelected As Object 'afNode
Private mPicPicture As StdPicture
Private mPicMouseIcon As StdPicture
 
Private Sub Form_Load()
search CurrentProject.Path & "\res\image\", "*.jpg"
     LoadPic
End Sub
 
 
 
'搜索目录下所有图片
Public Function search(ByVal strPath As String, Optional strSearch As String = "") As Boolean
Dim strFileDir() As String
Dim strFile As String
Dim i As Long
 
Dim lDirCount As Long
On Error GoTo MyErr
Dim rs As Object
'先清除表上一次搜索的结果
 
CodeProject.Connection.Execute "delete * from tblSysImageTmp"
 
'........................
'........................
            '如果找到是文件,就把这个文件添加到表中
            If strSearch = "" Then
                rs.AddNew
                rs("FFileName") = strFile
                'Form1.List1.AddItem strPath + strFile
            ElseIf LCase(GetExtName(strPath + strFile)) = LCase(GetExtName(strSearch)) Then
              '满足搜索条件,则处理该文件
              ' Form1.List1.AddItem strPath + strFile '将文件全名保存至列表框List1中
               rs.AddNew
                rs("FFileName") = strFile
            End If
            rs.Update
        End If
        
        strFile = Dir
Wend
For i = 0 To lDirCount - 1
     ' Form1.Label3.Caption = strPath + strFileDir(i)
      Call search(strPath + strFileDir(i), strSearch) '递归搜索子目录
Next
rs.Close
ReDim strFileDir(0) '将动态数组清空
search = True '搜索成功
Exit Function
MyErr:
search = False '搜索失败
End Function
 
 
 
 
 
Private Sub img1_Click()
    setBorder 1
End Sub
 
Private Sub img2_Click()
    setBorder 2
End Sub
 
Private Sub img3_Click()
    setBorder 3
End Sub
 
Private Sub img4_Click()
    setBorder 4
End Sub
 
Private Sub img5_Click()
    setBorder 5
End Sub
 
Private Sub img6_Click()
    setBorder 6
End Sub
'设置边框
Private Sub setBorder(rintSeq As Integer)
    Dim i As Integer
    Dim pic As StdPicture
    Controls("img" & rintSeq).BorderStyle = 1
  '........................
'........................
                    
          
            
            If Not (gf_IsNothingOrZero(pic)) Then
             Call gf_CopyStdPicToImageData(pic, ImgPre, , True)
            End If
    
    
    
End Sub
 
'页切换
Public Sub changePage(way As Boolean)
    Dim strSql As String
    Dim strFileName As String
    Dim strImg As String
    Dim rs As Object
    Dim lngRecCnt As Long
    Dim i As Integer, j As Integer
 
    Select Case way
        Case True
            If Nz(txtCurrPage.Value) = 1 Then
                gf_MsgBox "已经是第一页!", vbInformation
                Exit Sub
            Else
                '........................
                '........................
 
            
        Case False
            If Nz(txtCurrPage.Value) = Nz(txtTotlePage.Value) Then
                gf_MsgBox "已经是最后一页!", vbInformation
                Exit Sub
            Else    '
               '........................
               '........................
            End If
    End Select
 
    
    For j = 1 To 6
        Controls("img" & j).Visible = False
        Controls("lblID" & j).Visible = False
    Next
    
    Set rs = gf_OpenRecordset(strSql, CodeProject.Connection, intOpenStatic, intLockReadOnly)
     
    i = 0
    Do Until rs.EOF
        i = i + 1
       '........................
       '........................
        Controls("img" & i).Visible = True
        Controls("lblID" & i).Visible = True
        rs.MoveNext
    Loop
    rs.Close
    Set rs = Nothing
            txtCurrPage.SetFocus
            If txtCurrPage.Value = 1 Then
                cmdPre.Enabled = False
               ' cmdFirst.Enabled = False
            Else
                cmdPre.Enabled = True
               ' cmdFirst.Enabled = True
                
            End If
            If txtCurrPage.Value = Nz(txtTotlePage.Value) Then
                cmdNext.Enabled = False
               ' cmdLast.Enabled = False
            Else
                cmdNext.Enabled = True
              '  cmdLast.Enabled = True
            End If
    
End Sub
 
 
 
Private Sub cmdPre_Click()
    changePage True
End Sub
 
 
Private Sub cmdNext_Click()
    changePage False
End Sub
 
 
'加载图片
Private Sub LoadPic()
 Dim lngRecCnt As Long
 
 '........................
 '........................
     
         If Nz(Me.txtTotlePage.Value) > 1 Then Me.cmdNext.Enabled = True: Me.cmdPre.Enabled = True
   ' Me.cmdView.Enabled = True
   ' Me.cmdZoom.Enabled = True
  '  Me.cmdPrint.Enabled = True
     
   '  Exit Sub
    
    Dim strSql As String
    Dim strImg As String
    Dim rs As Object
    
    Dim i As Integer, j As Integer
    Dim strFileName As String
    Dim strExt As String
    txtCurrPage.Value = ""
    txtTotlePage.Value = ""
    
    '........................
    '........................
    
 
    strSql = "select top " & intPerPagNum & " FFileName from tblSysImageTmp "
 
    lngRecCnt = DCount("*", "tblSysImageTmp")
    Me.txtTotlePage = IIf((lngRecCnt Mod intPerPagNum) = 0, lngRecCnt / intPerPagNum, Int(lngRecCnt / intPerPagNum) + 1)
 
    
    txtCurrPage.Value = "1"
    
    Set rs = gf_OpenRecordset(strSql, CodeProject.Connection, intOpenStatic, intLockReadOnly)
    i = 0
    '........................
    '........................
    Loop
    rs.Close
    Set rs = Nothing
    If Nz(Me.txtTotlePage.Value) > 1 Then Me.cmdNext.Enabled = True: Me.cmdPre.Enabled = True
  '  Me.cmdView.Enabled = True
  '  Me.cmdZoom.Enabled = True
  '  Me.cmdPrint.Enabled = True
End Sub
 
 
'获取扩展名
Public Function GetExtName(strFileName As String) As String
Dim strTmp As String
Dim strByte As String
Dim i As Long
'........................
'........................
     If strByte <> "." Then
        strTmp = strByte + strTmp
    Else
      Exit For
    End If
Next i
GetExtName = strTmp
End Function
 
 
 
 
 
Public Function gf_IsNothingOrZero(pic As StdPicture) As Boolean
  On Error Resume Next
  gf_IsNothingOrZero = False
  If Not (pic Is Nothing) Then
    ' If Err.Number > 0 Then
       Err.Clear
      '........................
      '........................
       Else
         gf_IsNothingOrZero = True
       End If
   '  End If
  Else
    gf_IsNothingOrZero = True
  End If
End Function
 
 

 

发布人:zstmtony  
分享到:
点击次数:  更新时间:2018-02-28 11:16:07  【打印此页】  【关闭】
上一条:Access自动执行宏的妙用-Access经典源码剖析  下一条:通用读取文本文件模块-Access经典源码剖析



相关文章

  • • Access多层架构开发思路-Access经典源码剖析
  • • 数据自动导出多个Excel或者多个工作表-Access经典源码剖析
  • • 网站数据提取与采集-Access经典源码剖析
  • • Access控制outlook自动处理邮件-Access经典源码剖析
  • • VBA开发神器发布及培训--完全颠覆Access VBA的开发方式--平台插件VBA伴侣-Access经典源码剖析
  • • 能排序的列表框-Access经典源码剖析
  • • Access专业工资条打印-Access经典源码剖析
  • • Access调用网页功能-中英自动翻译功能-Access经典源码剖析

热门文章

热门产品

公司动态|在线留言|在线反馈|友情链接|会员中心|站内搜索|网站地图

中山市天鸣科技发展有限公司 版权所有 1999-2023 粤ICP备10043721号

QQ:18449932

Access应用 Access培训 Access开发 Access平台

access|数据库|access下载|access教程|access视频|access软件

Powered by MetInfo 5.3.12 ©2008-2025  www.metinfo.cn