Solved

How To Change Icon at Runtime...

Posted on 2004-04-15
7
1,234 Views
Last Modified: 2007-11-27
I need to have the Internet Explorer ICON change if an IE window is on the 'www.yahoo.com' website.  I'm getting a syntax error on what I have so far:

Private Sub Command1_Click()
        Dim shWin As New ShellWindows
        Dim IE As InternetExplorer
        For Each IE In shWin
            If IE.LocationURL = "http://www.yahoo.com" Then
                msgbox "Yahoo found!"
                IE.Application.Icon.LoadfromFile(StartupDirectory + 'Busy.ico') <=== this is the line I'm getting the error
                Exit For
            End If
        Next
End Sub

0
Comment
Question by:frankmorrison
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 11

Expert Comment

by:bingie
ID: 10834801
(StartupDirectory + 'Busy.ico')

Change + to &, and ' to "

(StartupDirectory & "Busy.ico")

Bingie
0
 
LVL 11

Expert Comment

by:bingie
ID: 10834915
VB uses & to join strings and the ' for comments. So you have essentially commented out the "Busy.ico":
 
  IE.Application.Icon.LoadfromFile(StartupDirectory +

Also, + is a mathmatical operator. But is used in Java to join strings.

You might also need a "\" before the "\busy.ico" only if the StartupDirectory string doesn't have one at the end.

   IE.Application.Icon.LoadfromFile(StartupDirectory & "\Busy.ico")

0
 
LVL 1

Author Comment

by:frankmorrison
ID: 10836751
Bingie,

After fixing the syntax, I still get an error:

Run-time error "438"
object doesn't support this property or method

I even tried this:

IE.Application.Icon.LoadfromFile ("C:\Documents and Settings\Frank Morrison\Desktop\Busy.ico")

Got the same error "438"
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 17

Expert Comment

by:zzzzzooc
ID: 10841374
>> IE.Application.Icon.LoadfromFile

The IE.Application object does not have "Icon" so you can't use that to change it's icon.

Did you want to change the "Busy" icon (top-right) or the standard icon (top-left and taskbar)?
0
 
LVL 1

Author Comment

by:frankmorrison
ID: 10846681
I want to change the "The top-left" and "taskbar" icon
0
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 500 total points
ID: 10848100
I'm not aware of IE having any public methods to change it's window's standard icon. You can, however, send a WM_SETICON message along with a handle to an icon and it'll use that. I believe the icon has to be globally accessible though (such as in a DLL)..

Example...

Form1:
-------------

Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function LoadIcon Lib "user32" Alias "LoadIconA" (ByVal hInstance As Long, ByVal lpIconName As Any) As Long

Private Const WM_SETICON = &H80

Private Const ICON_SMALL = 0
Private Const ICON_BIG = 1

Private Const IDI_EXCLAMATION = 32515&
Private Sub Form_Load()
    Timer1.Interval = 1000
    Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
    Dim shWin As New ShellWindows
    Dim IE As InternetExplorer
    Dim lIcon As Long
    For Each IE In shWin
        If IE.LocationURL = "file:///C:/test.htm" Then
            lIcon = LoadIcon(0, IDI_EXCLAMATION)
            Call SendMessage(IE.hWnd, WM_SETICON, ICON_BIG, ByVal lIcon)
            Call SendMessage(IE.hWnd, WM_SETICON, ICON_SMALL, ByVal lIcon)
        End If
    Next
End Sub
0
 

Expert Comment

by:jchandrababu_a
ID: 11152040

 Dear Masters,

    I tried ur coding. But it is not working.

    I want to change the Icon of Any window, by passing
  Handle to that window, Icon file name.  

    I tried this as follows.

Private Sub Form_Load()
   
    lIcon = LoadIcon(Me.hWnd, "c:\setup1.ico")
    Call SendMessage(Me.hWnd, WM_SETICON, ICON_BIG, ByVal lIcon)
       
End Sub

     It is not giving any errors. But it is not working properly.
 
     Please help me as soon as possible....

     Thanks in advance.......
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

730 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