[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 576
  • Last Modified:

Using document icons via VB6's resource editor.

In visual basic 6, I have created a program much like a text editor. When it opens for the first time, it installs itself into the registry, so that  *.cph  files (or documents) will open with it. How so I save the icon for these  *.cph  documents as a resource, using VB's resource editor, and install them when I run the program?
0
Sid_The_Kid
Asked:
Sid_The_Kid
  • 6
  • 3
1 Solution
 
peetmCommented:
You don't need to 'install them' [it], you just associate the document-type with A) your application, and B) an Icon resource to be used.

Here's an example of how to 'change' the icon associated with .JPG files - so, it points out the important stuff: http://windowsxp.mvps.org/jpgicon.htm

To add icons using the resource editor, just select 'Add Icon ...' I believe the order in which they appear - leaving the ID alone - will be the 'index' required e.g., the '8' in C:\Program Files\Internet Explorer\IEXPLORE.EXE,8 from the webpage pointed to above.
0
 
Sid_The_KidAuthor Commented:
Thanks for the response.

Ok I may have been misleading in my question. My program doesn't install, it just uses a registry key API to associate my  *.cph  document type to it, and it is also -already able to- set an icon for that document. The problem is that the way I have it set up is so that it takes its icon file from the same directory. In order to make the file more portable I would like to use the resource editor instead of an actual icon file, so that when I open my .exe file on other computers, or send it to people, I don't need to drag along the icon file. But I don't really know how to use the resource editor very well. So I am looking for the code that will allow me to use an icon from the resource editor instead of an external icon file.
0
 
Sid_The_KidAuthor Commented:
I've used the resource editor before for pictures, so I know it a little bit, but I have no clue how to use it with icons.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
peetmCommented:
Ok, well just do as I said - invoke the editor, browse-for/add an icon as a resource - rebuild your app.  you'd then alter the registry setting you used to reference your executable.  If you've one icon, just give that an ID of '1' in the resource editor, and change the registry setting to C:\YourApp.exe,1
0
 
Sid_The_KidAuthor Commented:
Cool can't wait to try this :P
0
 
Sid_The_KidAuthor Commented:
Alright, I seem to be having some problems getting your solution running. Maybe you will have better luck understanding the problem than I...

I am using the following sub head to associate my app to associate files:

Public Sub AssociateMyApp(ByVal sAppName As String, ByVal sEXE As String, ByVal sExt As String, Optional ByVal sCommand As String, Optional ByVal sIcon As String)

The perimiters have the following meaning:
ByVal sAppName As String - The name of the application
ByVal sEXE As String - The path and file name of the application
ByVal sExt As String - The file extention
Optional ByVal sCommand As String - don't care
Optional ByVal sIcon As String - The icon path and file name

So, I would assume that for this program to work, I would have to stick "c:\myapp.exe,1" in for sIcon. And when I do this, it does update the registrty under the 'default icon' key. But for some reason I can't get it to change the icon of my  *.cph  files. I have tried everything. In fact, in order to make sure that it was not an indexing problem, I added four icon resorces, and set the sIcon to "c:\myapp.exe,2", and changed all the IDs to 1, 2, 3 ,4 so that there was no reason for it not to work, and yet it still does not work. As a debugging step, I used windows to brows the exe file for icons, and if found two - the icon for the exe file, and the one I added in for the documents. Any Ideas?

Thanks for all your help. I am going to up the points to 500. I am going to close this accout as soon as I have a solution for this problem :P
0
 
Sid_The_KidAuthor Commented:
Ok I figured it out. I must be really dumb...

I was not really using the format "c:/myapp.exe,1". I was using the format: app.path & app.exename & ",1". All I needed to do was add the ".exe" onto that: app.path & app.exename & ".exe,1"

It works fine now. Thanks for the help.
0
 
peetmCommented:
Just a warning, app.path & app.exename won't work all of the time.  

E.g., you'll need a \ in there - if, and only if - your app isn't in a root folder.

    appPath = App.Path & IIf(Right$(App.Path, 1) <> "\", "\", "") & App.EXEName
0
 
Sid_The_KidAuthor Commented:
Oh yea I have that I just forgot to include the \ in my last comment.
0

Featured Post

Independent Software Vendors: 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!

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now