Solved

How To Change Icon at Runtime...

Posted on 2004-04-15
7
1,229 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 code to programmatically convert pdf to excel 21 85
Visual Basic Excel Formatting error 4 102
Sending a email via excel using vba 6 79
Access 2013 combo box not working 3 43
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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

808 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