469,281 Members | 2,419 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,281 developers. It's quick & easy.

Picture browser and image scaling

Hiya,

Im currently in the process of developing a picture browser, I want it
to run off a CD, basically I have 2 questions for the group.

The first is how do I get the program to only view the contents of the
CD, at the moment i have a drop down drive menu that allows me to
select the drive, i want to be able to put the CD in and then have i
view only the CD contents, Ive considered just entering in my code D:\
but what happens if the drive isnt d:\ for instance, it wouldnt work.
Is there a way to sense the drive name and then use that in my code??

the second in a matter of scaling, at the moment my images expand to
there orignal size and i often only able to view the top right hand
corner, Is there a way to make all the images fit the picture box??
ive heard about the use of the image box but this doesnt tend to have
any boundarys and fills the entire window,

Ive inserted the code im using below

Cheers in advance

greg
__________________________________________________ ______________________
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
Dir1.Path = Left(Drive1.Drive, 2)
End Sub

Private Sub File1_Click()
On Error Resume Next
Picture1.Picture = LoadPicture(File1.Path + "\" + File1.FileName)
End Sub
__________________________________________________ ______________________
Jul 17 '05 #1
3 8102
> The first is how do I get the program to only view the contents of the
CD, at the moment i have a drop down drive menu that allows me to
select the drive, i want to be able to put the CD in and then have i
view only the CD contents, Ive considered just entering in my code D:\
but what happens if the drive isnt d:\ for instance, it wouldnt work.
Is there a way to sense the drive name and then use that in my code??


Consider this previous post of mine...

Rick - MVP

I've created a function that will find a file at the root level, or at a
specified path off of the root level, of a CD without relying on an error
handler. The function returns the drive letter (no backslash, although it
can be easily modified to have this if desired) of the first CD drive it
finds that has a CD in it which contains the file at the specified location.
The function is named CDLetterContaining and you could use it like this:

MsgBox "CD Drive """ & _
CDLetterContaining("readme.txt") & _
""" contains my ReadMe file."

Simply paste all of the following into your Form's code window or into a BAS
module.

Private Declare Function GetDriveType _
Lib "kernel32" Alias "GetDriveTypeA" _
(ByVal nDrive As String) As Long

Private Declare Function GetLogicalDriveStrings _
Lib "kernel32" Alias "GetLogicalDriveStringsA" _
(ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long

Private Declare Function GetVolumeInformation _
Lib "kernel32" Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, _
ByVal lpVolumeNameBuffer As String, _
ByVal nVolumeNameSize As Long, _
lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, _
lpFileSystemFlags As Long, _
ByVal lpFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long) As Long

Function CDLetterContaining(FileName As String) As String
Dim X As Long
Dim LengthUsed As Long
Dim Drives As String
Dim AvailableCDs As String
Dim SingleDriveLetter As String
'Get GetLogicalDriveStrings variable
Dim gldsBuffer As String * 255
'GetVolumeInformation variables
Dim gviBuffer As String
Dim gviBufferLength As Long
Dim gviSerialNumber As Long
Dim gviMaxComponentLen As Long
Dim gviFileSystemFlags As Long
Dim gviFileSystemNameBuff As String
Dim gviFileSystemNameSize As Long
If Left$(FileName, 1) = "\" Then
FileName = Mid$(FileName, 2)
End If
LengthUsed = GetLogicalDriveStrings(255, gldsBuffer)
Drives = Left$(gldsBuffer, LengthUsed)
Drives = Replace$(Drives, "\" & Chr$(0), "")
For X = 1 To Len(Drives) Step 2
SingleDriveLetter = Mid$(Drives, X, 2)
If GetDriveType(SingleDriveLetter) = 5 Then
GetVolumeInformation SingleDriveLetter, gviBuffer, _
gviBufferLength, gviSerialNumber, _
gviMaxComponentLen, gviFileSystemFlags, _
gviFileSystemNameBuff, gviFileSystemNameSize
If gviSerialNumber Then
If Len(Dir$(SingleDriveLetter & "\" & FileName)) Then
CDLetterContaining = SingleDriveLetter
Exit For
End If
End If
End If
Next
End Function
Jul 17 '05 #2
> the second in a matter of scaling, at the moment my images expand to
there orignal size and i often only able to view the top right hand
corner, Is there a way to make all the images fit the picture box??
ive heard about the use of the image box but this doesnt tend to have
any boundarys and fills the entire window,


From a previous post of mine...

If you don't care about the preserving the picture's original aspect ratio,
simply put the picture into an ImageBox with its Stretch property set to
True; put that ImageBox **IN** (on visibly on top of) a PictureBox and set
the ImageBox's Width and Height to the PictureBox's ScaleWidth and
ScaleHeight.. If you want to preserve the aspect ratio after the resize,
then perhaps the following previous post of mine will be of some help.

Rick - MVP

You will need to put your picture into an ImageBox and place that ImageBox
into a PictureBox. Then give the following Subroutine a try. It properly
fits the ImageBox (with its Stretch property set to False) into its
container (in this case, a PictureBox, but it would also work if the
container was a Frame, the Form, or anything else that can serve as a
container). So, for your program, use a PictureBox of whatever size you need
as a container for the ImageBox. (Make sure the ImageBox is *really*
contained in the PictureBox and not simply resting on top of it; cut it from
the Form, click on the PictureBox and paste it back into the now highlighted
PictureBox.)

The first parameter is the name you have given to the ImageBox. The optional
2nd argument allows you to specify a minimum number of pixel that the image
must be away from the closest edge of its container. As an example, you
could call the following subroutine like this

Image1.Picture = LoadPicture("c:\windows\clouds.bmp")
SetImageBoxSize Image1, 150

where your ImageBox is named Image1 and the picture won't come any closer
than 150 twips to an edge of its Container. Simply assign your picture to
the ImageBox control and call this subroutine.

Private Sub SetImageBoxSize(ImageBox As Image, _
Optional ImageReductionAmount As Long = 0)
Dim ParentRatio As Single
Dim PictureRatio As Single
Dim ContainerWidth As Single
Dim ContainerHeight As Single
Dim ContainerControl As Control
With ImageBox
.Visible = False
PictureRatio = .Width / .Height
On Error Resume Next
ContainerWidth = .Container.ScaleWidth
If Err.Number Then
ContainerWidth = .Container.Width
ContainerHeight = .Container.Height
Else
ContainerHeight = .Container.ScaleHeight
End If
ParentRatio = ContainerWidth / ContainerHeight
If ParentRatio < PictureRatio Then
.Width = ContainerWidth - 2 * ImageReductionAmount
.Height = .Width / PictureRatio
Else
.Height = ContainerHeight - 2 * ImageReductionAmount
.Width = .Height * PictureRatio
End If
.Move (ContainerWidth - .Width) \ 2, _
(ContainerHeight - .Height) \ 2
.Visible = True
End With
End Sub
Jul 17 '05 #3
Hmm! I forgot to tell you why I posted this particular function. The
assumption I made is that there will be a somewhat uniquely named file on
your CD (the name of your program for instance); simply use the posted
function to get what drive letter the CD containing it is in. Armed with
that, you can restrict any data reading (and subsequent display) directly to
that path and exclude all others.

Rick - MVP

"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message
news:ln********************@comcast.com...
The first is how do I get the program to only view the contents of the
CD, at the moment i have a drop down drive menu that allows me to
select the drive, i want to be able to put the CD in and then have i
view only the CD contents, Ive considered just entering in my code D:\
but what happens if the drive isnt d:\ for instance, it wouldnt work.
Is there a way to sense the drive name and then use that in my code??
Consider this previous post of mine...

Rick - MVP

I've created a function that will find a file at the root level, or at a
specified path off of the root level, of a CD without relying on an error
handler. The function returns the drive letter (no backslash, although it
can be easily modified to have this if desired) of the first CD drive it
finds that has a CD in it which contains the file at the specified

location. The function is named CDLetterContaining and you could use it like this:

MsgBox "CD Drive """ & _
CDLetterContaining("readme.txt") & _
""" contains my ReadMe file."

Simply paste all of the following into your Form's code window or into a BAS module.

Private Declare Function GetDriveType _
Lib "kernel32" Alias "GetDriveTypeA" _
(ByVal nDrive As String) As Long

Private Declare Function GetLogicalDriveStrings _
Lib "kernel32" Alias "GetLogicalDriveStringsA" _
(ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long

Private Declare Function GetVolumeInformation _
Lib "kernel32" Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, _
ByVal lpVolumeNameBuffer As String, _
ByVal nVolumeNameSize As Long, _
lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, _
lpFileSystemFlags As Long, _
ByVal lpFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long) As Long

Function CDLetterContaining(FileName As String) As String
Dim X As Long
Dim LengthUsed As Long
Dim Drives As String
Dim AvailableCDs As String
Dim SingleDriveLetter As String
'Get GetLogicalDriveStrings variable
Dim gldsBuffer As String * 255
'GetVolumeInformation variables
Dim gviBuffer As String
Dim gviBufferLength As Long
Dim gviSerialNumber As Long
Dim gviMaxComponentLen As Long
Dim gviFileSystemFlags As Long
Dim gviFileSystemNameBuff As String
Dim gviFileSystemNameSize As Long
If Left$(FileName, 1) = "\" Then
FileName = Mid$(FileName, 2)
End If
LengthUsed = GetLogicalDriveStrings(255, gldsBuffer)
Drives = Left$(gldsBuffer, LengthUsed)
Drives = Replace$(Drives, "\" & Chr$(0), "")
For X = 1 To Len(Drives) Step 2
SingleDriveLetter = Mid$(Drives, X, 2)
If GetDriveType(SingleDriveLetter) = 5 Then
GetVolumeInformation SingleDriveLetter, gviBuffer, _
gviBufferLength, gviSerialNumber, _
gviMaxComponentLen, gviFileSystemFlags, _
gviFileSystemNameBuff, gviFileSystemNameSize
If gviSerialNumber Then
If Len(Dir$(SingleDriveLetter & "\" & FileName)) Then
CDLetterContaining = SingleDriveLetter
Exit For
End If
End If
End If
Next
End Function

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Tim Streater | last post: by
1 post views Thread by Phil Powell | last post: by
4 posts views Thread by D. Alvarado | last post: by
10 posts views Thread by Chris Coho, Jr. | last post: by
3 posts views Thread by Stijn Goris | last post: by
6 posts views Thread by dave | last post: by
3 posts views Thread by Larry Serflaten | last post: by
3 posts views Thread by =?Utf-8?B?SlIx?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.