Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening Photo folders in VB6 4

Status
Not open for further replies.

Dues

Technical User
Jul 22, 2014
9
US
I have a VB6 tst program that consists of a form with an image box on it.
The Load sub has :

fnum as free file()
Open App. Path & "\Photos" for input as fnum
etc

Photos is a picture folder that would be accesable by App.Path method, I thought.
But I get a File not found message
What am I doing wrong?

I would like to have the program open the Photo foulder, and be able to click on a picture
to assign it to the image box, permenently.

Any help would be appreciated.
 
Here is another idea of what picture goes with what person:
Let’s say you are in charge of taking / collecting / storing / naming the pictures (files). If you would name the jpg file SusieQBrown.jpg for a person Susie Q. Brown, as soon as Susie would filled up her name in appropriate places (text boxes) on the form, you would just show the picture of her in the image box. No selection / arrays / image combos needed. Just magic. And you avoid selecting the wrong picture for that person because no selection is made by the person. Let computer do this job.


Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
here's something that illustrates one way of meeting your basic requirements:

You will need a VB6 project with two forms. On the first form place an Image control and a Command button captioned 'Photo'. Then paste in the following complex bit of code:

Code:
[blue]Option Explicit

Private Sub Command1_Click()
    Form2.Show
End Sub[/blue]

Ok, now we get complicated. We need to:

1) Add the Microsoft Internet Controls component; and
2) Add a reference to 'Microsoft Shell Controls and Automation'

Now put a webbrowser control on Form2. Then paste in the following code into Form2:

Code:
[blue]Option Explicit

Dim WithEvents shfolder As ShellFolderView

Public Enum FolderViewMode
    FVM_ICON = 1
    FVM_SMALLICON = 2
    FVM_LIST = 3
    fvm_details = 4
    FVM_THUMBNAIL = 5
    FVM_TILE = 6
    FVM_THUMBSTRIP = 7
End Enum

[green]' Just for this example. You'd need to set this as appropriate for your environment[/green]
Private Const PictureFolderURL = "file:\\C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures"

Private Sub Form_Load()
    WebBrowser1.Navigate PictureFolderURL
    WebBrowser1.Document.CurrentViewMode = FVM_THUMBNAIL
    Set shfolder = WebBrowser1.Document [green]'add interface to start tracking events for this document[/green]
    WebBrowser1.Move 0, 0, Form2.ScaleWidth, Form2.ScaleHeight
End Sub

Private Sub Form_Resize()
    WebBrowser1.Move 0, 0, Form2.ScaleWidth, Form2.ScaleHeight
End Sub

Private Function shfolder_DefaultVerbInvoked() As Boolean
    sh_DefaultVerbInvoked = False [green]' disable default action for doubleclick[/green]
End Function

Private Sub shfolder_SelectionChanged()
    [green]'shfolder.SelectItem shfolder.FocusedItem, 1 + 4 [green]' Select and highlight, but not needed for this example[/green][/green]
    GetPhoto
End Sub

Private Function shfolder_VerbInvoked() As Boolean
    MsgBox "Popup menu items are disabled"
    shfolder_VerbInvoked=False
End Function

Public Sub GetPhoto()
    Form1.Image1 = LoadPicture(shfolder.FocusedItem.Path)
    Form1.Image1.ToolTipText = shfolder.FocusedItem.Path
    Unload Me
End Sub[/blue]

And that's it. This basically does exactly what you described in your post of 4 Aug 14 13:50
It is just example code, not bulletproof - but illustrates how we can leverage already existing functionality for our own use with fairly minimal effort.
 
I like this answer (GetPhoto doesn't need to be Public above), however I had the idea that this can fail beginning with Windows 7 which often substitutes an undocumented "item view" control for the SysListView32 Common Control you normally get.

Probably doesn't matter if ShellFolderView's members expose enough functionality though. I have some programs myself that have to subclass the SysListView32 window inside ShellFolderView to do some fancier stuff.
 
Thank you strongm and dilitante,
last night I hit on a way that I think can make this work. Using a DriveListBox and Directorylistbox, I can access and open the Photo folder.
I'll work on it.
 
Is there really an issue with the use of the CommonDialog.ShowOpen?

If needed the user can change the view of the folder to show thumbnails. I believe on most supported versions of Windows it will "remember" the selected view for subsequent usages of a particular folder.

Or is it another issue? Maybe you need to have more control so the user can't navigate away to subfolders or some other folder?
 
OK Andy and dilettante
I havea a program with 1 Form and the following code:

Option Explicit
Dim DD As Integer, Pict As String, fnum As Integer

Private Sub Command1_Click() 'End
Unload Form1
End
End Sub

Private Sub Dir1_Change()
File1.Path = Dir1.Path
File1.Visible = True
End Sub

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

Private Sub Command3_Click()
On Error Resume Next
For DD = 0 To File1.ListCount - 1
Pict = Dir1 & "\" & File1.List(DD)
Image1(DD).Picture = LoadPicture(Pict)
Next
End Sub

Private Sub Image1_Click(Index As Integer)
On Error Resume Next
Pict = Dir1 & "\" & File1.List(Index)
Image2.Picture = LoadPicture(Pict)
End Sub

The Form has a DriveListBox, DirectoryListBox, Get Photo Button,FileListBox, an array of Image1(0 to 9) boxes, a larger Image2 box and an "End" button. When one Clicks on one of the small Image1 picture, that picture is assigned to Image2 which will be recorded.
The Photos folder is in the program VB6 folder.
The program works as I intended, but perhaps you may suggest some improvments.
To start the program, the user has to double click "Photos" in the list box. Can this step be eliminated so that double clicking "Photos" is done automaticlly when the program starts?

This is only a test program, I will later add means to record and save the information so that a user can click on a name in the FileListBox amd that person's information and foto shown.
Thank you for any help
 
Quick question - why use the DriveListBox, DirectoryListBox, and FileListBox controls in preference to dilettante's advised use of the CommonDialog?

Those controls are a legacy from a time when the CommonDialog control did not exist. Is it, as he suggests, perhaps because you want to restrict what the users can do?
 
CommonDialog was actually my idea. Along with naming the photo files corresponding to people’s full names (no selection by user needed), and the use of ImageCombo control which should do exactly what Dues needs. Most of those ideas were ignored and not even responded to :-(



Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Yes, sorry. Wrongly credited.

>the use of ImageCombo control which should do exactly what Dues needs

Hmm. Not convinced, I'm afraid. I'd suggest that the ListView would be a better control for this, and better meet the described requirement. In either case you've got some work to do to make the images all appear as similarly sized thumbnails, since I think it is safe to assume that the source photos may be a) of differing sizes; and b) larger than a typical thumbnail.


 
The VB OCX ListView wrappers have some annoying quirks, in both versions 5 and 6.

When used in icon view with .LabelWrap = True long label values (ListItem.Text) can result in item arrangement problems. Just cosmetic but a nuisance nonetheless.

As your code "fills" the ListView, items will be added in a grid fashion as expected but a wrapped long label value seems to cause "gaps" in the grid arrangement. Everything snaps back "correctly" if you either resize the ListView control by any amount or if you set .Arrange = lvwNone then back to lvwAutoTop or lvwAutoLeft (which makes everything "jump" a little). Calling .Refresh, etc. don't do the job.

This is more disconcerting to the user than it might sound.

Adding items via API calls doesn't have this problem but leaves many OCX control properties out of sync with the underlying SysListView32 control.
 
Hence my solution, which avoids this nonsense ;-) (mind you, it has its own quirks ...)
 
One annoying feature of Commomdialog is it normally won't open showing the thumbnails by default
Perhaps a more experienced person may know how to use an API or method to do this?
Then it should satisfy the questioner I would think.
 
CommonDialog was actually my idea. Along with naming the photo files corresponding to people’s full names (no selection by user needed)

From this and other posts, it seems that there is no need for any selection process at all. If you can use a fixed path and name the image files to match the people's names, then any kind of selection by the user can be made redundant.

For example, if the name is entered into Text1, and clicking Command1 loads the picture into Picture1, then you can simply do this:

Code:
Private Sub Command1_Click()
    Dim sFile As String
    Dim lLen As Long
    sFile = "C:\Photos\" & Text1.Text & ".jpg"
    On Error Resume Next
    lLen = FileLen(sFile)
    If Err Then
        Picture1.Picture = Nothing
    Else
        Picture1.Picture = LoadPicture(sFile)
    End If
    On Error Goto 0
End Sub

In other words, don't over complicate things unless you have to. Use the KISS approach whenever you can.

Heaven doesn't want me, and Hell's afraid I'll take over!
 
It seems odd that there'd be some fixed folder, considering these are sort of "ID photos." They would need to be brought in from a camera or removable media or... well someplace.

Why not just support drag and drop to let the user drag from an Explorer window into the application?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top