VB icon

FYI: Alt+Tab Icon Updating

Email
Submitted on: 2/9/2015 5:48:00 PM
By: LaVolpe (from psc cd)  
Level: Intermediate
User Rating: By 5 Users
Compatibility: VB 6.0
Views: 1094
 
     How do you change the icon that appears in the Alt+Tab window? This is nothing new can be found on MSDN. The notes I added here are of interest. More info for skinning forms. Changing a form's icon doesn't affect the Alt+Tab window; you need to change the icon in an upper level, hidden window. Code below shows how. Notes to keep in mind.... The icon does NOT have to be one assigned to a form! If not, the only thing to remember is to cache that icon handle and don't destroy it until your application closes or you reassign using the same code below. Should you not cache the icon, and it is destroyed, the Alt+Tab will show a "blank/invisible" icon instead.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: FYI: Alt+Tab Icon Updating
' Description:How do you change the icon that appears in the Alt+Tab window? This is nothing new can be found on MSDN. The notes I added here are of interest. More info for skinning forms. Changing a form's icon doesn't affect the Alt+Tab window; you need to change the icon in an upper level, hidden window. Code below shows how. Notes to keep in mind.... The icon does NOT have to be one assigned to a form! If not, the only thing to remember is to cache that icon handle and don't destroy it until your application closes or you reassign using the same code below. Should you not cache the icon, and it is destroyed, the Alt+Tab will show a "blank/invisible" icon instead.
' By: LaVolpe (from psc cd)
'**************************************

Public Sub SetApplicationIcon _
(hIcon As Long, mainHwnd As Long)
' hIcon must be a 32x32 pixel icon
' mainHwnd can be any open form
' This will not work in IDE but 
' works when compiled
Dim tHwnd As Long, cParent As Long
Const ICON_BIG As Long = 1
Const GWL_HWNDPARENT = (-8)
' Get starting point
tHwnd = GetWindowLong(mainHwnd, GWL_HWNDPARENT)
' Get EXE's wrapper class 
' (all VB compiled apps have them)
Do While tHwnd
cParent = tHwnd
tHwnd = GetWindowLong(cParent, _
GWL_HWNDPARENT)
Loop
On Error Resume Next
' tell the wrapper class what icon to use
PostMessage cParent, WM_SETICON, _
 ICON_BIG, ByVal hIcon
End Sub


Other 61 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.