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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Project Icon at runtime

Status
Not open for further replies.

pbrement

Programmer
Nov 16, 2000
4
FR
Can I change the icon of a project at runtime ?

The application is running from two different locations on a same station. I want different icons for each application, without having to rebuilt two executables with the good icon.
 
Create 2 shortcuts on the desktop or in a folder, then change the icon on each one. When you replace the exe, the shortcut icons will NOT be updated. Snaggs
tribesaddict@swbell.net
 
OK, it's an idea, but I'm worry with the task bar.

In fact, when you want to change the active task with the commande ALT-TAB, the visible icon will be always the same project icon and not the shortcut icon. Then the user who execute two sessions of the executable have a problem to know the selected task.

It's why I want to change exactly the project icon.

Does a solution exist ?
 
1. Include both icons in your project.
2. When you start an instance of your application you can get the path where the app is located. By testing this path you can set one icon or other depending of the result.
If doesn't matter the location, you can test if an instance of your application already run and change the icon for the second one.
 
Thanks for this method. I've already think to do it...

But how do you insert two icons in your project ?

And how do you assign one of both icons to your project when a new instance is started ?

Please, could you give more details ?
Perhaps a example of source ...
 
Try this as a test. Create a new project with three forms. Assign different icons to Form2 and Form3. Form2 and 3 will srve no function other than to be containers for icons.
[tt]
Private Sub Form_Load()
If App.Path = "C:\MyPath" Then
[tab]Form1.Icon = Form2.Icon
Else
[tab]Form1.Icon = Form3.Icon
End Sub
[/tt]

If an instance of your app starts in "C:\MyPath" the icon for Form1 will be the icon for Form2, otherwise it will be the icon for Form3. Whenever the project is minimized you will be able to see the appropriate icon in the taskbar.

VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Hi

What you can also do is .....

Include a default icon with your project (This is necessary in case my method fails) ;-)
Place the icon you want associated with the program in the same path as the program and rename it to appicon.ico

Here's a fragment

sIconFile = App.Path & "\appicon.ico"

If Dir(sIconFile) <> &quot;&quot; then
Form1.Icon = LoadPicture(sIconFile)
End If

Have fun
caf
 
This solution is good if you watch the taskbar at the bottom of the desktop.

My problem is to view different icons in the taskbar who appears in the center of screen when you type ALT-TAB.
And this method doesn't matter.

The project exist in two locations. I want a icon for each project / location, without having to built two projects :
one time with a first icon, two times with a other icon.

It's necessary to keep one project (for a elementary solution of installation and update of my software).

Please, this time : Give me the right answer.
 
I believe you have already received more than one good answer. You just haven't stopped to consider it yet.

The icon associated with a given project is irrelevant. You can't see that icon unless it is associated with a form. If you are running multiple instances of an app you will see a unique icon for each in the taskbar. The icon associated with a form appears on the left side of a form's title bar. When you switch tasks and reveal a form you can identify the app instance by glancing at the title bar.

If you need to make the ID of the app more obvious you can place a timer on a form, set the interval to 100 and add this code:
[tt]
Private Sub Timer1_Timer()
If Form1.Caption = App.Path Then
Form1.Caption = &quot;&quot;
Else
Form1.Caption = App.Path
End If
End Sub
[/tt]

It should be pretty obvious which app instance is flashing its location five times every second. It would be a little hard to miss.

VCA.gif

Alt255@Vorpalcom.Intranets.com
 
There is a totally different way to do this.
You can store the icons for your application in a resource file (use the resource editor in vb), and use a resource script to set a icon for the project.
I could explain it here, but there's a good explanation and a downloadable example at vbaccelerator:


I guess you've solved your problem by now, but it's always fun to find out a nice little trick...

Remedy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top