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

sendmessage - change application icon

Status
Not open for further replies.

saintcb

Programmer
Oct 24, 2009
3
0
0
GB
Hi

I am trying to change the icon of a running external application , Notepad.
I can n't seem to see figure this out.

Thanks in advance.

The code I am using:

Declaration:
Public Declare Function LoadImage Lib "user32" _
Alias "LoadImageA" _
(ByVal hInst As Long, _
ByVal lpsz As String, _
ByVal un1 As Long, _
ByVal n1 As Long, _
ByVal n2 As Long, _
ByVal un2 As Long) _
As Long

Public Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal LParam As Long) _
As Long

Main code:
SetFormIcon(hwnd, "C:\myicon.ico")

Function:
Public Function SetFormIcon(ByVal hWnd As Long, ByVal IconPath As String) As Boolean
Dim hIcon As Long

hIcon = LoadImage(0&, IconPath, IMAGE_ICON, 16, 16, LR_LOADFROMFILE)

If hIcon <> 0 Then
Call SendMessage(hWnd, WM_SETICON, ICON_SMALL, hIcon)
Call SendMessage(hWnd, WM_SETICON, ICON_BIG, hIcon)
SetFormIcon = True
End If
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top