Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Opening from Explorer

Posted on 1999-07-12
14
Medium Priority
?
169 Views
Last Modified: 2010-05-02
If I associate a file typ with my app, how do I set it up so that when I double click on a file of that type in Windows Explorer, my app loads it??
0
Comment
Question by:Phuzzy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
  • +1
14 Comments
 

Author Comment

by:Phuzzy
ID: 1524083
Edited text of question.
0
 
LVL 5

Expert Comment

by:KDivad
ID: 1524084
Do you need help associating the type? Or getting the file to load it when it is double-clicked?
0
 
LVL 5

Expert Comment

by:KDivad
ID: 1524085
Also, if the problem is in asscoiating, do you want associate it manually or through code?

I can tell you how to do all three (associate through code, associate manually and open double-cicked file), but I need to know which one you need.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Phuzzy
ID: 1524086
Associate through code, and open double-clicked file . . .
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 1524087
I answered this question on another forum yesterday, I'll post it here (this guy wanted to be able to make his program the default mp3 player)..

This make it so when you double-click on a file in explorer your program is executed alternatively with the filename as a parameter. Note that this add was meant for someone with low VB skills so it's kinda long..

"There's one way (copying code) or the better way to learn from an
 explanation:

 Open your registry editor program (regedit). Check the content of
 the HKEY_CLASSES_ROOT "directory". There u can see a
 "subdirectory" called ".mp3" this will be used to see what program
 should be run when the user runs a file with that extension. Look at
 what the "Standard Value" is, that's the description name for the
 extension.. Now there should be a "subdirectory" inside the
 HKEY_CLASSES_ROOT "directory" with the same name as the
 "Standard Value". There's some additional information about the
 file but the thingie u are interested in is the shell subdirectory. That
 contains a "open" directory which contains a "command" directory.
 The standard value in the shell\open\command tells what
 command line to run when a file is executed.

 And a example to help understand my very messy explanation:

 (Let's say u have Winamp registered with the extension .mp3)

 * Check the value of HKEY_CLASSES_ROOT\.mp3\(Standard
 Value) (if u have winamp it's "Winamp.File").

 * Then check the value of
 HKEY_CLASSES_ROOT\Winamp.File\Shell\Open\Command\(Standard
 Value)

 Now all u need to do is set that value to "YOUREXEFILENAME"
 and ur program will execute when u run a file with the extension
 .mp3

 If u need to have a parameter sent when u press the mp3 file u
 need to add %1 to that last "Standard Value", that will send u the
 parameters needed for your program to see what file is run. (Check
 the value of the string Command$ inside ur VB app).

 And one more thingie. All this I learned on my own just by opening
 my regedit program and used whatever I have "upstairs". So it
 doesn't hurt if u mess around a little. You can never do anything
 that a reinstallation can't fix ;) "
0
 
LVL 5

Expert Comment

by:KDivad
ID: 1524088
To add an association through code, you must create several keys and values.

The following are some of the registry API's and constants:

Type SECURITY_ATTRIBUTES
  nLength As Long
  lpSecurityDescriptor As Long
  bInheritHandle As Boolean
End Type

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
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
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, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
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 lpData As String, ByVal cbData As Long) As Long

Global Const REG_SZ = 1
Global Const HKCR = &H80000000
Global Const KEY_ALL_ACCESS = &HF003F


And some code(should work, untested):

Dim sa As Security_Attributes
x = RegCreateKeyEx(HKCR, ".YourExtension", 0, "", 0, KEY_ALL_ACCESS, sa, hRegKey, oc)
x = RegSetValueExString (hRegKey, "(Default)", 0, REG_SZ, "YourExtensionFile", Len("YourExtensionFile"))
x = RegCloseKey(hRegKey)
x = RegCreateKeyEx(HKCR, "YourExtensionFile", 0, "", 0, KEY_ALL_ACCESS, sa, hRegKey, oc)
x = RegSetValueExString (hRegKey, "(Default)", 0, REG_SZ, "Description of file type", Len("Description of file type"))
x = RegCloseKey(hRegKey)
x = RegCreateKeyEx(HKCR, "YourExtensionFile/shell", 0, "", 0, KEY_ALL_ACCESS, sa, hRegKey, oc)
x = RegSetValueExString (hRegKey, "(Default)", 0, REG_SZ, "Open", Len("Open"))
x = RegCloseKey(hRegKey)
x = RegCreateKeyEx(HKCR, "YourExtensionFile\shell\open\command", 0, "", 0, KEY_ALL_ACCESS, sa, hRegKey, oc)
x = RegSetValueExString (hRegKey, "(Default)", 0, REG_SZ, "Path to your app", Len("Path to your app"))
x = RegCloseKey(hRegKey)


The association should have been made by the above code.

.YourExtension is the .txt for a text file
YourExtensionFile is used to link the two main keys and for a text file is txtfile, but can be almost whatever you want
Description of file type is the same as "Text Document" for a text file.
The rest should be fairly easy to figure out.

If associated properly, when the file is double clicked it will be passed to your app as a command line. Use Command$ to retrieve it.
0
 

Author Comment

by:Phuzzy
ID: 1524089
Cheers, guys!
 P.S. Point taken about the messing about bit, that's my philosophy too, but I haven't had much time at the k/b of late. excuses, excuses!

0
 

Expert Comment

by:pakos
ID: 1524090
Phuzzy are u still alive ?
did u accept any of these comments sent to u by those expert, if no i'll post the answer soon.

cheers vbmaster :)

0
 

Author Comment

by:Phuzzy
ID: 1524091
It hasn't given me the option to mark this Q as answered - i'll keep messing with it.
0
 
LVL 5

Expert Comment

by:KDivad
ID: 1524092
That's because no-one has posted an answer. Someone will have to post an answer before you can accept it. If me or VBMaster answered your question satisfactorily, then that one will post an answer for you to accept. If not, Pakos wishes to post an answer for the points.
0
 

Expert Comment

by:pakos
ID: 1524093
That's fair.
thanx KDavid.
0
 
LVL 5

Expert Comment

by:KDivad
ID: 1524094
I thought so, but by my calendar it's been four days since he last posted to this page.
0
 

Author Comment

by:Phuzzy
ID: 1524095
I'll accept KDivad's answer if u post it ...
Sorry about the delay, as I said, not much k/b time.
0
 
LVL 5

Accepted Solution

by:
KDivad earned 300 total points
ID: 1524096
My answer.

No problem about the delay, I think we were all just starting to wonder. I guess that means the code worked for you?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question