عرض الصور - الصور مختلفة الأسماء وموجودة في مكان واحد أو في عدة أمكنة مثال في الأكسس 2000

أضيف بتاريخ 26/8/1423هـ

في الأكسس 2000 لا يمكن عرض الصور مباشرة بدون استخدام كود .

وكذلك نحتاج في هذه الطريقة لزر أمر لنختار الصورة لكل سجل عند إنشاء السجل الجديد ويمكن اختيار الصور إما باستخدام كائن اكتف اكس أو بالكود ، والأخير أفضل لسهولته ولعدم وجود مشاكل في استخدامه ، وكذلك نحتاج لتخزين مسار كل صورة في الجدول لذلك أنشئ حقل نصي .

خطوات الإنشاء :

1- افتح النموذج في عرض التصميم ثم اضغط زر صورة من شريط أدوات المسمى مربع الأدوات ثم ارسم الصورة على النموذج :

2- سيظهر مربع حوار يطالبك باختيار الصورة الأولية :

اختر الصورة الأولية وهي التي ستعرض أولا .

فكرة : استخدم صورة فارغة بيضاء أو صورة مكتوب فيها سجل جديد عندما يكون النموذج بدون سجلات .

ثم اضغط موافق .

3- ستظهر الصورة كما في الشكل :

 

 

أنا هنا اخترت الصورة المسماة NewRecord.gif والتي تجدها مرفقة مع المثال .

الآن سم كائن الصورة الجديد باسم عارض_الصور .

ملاحظة هامة : اسم الحقل الذي نخزن فيه مسار كل صورة في مثالي اسمه صورته .

4- في حدث عند الحالي للنموذج اكتب :

On Error GoTo err_pic
If IsNull(صورته) Or صورته = "" Then
عارض_الصور.Picture = ""
Else
fLoadPicture عارض_الصور, صورته
End If
err_exit:
Exit Sub
err_pic:
If Err.Number = 2220 Then
MsgBox "الصورة غير موجودة."

DoCmd.Hourglass False
End If
Resume err_exit

 

5- ضع زر أمر على النموذج لإظهار مربع الحوار لاختيار ملف الصورة ، وفي حدث عند النقر له اكتب :

 

Dim picturepaht
picturepaht = GetOpenFile_CLT("", "اختر صورة :")
If picturepaht <> "" Then
صورته = picturepaht
Call Form_Current
End If

 

6- أنشئ وحدة نمطية عامة واكتب فيها :

 

Option Compare Database

' Declarations for Windows Common Dialogs procedures
Private Type CLTAPI_OPENFILE
strFilter As String ' Filter string
intFilterIndex As Long ' Initial Filter to display.
strInitialDir As String ' Initial directory for the dialog to open in.
strInitialFile As String ' Initial file name to populate the dialog with.
strDialogTitle As String ' Dialog title
strDefaultExtension As String ' Default extension to append to file If user didn't specify one.
lngFlags As Long ' Flags (see constant list) to be used.
strFullPathReturned As String ' Full path of file picked.
strFileNameReturned As String ' File name of file picked.
intFileOffset As Integer ' Offset in full path (strFullPathReturned) where the file name (strFileNameReturned) begins.
intFileExtension As Integer ' Offset in full path (strFullPathReturned) where the file extension begins.
End Type

Const ALLFILES = "All Files"

Private Type CLTAPI_WINOPENFILENAME
lStructSize As Long
hWndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustrFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustrData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Const OFN_ALLOWMULTISELECT = &H200
Const OFN_CREATEPROMPT = &H2000
Const OFN_EXPLORER = &H80000
Const OFN_FILEMUSTEXIST = &H1000
Const OFN_HIDEREADONLY = &H4
Const OFN_NOCHANGEDIR = &H8
Const OFN_NODEREFERENCELINKS = &H100000
Const OFN_NONETWORKBUTTON = &H20000
Const OFN_NOREADONLYRETURN = &H8000
Const OFN_NOVALIDATE = &H100
Const OFN_OVERWRITEPROMPT = &H2
Const OFN_PATHMUSTEXIST = &H800
Const OFN_READONLY = &H1
Const OFN_SHOWHELP = &H10

Declare Function CLTAPI_GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" _
(pOpenfilename As CLTAPI_WINOPENFILENAME) _
As Boolean

Declare Function CLTAPI_GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" _
(pOpenfilename As CLTAPI_WINOPENFILENAME) _
As Boolean

Declare Sub CLTAPI_ChooseColor Lib "msaccess.exe" Alias "#53" _
(ByVal hwnd As Long, rgb As Long)

Function GetOpenFile_CLT(strInitialDir As String, strTitle As String) As String
Dim fOK As Boolean
Dim typWinOpen As CLTAPI_WINOPENFILENAME
Dim typOpenFile As CLTAPI_OPENFILE
Dim strFilter As String

On Error GoTo PROC_ERR

' Set defaults for the structure
strFilter = CreateFilterString_CLT("JPEG (*.JPG)" & Chr$(0) & "*.JPG" & Chr$(0) & "Gif (*.GIF)" & Chr$(0) & "*.GIF" & Chr$(0))
If strInitialDir <> "" Then
typOpenFile.strInitialDir = strInitialDir
Else
typOpenFile.strInitialDir = CurDir()
End If

If strTitle <> "" Then
typOpenFile.strDialogTitle = strTitle
End If

typOpenFile.strFilter = strFilter
typOpenFile.lngFlags = OFN_HIDEREADONLY Or OFN_SHOWHELP

' Convert the CLT structure to a Win structure
ConvertCLT2Win typOpenFile, typWinOpen

' Call the Common dialog
fOK = CLTAPI_GetOpenFileName(typWinOpen)

' Convert the Win structure back to a CLT structure
ConvertWin2CLT typWinOpen, typOpenFile

GetOpenFile_CLT = typOpenFile.strFullPathReturned

PROC_EXIT:
Exit Function

PROC_ERR:
GetOpenFile_CLT = ""
Resume PROC_EXIT

End Function

Sub ConvertCLT2Win(CLT_Struct As CLTAPI_OPENFILE, Win_Struct As CLTAPI_WINOPENFILENAME)
' Comments : Converts the passed CLTAPI structure to a Windows structure
' Parameters: CLT_Struct - record of type CLTAPI_OPENFILE
' Win_Struct - record of type CLTAPI_WINOPENFILENAME
' Returns : Nothing
'
Dim strFile As String * 512

On Error GoTo PROC_ERR

Win_Struct.hWndOwner = Application.hWndAccessApp
Win_Struct.hInstance = 0

If CLT_Struct.strFilter = "" Then
Win_Struct.lpstrFilter = ALLFILES & Chr$(0) & "*.*" & Chr$(0)
Else
Win_Struct.lpstrFilter = CLT_Struct.strFilter
End If
Win_Struct.nFilterIndex = CLT_Struct.intFilterIndex

Win_Struct.lpstrFile = String(512, 0)
Win_Struct.nMaxFile = 511

Win_Struct.lpstrFileTitle = String$(512, 0)
Win_Struct.nMaxFileTitle = 511

Win_Struct.lpstrTitle = CLT_Struct.strDialogTitle
Win_Struct.lpstrInitialDir = CLT_Struct.strInitialDir
Win_Struct.lpstrDefExt = CLT_Struct.strDefaultExtension

Win_Struct.Flags = CLT_Struct.lngFlags

Win_Struct.lStructSize = Len(Win_Struct)

PROC_EXIT:
Exit Sub

PROC_ERR:
Resume PROC_EXIT

End Sub

Sub ConvertWin2CLT(Win_Struct As CLTAPI_WINOPENFILENAME, CLT_Struct As CLTAPI_OPENFILE)
' Comments : Converts the passed CLTAPI structure to a Windows structure
' Parameters: Win_Struct - record of type CLTAPI_WINOPENFILENAME
' CLT_Struct - record of type CLTAPI_OPENFILE
' Returns : Nothing
'
On Error GoTo PROC_ERR

CLT_Struct.strFullPathReturned = Left(Win_Struct.lpstrFile, InStr(Win_Struct.lpstrFile, vbNullChar) - 1)
CLT_Struct.strFileNameReturned = RemoveNulls_CLT(Win_Struct.lpstrFileTitle)
CLT_Struct.intFileOffset = Win_Struct.nFileOffset
CLT_Struct.intFileExtension = Win_Struct.nFileExtension

PROC_EXIT:
Exit Sub

PROC_ERR:
Resume PROC_EXIT

End Sub

Function CreateFilterString_CLT(ParamArray varFilt() As Variant) As String
' Comments : Builds a Windows formatted filter string for "file type"
' Parameters: varFilter - parameter array in the format:
' Text, Filter, Text, Filter ...
' Such As:
' "All Files (*.*)", "*.*", "Text Files (*.TXT)", "*.TXT"
' Returns : windows formatted filter string
'
Dim strFilter As String
Dim intCounter As Integer
Dim intParamCount As Integer

On Error GoTo PROC_ERR

' Get the count of paramaters passed to the Function
intParamCount = UBound(varFilt)

If (intParamCount <> -1) Then

' Count through each parameter
For intCounter = 0 To intParamCount
strFilter = strFilter & varFilt(intCounter) & Chr$(0)
Next

' Check for an even number of parameters
If (intParamCount Mod 2) = 0 Then
strFilter = strFilter & "*.*" & Chr$(0)
End If

End If

CreateFilterString_CLT = strFilter

PROC_EXIT:
Exit Function

PROC_ERR:
CreateFilterString_CLT = ""
Resume PROC_EXIT

End Function

Function RemoveNulls_CLT(strIn As String) As String
' Comments : Removes terminator from a string
' Parameters: strIn - string to modify
' Return : modified string
'
Dim intChr As Integer

intChr = InStr(strIn, Chr$(0))

If intChr > 0 Then
RemoveNulls_CLT = Left$(strIn, intChr - 1)
Else
RemoveNulls_CLT = strIn
End If

End Function

 

7- أنشئ وحدة نمطية عامة أخرى واكتب فيها :

Option Compare Database
Option Explicit

' هذه الوحدة مختصة بعرض الصور من نوع GIF
Public مسار_الوثيقة As String

Private Type POINTAPI
X As Long
Y As Long
End Type

Private Type RECTL
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Type SIZEL
cx As Long
cy As Long
End Type

Private Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
End Type

Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type

Private Type BITMAPINFOHEADER '40 bytes
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type

Private Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
' bmiColors As RGBQUAD ' No COlors 24 bit RGB
End Type


Private Declare Function apiCloseEnhMetaFile Lib "gdi32" _
Alias "CloseEnhMetaFile" (ByVal hdc As Long) As Long
' lprect as RECT changed to as BYVAL as Any to allow for NULL

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

Private Declare Function apiDeleteEnhMetaFile Lib "gdi32" _
Alias "DeleteEnhMetaFile" (ByVal hemf As Long) As Long

Private Declare Function GetEnhMetaFileBits Lib "gdi32" _
(ByVal hemf As Long, ByVal cbBuffer As Long, lpbBuffer As Byte) As Long

Private Declare Sub apiCopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" _
(Destination As Any, Source As Any, ByVal Length As Long)

Private Declare Function apiSelectObject Lib "gdi32" _
Alias "SelectObject" (ByVal hdc As Long, ByVal hObject As Long) As Long

Private Declare Function apiGetDC Lib "user32" _
Alias "GetDC" (ByVal hwnd As Long) As Long

Private Declare Function apiReleaseDC Lib "user32" _
Alias "ReleaseDC" (ByVal hwnd As Long, _
ByVal hdc As Long) As Long

Private Declare Function apiCreateCompatibleDC Lib "gdi32" _
Alias "CreateCompatibleDC" (ByVal hdc As Long) As Long

Private Declare Function apiDeleteDC Lib "gdi32" _
Alias "DeleteDC" (ByVal hdc As Long) As Long

Private Declare Function apiBitBlt Lib "gdi32" _
Alias "BitBlt" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, _
ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Private Declare Function apiDeleteObject Lib "gdi32" _
Alias "DeleteObject" (ByVal hObject As Long) As Long

Private Declare Function apiGetObject Lib "gdi32" Alias "GetObjectA" _
(ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long

' CONSTANTS

Private Const WM_HSCROLL = &H114
Private Const WM_VSCROLL = &H115
' Scroll Bar Commands
Private Const SB_LINEUP = 0
Private Const SB_LINELEFT = 0
Private Const SB_LINEDOWN = 1
Private Const SB_LINERIGHT = 1
Private Const SB_PAGEUP = 2
Private Const SB_PAGELEFT = 2
Private Const SB_PAGEDOWN = 3
Private Const SB_PAGERIGHT = 3
Private Const SB_THUMBPOSITION = 4
Private Const SB_THUMBTRACK = 5
Private Const SB_TOP = 6
Private Const SB_LEFT = 6
Private Const SB_BOTTOM = 7
Private Const SB_RIGHT = 7
Private Const SB_ENDSCROLL = 8

' 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


Function fStdPicToImageData(hStdPic As Object, ctl As Access.Image, _
Optional FileNamePath As String = "") As Boolean

'On Error GoTo ERR_SHOWPIC

' Temp Device Context handles
Dim hDCref As Long, hdc As Long

' Temp GDI Bitmap handles
Dim hBmap As Long
Dim hBmapOrig As Long

' Temp var to hold API returns
Dim lngRet As Long

' Bitmap structure to hold Image props
Dim Bm As BITMAP

' 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

' Temp DC to select StdPicture object into
hdc = apiCreateCompatibleDC(0)

' It must be GetDC not CreateCompatibleDC!!!
hDCref = apiGetDC(0)

' Make sure user hasn't tricked us by renaming
' a graphic file mistakenly to JPG OR GIF.

If hStdPic.Type <> 1 Then
Err.Raise vbObjectError + 523, "CreateBitmapFromImageCtl.modStdPic", _
"الكود يعرض صور من نوع GIF أو JPG فقط ." & vbCrLf & "اختر أحد هذين النوعين فقط"
End If

' Get the Original Images Width and Height props
lngRet = apiGetObject(hStdPic, Len(Bm), Bm)

' Can we read the picture dimensions
If Bm.bmWidth <= 0 Then
Err.Raise vbObjectError + 524, "CreateBitmapFromImageCtl.modStdPic", _
"Sorry...cannot read Image Dimensions. Please Select a Valid JPEG or GIF File"
End If

hBmapOrig = apiSelectObject(hdc, hStdPic)

' Create our Enhanced Metafile - Memory Based
hDCMeta = apiCreateEnhMetaFile(hDCref, vbNullString, 0&, vbNullString)

If hDCMeta = 0 Then
Err.Raise vbObjectError + 525, "CreateBitmapFromImageCtl.modStdPic", _
"Sorry...cannot Create Enhanced Metafile"
End If

' Copy the contents of our StdPicture object over
' into the Enhanced Metafile we created.
lngRet = apiBitBlt(hDCMeta, 0&, 0&, Bm.bmWidth, _
Bm.bmHeight, hdc, 0, 0, SRCCOPY)

' Cleanup our Bitmaps
If hBmapOrig <> 0 Then
lngRet = apiSelectObject(hdc, hBmapOrig)
Call apiDeleteObject(hBmap)
End If

' Delete our Memory DC
Call apiDeleteDC(hdc)

' Close EnhMetafile
If hDCMeta <> 0 Then
hMetafile = apiCloseEnhMetaFile(hDCMeta)
End If

' Grab the contents of the Metafile
lngRet = GetEnhMetaFileBits(hMetafile, 0, ByVal 0&)
ReDim arrayMeta((lngRet - 1) + 8)
lngRet = GetEnhMetaFileBits(hMetafile, lngRet, arrayMeta(8))

' Delete EMF memory footprint.
lngRet = apiDeleteEnhMetaFile(hMetafile)


arrayMeta(0) = CF_ENHMETAFILE
ctl.PictureData = arrayMeta

EXIT_SHOWPIC:
Call apiDeleteDC(hdc)
lngRet = apiReleaseDC(0&, hDCref)
Exit Function

ERR_SHOWPIC:
MsgBox Err.Description, vbOKOnly, Err.Source & ":" & Err.Number
Resume EXIT_SHOWPIC

End Function


Public Function fLoadPicture(ctl As Access.Image, Optional strfName As String = "") As Boolean

'On Error GoTo Err_fLoadPicture

' Temp Vars
Dim lngRet As Long
Dim blRet As Boolean

' Our 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

strfName = strfName
'clsDialog.FileName
If Len(strfName & vbNullString) = 0 Then
' Raise the exception
Err.Raise vbObjectError + 513, "CreateBitmapFromImageCtl.modStdPic", _
"الكود يعرض صور من نوع GIF أو JPG فقط ."
End If

End If

Application.Screen.MousePointer = 11

' Load the Picture as a StandardPicture object
Set hPic = LoadPicture(strfName)
If hPic = 0 Then
Err.Raise vbObjectError + 514, "CreateBitmapFromImageCtl.modStdPic", _
"الكود يعرض صور من نوع GIF أو JPG فقط ."
End If

blRet = fStdPicToImageData(hPic, ctl)

' Scroll the Form back to X:0,Y:0
ScrollToHome ctl

' Cleanup
fLoadPicture = 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:
fLoadPicture = False
MsgBox Err.Description, vbOKOnly, Err.Source & ":" & Err.Number
Resume Exit_LoadPic

End Function


Public Sub ScrollToHome(ctl As Control)
Dim lngRet As Long

' Temp counter
Dim lngTemp As Long

' Be careful because of Echo Off
On Error Resume Next

' Stop Screen Redraws
Application.Echo False

For lngTemp = 1 To 9
lngRet = SendMessage(ctl.Parent.hwnd, WM_VSCROLL, SB_PAGEUP, 0&)
lngRet = SendMessage(ctl.Parent.hwnd, WM_HSCROLL, SB_PAGELEFT, 0&)
Next lngTemp

' Start Screen Redraws
Application.Echo True

End Sub

مواضيع مرتبطة :

- مثال عن عرض صور GIF

- كيف تستورد وحدات نمطية لقاعدة بياناتك .

تحميل :

الوحدة النمطية الأولى

الوحدة النمطية الثانية

الأمثلة مضغوطة

تحتاج إلى برنامج فك الضغط

انقر هنا لتحميل البرنامج

مثال بالأكسس 2000