VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Set Icons for any Form or Program

by J. van Gils (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

With this code you can place any Icon in the title bar of any Window, just by reffering to a .ico file or to the position of the Icon in a DLL.

Inputs
Handle of the window you want to change the icon of.
Assumes
You need to have the Window Handle (hWnd) of the window whitch Icon you want to change. This can be done by searching/finding it with the API-call Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Side Effects
none (that I know of)
API Declarations
Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const WM_SETICON = &H80

Rate Set Icons for any Form or Program

Public Function SetIcon(FormhWnd As Long)
Dim x, i As Long
  i = ExtractIcon(0, "c:\SomeDll.DLL", 3)
   'In this case you will extract the 3rd icon from SomeDll.DLL. In this
   'way you can extract any icon you want, just by reffering to the icon
   '(number) of the icon you want to extract in the dll. If you want to 
   'know the iconnumbers of a dll, you will have to use a recource editor
   '(like Borland Recource Workshop). You can also extract the Icon Handle
   'of a .ico file just by using some code like:
   'i=ExtractIcon(0,"c:\SomeIconFile.ico",0)
   'where SomeIconFile is the name of the icon you want to use.
   'Now finally set the icon in the title bar of the window
  x = DefWindowProc(FormhWnd, WM_SETICON, &H1, i)
End Function

Download this snippet    Add to My Saved Code

Set Icons for any Form or Program Comments

No comments have been posted about Set Icons for any Form or Program. Why not be the first to post a comment about Set Icons for any Form or Program.

Post your comment

Subject:
Message:
0/1000 characters