Date: 02-16-2022
Return to Index
created by gbSnippets
'draw on
' hDC = GetDC(hDlg)
' Ellipse hDC, 1,1,10,10
' ReleaseDC hDlg, hDC
' Dialog Set Text hDlg, Time$
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Resource "gbsnippets.pbr"
%ID_Timer = 500
Global hDlg, hIcon As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Animated Taskbar",300,300,200,200, %WS_OverlappedWindow To hDlg
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local hDC As Dword, temp$, iCount as Long
Select Case Cb.Msg
Case %WM_InitDialog
SetTimer(Cb.Hndl, %ID_Timer, 2000, ByVal %NULL) 'uses callback messages
Case %WM_Timer
If IsIconic(hDlg) Then
ModifyIcon hIcon, iCount
SendMessage hDlg, %WM_SETICON, %ICON_BIG, hIcon
End If
Case %WM_Destroy
KillTimer Cb.Hndl, %ID_Timer
End Select
End Function
'----------------------------------------------------------------
Sub ModifyIcon(hIcon AS DWord, ByVal lCount As Long)
'----------------------------------------------------------------
' Draw a number (lCount) over the icon (hIcon), then create a
' new icon from the resulting image and return a handle to it
Local uInfo AS ICONINFO, lRes As Long
Local hMemDC AS DWord, hOldBMP AS DWord, sText As String
Local hNewIcon AS DWord, rectDraw AS RECT, uBitmap AS BITMAP
lRes = GetIconInfo(hIcon, uInfo)
IF lRes <> 0 THEN
' Call succeeded
hMemDC = CreateCompatibleDC(ByVal %NULL)
IF hMemDC = 0 THEN
MSGBOX "CreateCompatibleDC failed : " & STR$(hMemDC), %MB_TASKMODAL
ELSE
' Get info for the bitmap
GetObject uInfo.hbmColor, SIZEOF(uBitmap), uBitmap
' and setup RECT
rectDraw.nLeft = 0 : rectDraw.nTop = 0 : rectDraw.nRight = uBitmap.bmWidth - 1 : rectDraw.nBottom = uBitmap.bmHeight - 1
' Get our bitmap ready to draw on
hOldBMP = SelectObject(hMemDC, uInfo.hbmColor)
' Format the count
sText = FORMAT$(lCount, "#0")
' Draw it
lRes = DrawText(hMemDC, BYCOPY sText, LEN(sText), rectDraw, %DT_CENTER OR %DT_VCENTER OR %DT_SINGLELINE)
' Put old bitmap back
SelectObject hMemDC, hOldBMP
' Create the new icon from the modified structure
hNewIcon = CreateIconIndirect(uInfo)
IF hNewIcon <> 0 THEN
' Worked ok - delete the old icon
DestroyIcon hIcon
' And pass the handle to the new one back
hIcon = hNewIcon
ELSE
MSGBOX "CreateIconIndirect failed", %MB_TASKMODAL
END IF
' Clean up the memory DC
DeleteDC hMemDC
END IF
' Note that we also need to clean up the 2 bitmaps we got in the structure
DeleteObject uInfo.hbmMask
DeleteObject uInfo.hbmColor
ELSE
MSGBOX "GetIconInfo failed", %MB_TASKMODAL
END IF
End Sub
'gbs_00883
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm