Solved

How To Change Icon at Runtime...

Posted on 2004-04-15
7
1,227 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
Comment Utility
(StartupDirectory + 'Busy.ico')

Change + to &, and ' to "

(StartupDirectory & "Busy.ico")

Bingie
0
 
LVL 11

Expert Comment

by:bingie
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 17

Expert Comment

by:zzzzzooc
Comment Utility
>> 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
Comment Utility
I want to change the "The top-left" and "taskbar" icon
0
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 500 total points
Comment Utility
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
Comment Utility

 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now