设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
楼主: zhuyiwen
打印 上一主题 下一主题

Show 一个没有菜单的界面(ADP)

[复制链接]

点击这里给我发消息

11#
发表于 2011-7-19 14:08:39 | 只看该作者
回复 zhuyiwen 的帖子

  1. 下面的代码从位图句柄获取位图数据

  2. Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
  3. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
  4. Private Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
  5. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
  6. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  7. Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long

  8. Private Type bitmap
  9.     bmType As Long
  10.     bmWidth As Long
  11.     bmHeight As Long
  12.     bmWidthBytes As Long
  13.     bmPlanes As Integer
  14.     bmBitsPixel As Integer
  15.     bmBits As Long
  16. End Type

  17. Private Type BITMAPINFOHEADER
  18.         biSize As Long
  19.         biWidth As Long
  20.         biHeight As Long
  21.         biPlanes As Integer
  22.         biBitCount As Integer
  23.         biCompression As Long
  24.         biSizeImage As Long
  25.         biXPelsPerMeter As Long
  26.         biYPelsPerMeter As Long
  27.         biClrUsed As Long
  28.         biClrImportant As Long
  29. End Type
  30. Private Type RGBQUAD
  31.         rgbBlue As Byte
  32.         rgbGreen As Byte
  33.         rgbRed As Byte
  34.         rgbReserved As Byte
  35. End Type

  36. Private Type BITMAPINFO
  37.         bmiHeader As BITMAPINFOHEADER
  38.         bmiColors As RGBQUAD
  39. End Type

  40. Private Const DIB_RGB_COLORS = 0
  41. Private Const BI_RGB = 0&

  42. Private Function GetPictureDataFromBitmap(hBitmap As Long, bPictureData() As Byte) As Boolean
  43.     Dim bm As bitmap
  44.     Dim bi24BitInfo As BITMAPINFO
  45.     Dim hMemDc As Long
  46.     Dim bBytes() As Byte

  47.     GetObject hBitmap, Len(bm), bm
  48.     With bi24BitInfo.bmiHeader
  49.         .biWidth = bm.bmWidth
  50.         .biHeight = bm.bmHeight
  51.         .biBitCount = 24
  52.         .biCompression = BI_RGB
  53.         .biPlanes = 1
  54.         .biSize = Len(bi24BitInfo.bmiHeader)
  55.     End With
  56.     ReDim bBytes(1 To ((bm.bmWidth * 3 + 3) \ 4) * 4 * bm.bmHeight) As Byte
  57.     hMemDc = CreateCompatibleDC(0)
  58.     GetDIBits hMemDc, hBitmap, 0, bm.bmHeight, bBytes(1), bi24BitInfo, DIB_RGB_COLORS
  59.    
  60.     ReDim bPictureData(bi24BitInfo.bmiHeader.biSizeImage + 40)
  61.     CopyMemory bPictureData(40), bBytes(1), bi24BitInfo.bmiHeader.biSizeImage
  62.     CopyMemory bPictureData(0), bi24BitInfo.bmiHeader, 40

  63.     DeleteDC hMemDc
  64.     DeleteObject hBitmap

  65. End Function
复制代码
6楼的代码可以获得StdPicture对象,此代码可将StdPicture对象转为access.image控件支持的位图数据,此代码结合6楼的代码如下使用即可:
Dim  bPictureData()  As  Byte
GetPictureDataFromBitmap  LoadPictureFromField(f).Handle,  bPictureData()
Me.Image1.PictureData = bPictureData()

点击这里给我发消息

12#
 楼主| 发表于 2011-7-19 16:52:12 | 只看该作者
If you have a valid PictureData prop then there is a SysCmd method
available that will return a StdPicture interface from the contents of
an Image control.

Dim pic As stdole.IPictureDisp
set pic = SysCmd(712,NameofYourImageControlHere)

可以这样将PictureData转换成StdPicture?
有待测试

点击这里给我发消息

13#
 楼主| 发表于 2011-7-19 16:56:48 | 只看该作者
Function FPictureDataToStdPicture(PictureData As Variant) As IPicture
' Memory Vars
Dim hGlobalMemory As Long
Dim lpGlobalMemory As Long
Dim hClipMemory As Long

'Fill picture description
Dim lngRet As Long
Dim IPic As IPicture, picdes As PictDesc, iidIPicture As IID

' Cf_metafilepict structure
Dim cfm As MetaFilePict

' Handle to a Memory Metafile
Dim hMetafile As Long

' Which ClipBoard format is contained in the PictureData prop
Dim CBFormat As Long

' Byte array to hold the PictureData prop
Dim bArray() As Byte

' Temp var

'On Error GoTo Err_PtoC

' Resize to hold entire PictureData prop
ReDim bArray(LenB(PictureData) - 1)
APGDebug "Len of PictureData=" & (LenB(PictureData) - 1)
' Copy to our array
bArray = PictureData

' Determine which ClipBoard format we are using
Select Case bArray(0)

Case 40
' This is a straight DIB.
CBFormat = CF_DIB
' MSDN states to Allocate moveable|Shared Global memory
' for ClipBoard operations.
hGlobalMemory = GlobalAlloc(GMEM_MOVEABLE Or GMEM_SHARE Or
GMEM_ZEROINIT, UBound(bArray) + 1)
If hGlobalMemory = 0 Then _
Err.Raise vbObjectError + 515, "ImageToClipBoard.modImageToClipBoard",
_
"GlobalAlloc Failed..not enough memory"

' Lock this block to get a pointer we can use to this memory.
lpGlobalMemory = GlobalLock(hGlobalMemory)
If lpGlobalMemory = 0 Then _
Err.Raise vbObjectError + 516, "ImageToClipBoard.modImageToClipBoard",
_
"GlobalLock Failed"

' Copy DIB as is in its entirety
apiCopyMemory ByVal lpGlobalMemory, bArray(0), UBound(bArray) + 1

' Unlock the memory and then copy to the clipboard
If GlobalUnlock(hGlobalMemory) <> 0 Then _
Err.Raise vbObjectError + 517, "ImageToClipBoard.modImageToClipBoard",
_
"GlobalUnLock Failed"

Case CF_ENHMETAFILE
' New Enhanced Metafile(EMF)
CBFormat = CF_ENHMETAFILE
hMetafile = SetEnhMetaFileBits(UBound(bArray) + 1 - 8, bArray(8))

Case CF_METAFILEPICT
' Old Metafile format(WMF)
CBFormat = CF_METAFILEPICT
' Copy the Metafile Header over to our Local Structure
apiCopyMemory cfm, bArray(8), Len(cfm)
' Let's convert older WMF to EMF.
' Allows us to have a single solution for Metafiles.
' 24 is the number of bytes in the sum of the
' METAFILEPICT structure and the 8 byte ClipBoard Format struct.
hMetafile = SetWinMetaFileBits(UBound(bArray) + 24 + 1 - 8, bArray(24),
0&, cfm)

Case Else
'Should not happen
Err.Raise vbObjectError + 514, "ImageToClipBoard.modImageToClipBoard",
_
"Unrecognized PictureData ClipBoard format"

End Select

' Can we open the ClipBoard.
If OpenClipboard(0&) = 0 Then _
Err.Raise vbObjectError + 518, "ImageToClipBoard.modImageToClipBoard",
_
"OpenClipBoard Failed"

' Always empty the ClipBoard First. Not the friendliest thing
' to do if you have several programs interacting!
Call EmptyClipboard

' Now set the Image to the ClipBoard
If CBFormat = CF_ENHMETAFILE Or CBFormat = CF_METAFILEPICT Then

' Remember we can use this logic for both types of Metafiles
' because we converted the older WMF to the newer EMF.
'hClipMemory = SetClipboardData(CF_ENHMETAFILE, hMetafile)

picdes.Size = Len(picdes)
picdes.type = vbPicTypeEMetafile
picdes.hBmp = hMetafile

' No palette info here
' Everything is 24bit for now

'picdes.hPal = hPal
' ' Fill in magic IPicture GUID
{7BF80980-BF32-101A-8BBB-00AA00300CAB}
iidIPicture.Data1 = &H7BF80980
iidIPicture.Data2 = &HBF32
iidIPicture.Data3 = &H101A
iidIPicture.Data4(0) = &H8B
iidIPicture.Data4(1) = &HBB
iidIPicture.Data4(2) = &H0
iidIPicture.Data4(3) = &HAA
iidIPicture.Data4(4) = &H0
iidIPicture.Data4(5) = &H30
iidIPicture.Data4(6) = &HC
iidIPicture.Data4(7) = &HAB
'' Create picture from bitmap handle
lngRet = OleCreatePictureIndirect(picdes, iidIPicture, True, IPic)
'' Result will be valid Picture or Nothing-either way set it
Set FPictureDataToStdPicture = IPic

Else
'' We are dealing with a standard DIB.
hClipMemory = SetClipboardData(CBFormat, hGlobalMemory)

End If

Exit_PtoC:
Exit Function

Err_PtoC:
Set FPictureDataToStdPicture = Nothing
APGDebug Err.Description & Err.Source & ":" & Err.Number
Resume Exit_PtoC

End Function

点击这里给我发消息

14#
 楼主| 发表于 2011-7-19 17:08:15 | 只看该作者
  1. ' Benötigte API-Deklarationen
  2. Private Declare Function CreateStreamOnHGlobal Lib "ole32.dll" ( _
  3.   ByVal hGlobal As Long, _
  4.   ByVal fDeleteOnRelease As Long, _
  5.   lpIStream As IUnknown) As Long

  6. Private Declare Function OleLoadPicture Lib "oleaut32.dll" ( _
  7.   ByVal lpStream As IUnknown, _
  8.   ByVal lSize As Long, _
  9.   ByVal fRunmode As Long, _
  10.   riid As Any, _
  11.   lpIPicture As IPicture) As Long

  12. ' Bild aus Bytearray laden und
  13. ' als StdPicture-Objekt zurückgeben

  14. Public Function BytesToPicture(PictureData() As Byte) As StdPicture

  15.     Dim IID_IPicture(3) As Long
  16.     Dim oPicture As IPicture
  17.     Dim nResult As Long
  18.     Dim oStream As IUnknown
  19.     Dim hGlobal As Long

  20.     ' Array füllen um den KlassenID (CLSID) IID_IPICTURE
  21.     ' zu simulieren
  22.     IID_IPicture(0) = &H7BF80980
  23.     IID_IPicture(1) = &H101ABF32
  24.     IID_IPicture(2) = &HAA00BB8B
  25.     IID_IPicture(3) = &HAB0C3000

  26.   ' Stream erstellen
  27.     Call CreateStreamOnHGlobal(VarPtr(PictureData( _
  28.     LBound(PictureData))), 0, oStream)

  29.   ' OLE IPicture-Objekt erstellen
  30.     nResult = OleLoadPicture(oStream, 0, 0, IID_IPicture(0), oPicture)
  31.     If nResult = 0 Then
  32.         Set BytesToPicture = oPicture
  33.     End If

  34. End Function
复制代码


15#
发表于 2011-7-21 19:32:00 | 只看该作者

点击这里给我发消息

16#
发表于 2011-7-22 09:06:16 | 只看该作者
先收藏
17#
发表于 2011-7-22 16:01:57 | 只看该作者
老师,照顾新人,啥时上传附件?

点击这里给我发消息

18#
发表于 2011-9-28 17:23:00 | 只看该作者
很早就用老朱的这段代码了,谢谢老朱当时的共享{:soso_e113:}

点击这里给我发消息

19#
发表于 2013-4-27 10:31:10 | 只看该作者
{:soso_e179:}
20#
发表于 2013-5-7 08:25:13 | 只看该作者
能否公开代码哟,嘻嘻...
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-29 04:43 , Processed in 0.126270 second(s), 32 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表