 |
| Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET). |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 21st, 2007, 02:22 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
|
|
Been wanting 2 know this for ages!
How do you do file associations, does it include registry handling?
By file associations i mean files that i want are linked to my program and when they're clicked they opened with my program. Also they have and icon which i set!
Cheers
------------------------------------------------
Apocolypse2005
Always ready and waiting to be helped!
__________________
Apocolypse2005, I'm a programmer - of sorts.
|
|

August 22nd, 2007, 03:42 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
In Windows Explorer, select [u]T</u>ools|Folder [u]O</u>ptions..., the File Types tab.
|
|

August 25th, 2007, 06:39 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
|
|
Oh my god! Really is that how you do file associations! Come on brian at least try a little hard! I'm sure that if I want to my program to be distributed that I want to write instructions to the user that when its installed they should
Quote:
quote:
Go into Windows Explorer, select Tools|Folder Options..., the File Types tab
|
I'm not an idiot brian! I find that reply insulting.
So I pose my question once again.
How do you assign your program and files created in runtime by your program; icons and associations?
|
|

August 27th, 2007, 12:33 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
It is ridiculous for you to get insulted. I don't know you. I don't know what you know. How can I possibly insult you?
Here, let me try:
Don't be so thin skinned.
(Your being so easily offended seems to put the preceeding statement in some question...)
If you had aske in your post something more like, âHow do you mak an installation package set up file associations for your app?â then the answer would have been quite different. If you want to be insulted less, try to ask what it is that you actually want to know, instead of making those who want to help you guess.
I came across this. It might not be helpful, but it's a thought (since I have been able to find nothing on this with respect to setup and deployment):
Code:
Option Explicit
Public Const REG_SZ As Long = 1
Public Const REG_DWORD As Long = 4
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const ERROR_NONE = 0
Public Const ERROR_BADDB = 1
Public Const ERROR_BADKEY = 2
Public Const ERROR_CANTOPEN = 3
Public Const ERROR_CANTREAD = 4
Public Const ERROR_CANTWRITE = 5
Public Const ERROR_OUTOFMEMORY = 6
Public Const ERROR_INVALID_PARAMETER = 7
Public Const ERROR_ACCESS_DENIED = 8
Public Const ERROR_INVALID_PARAMETERS = 87
Public Const ERROR_NO_MORE_ITEMS = 259
Public Const KEY_ALL_ACCESS = &H3F
Public Const REG_OPTION_NON_VOLATILE = 0
Public Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long
Public Declare Function RegCreateKeyEx _
Lib "advapi32.dll" Alias "RegCreateKeyExA" _
(ByVal hKey As Long, _
ByVal lpSubKey As String, _
ByVal Reserved As Long, _
ByVal lpClass As String, _
ByVal dwOptions As Long, _
ByVal samDesired As Long, _
ByVal lpSecurityAttributes As Long, _
phkResult As Long, _
lpdwDisposition As Long) As Long
Public Declare Function RegOpenKeyEx _
Lib "advapi32.dll" Alias "RegOpenKeyExA" _
(ByVal hKey As Long, _
ByVal lpSubKey As String, _
ByVal ulOptions As Long, _
ByVal samDesired As Long, _
phkResult As Long) As Long
Public Declare Function RegSetValueExString _
Lib "advapi32.dll" Alias "RegSetValueExA" _
(ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal Reserved As Long, _
ByVal dwType As Long, _
ByVal lpValue As String, _
ByVal cbData As Long) As Long
Public Declare Function RegSetValueExLong _
Lib "advapi32.dll" Alias "RegSetValueExA" _
(ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal Reserved As Long, _
ByVal dwType As Long, _
lpValue As Long, _
ByVal cbData As Long) As Long
Public Sub CreateAssociation()
Dim sPath As String
' File Associations begin with a listing of the default extension
' under HKEY_CLASSES_ROOT. So the first step is to create that
' root extension item
CreateNewKey ".xxx", HKEY_CLASSES_ROOT
' To the extension just added, add a subitem where the registry
' will look for commands relating to the .xxx extension
' ("MyApp.Document"). Its type is String (REG_SZ)
SetKeyValue ".xxx", "", "MyApp.Document", REG_SZ
' Create the 'MyApp.Document item under HKEY_CLASSES_ROOT.
' This is where you'll put the command line to execute or
' other shell statements necessary.
CreateNewKey "MyApp.Document\shell\open\command", _
HKEY_CLASSES_ROOT
' Set its default item to "MyApp Document". This is what is
' displayed in Explorer against for files with a xxx extension.
' Its type is String (REG_SZ)
SetKeyValue "MyApp.Document", "", "MyApp Document", REG_SZ
' Finally, add the path to myapp.exe. Remember to add %1 as
' the final command parameter to assure the app opens the
' passed command line item.
' (results in '"c:\LongPathname\Myapp.exe %1"). Again, its
' type is string.
sPath = "c:\LongPathname\Myapp.exe %1"
SetKeyValue "MyApp.Document\shell\open\command", "", _
sPath, REG_SZ
'All done
MsgBox "The file association has been made!"
End Sub
My thinking is that you could add to your app a test for the file association. If it is not found, then you could trigger that functionality to add it (without that stoopid MsgBox() stmnt...). Your app would have to be run at least one time to make this happen, of course.
|
|

August 31st, 2007, 04:28 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
|
|
Cool seems to be what i'm looking for! Thats what i run as its been setting up?!
|
|

August 31st, 2007, 11:45 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
My understanding of what I found on the net is that you would write your app to make this test every time it runs, and sets up the association if it finds that one does not exist.
Not as useful as having setup do it, but I was unable to even find an inference that using setup was a possibility. (One thing that gave me this impression is that there were 3rd party tools being sold to do this. How could they make a sale if Visual Studio provided a means to do it?)
|
|

September 1st, 2007, 06:48 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
|
|
Yeah, i could just make my own setup program! Be a bit of a task but it would mean i could customise it, do you know of any tutorials on how to use the progress bar (probably for advanced programmers). I could just use the setup and deployment program to get all the files need for the program in one place.
|
|

September 4th, 2007, 10:42 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
The progress bar is simplicity itself (I'm happy to say).
You add the control to a form, and it has properties for .Value, whether the display should look like blocks or a continuous bar, and I think a min and max.
I don't like the control much, but the interface shows pretty good crlarity of thought on the part of Microsoft.
|
|

September 12th, 2007, 07:18 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
|
|
I guess its just the code that surrounds the progress bar which is the hard part! An if its been used for loading then i guess you have to start a timer to get how long its through and probably how long it takes till it finished. But thats just getting confusing! Try this problem, if i were searching for files and i want the progress bar to report how far into the search it was is that possible?
|
|

September 21st, 2007, 11:36 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
Not really. You need to know how many files yo uwill be looking for (which would be the results of the search) before you search for them.
What I do in a situation lik ethis is to tell the user what's going on. (The actual choice of what to report is not as important as just reporting something.)
You'll notice in Windows' File-Search dialog you are told what folder is currently being examined. In addition there is an animated icon, which helps to dispel the suspician that the computer or the process might be be hung during really long searches.
Now, if you know in advance the total number of files, and you are going to be searching that set of files for specific text, then you can do a progress bar where Min would be 1, Max would be the file count, and each time you moved to the next file to examine you increment Value. But to do this you need to have the ability to take action each time the next file is selected. Using Windows file searching tools, you only can wait till they are through. You would have to write your own file-searching code. (That would be somewhat akin to reinventing the wheel...)
|
|
 |