Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Resource Icon, logo, "print.ico"
Enum Equates Singular
ID_Timer = 500
ID_Graphic
End Enum
Global hDlg,hStaticIcon,hDynamicIcon As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Dynamic TaskBar Icon",300,300,350,150, %WS_OverlappedWindow To hDlg
Control Add Graphic, hDlg, %ID_Graphic,"", 50,100,32,32 ', %ws_border
Graphic Attach hDlg, %ID_Graphic
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
hStaticIcon = LoadIcon(GetModuleHandle(""), "logo")
SetClassLong(hDlg, %GCL_HICON, hStaticIcon) 'Icon from Windows
Case %WM_Size
If IsIconic(hDlg) Then
SetTimer(Cb.Hndl, %ID_Timer, 100, ByVal %NULL) 'uses callback messages
Else
SetClassLong(hDlg, %GCL_HICON, hStaticIcon) 'Icon from Windows
KillTimer Cb.Hndl, %ID_Timer
End If
Case %WM_Timer
Dialog Set Text hDlg, Time$
If IsIconic(hDlg) Then
hDynamicIcon = CreateColorIcon(%Blue)
SetClassLong(hDlg, %GCL_HICON, hDynamicIcon) 'Icon from Windows
Else
SetClassLong(hDlg, %GCL_HICON, hStaticIcon) 'Icon from Windows
Dialog ReDraw hDlg
End If
Case %WM_Destroy
KillTimer Cb.Hndl, %ID_Timer
End Select
End Function
Function CreateColorIcon(iColor As Long) As Dword
Local B As Bitmap, w,h,i,iPos As Long, bmp$, P As IconInfo
Local hBMPXor,hBMPAnd As Dword, bmpXOR(), bmpAND() As Byte
Static iCount As Long
'Create an XOR bitmap using the bitstring in bmp$
w = 32 : h = 32
Graphic Bitmap New w,h To hBMPXOR
Graphic Attach hBMPXOR, 0
Graphic Clear iColor
'draw
Graphic Box (0,0)-(iCount,32),0,%Red,%Red 'optional demo of animated toolbar icon
Graphic Box (iCount+1,0)-(iCount+1,32),0,%Gray,%Gray 'optional demo of animated toolbar icon
Incr iCount
If iCount > 32 Then iCount = 0
'create the bit array for the monochrome MASK bitmask. &HECE9D8 is transparent color
Graphic Get Bits To bmp$
Dim Mask(1 To w*h/8) As Static Byte
For i = 9 To Len(bmp$) Step 4
If Cvl(bmp$,i) = &HECE9D8 Then
Bit Set Mask(1),(iPos And &hfffffff8) + 7 - (iPos And &h7) 'bit is transparent
Else
Bit Reset Mask(1),(iPos And &hfffffff8) + 7 - (iPos And &h7) 'bit is not transparent
End If
Incr iPos
Next
'fill out the MASK bitmap variable information
B.bmType = 0 : B.bmWidth = w : B.bmHeight = h
B.bmWidthBytes = w/8 : B.bmPlanes = 1 : B.bmBitsPixel = 1
B.bmBits = VarPtr(Mask(1))
'create the MASK bitmap
hBMPAND = CreateBitmapIndirect(B)
'fill in the ICONINFO variable and create the icon (.xHotSpot/.yHotSpot are ignored)
P.fIcon = %True
P.hbmColor = hBMPXOR
P. hbmMask = hBMPAND
Function = CreateIconIndirect (P)
End Function
'gbs_01197
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm