Animate an icon of titlebar...

Just starting out? Need help? Post your questions and find answers here.
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Animate an icon of titlebar...

Post by Tomi »

newly, i've interest to Parameters in titlebar!
I tried to animate an icon of titlebar.
result:

Code: Select all

Global aaa.l = 0, POSneg = 0
Procedure TimerRun(hw)
  Protected Path$
    Path$ = "c:\IconsFolder\" + Str(aaa) + ".ico"
   
  Window_Icon.l=LoadImage_(GetModuleHandle_(0), Path$,#IMAGE_ICON,16,16,#LR_LOADFROMFILE) 
  
  SendMessage_(hw, #WM_SETICON, 0, Window_Icon)
  If POSneg = 0
    aaa = aaa + 1
  Else
    aaa = aaa - 1
  EndIf
  If aaa > 6 : POSneg = 1 : EndIf
  If aaa < 0 : POSneg = 0 : EndIf
EndProcedure
hw = OpenWindow(0, 200, 200, 320,240,"AnimateIcon", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget)

SetTimer_(hw, 1, 128, @TimerRun()) 
  
Repeat    
  EventID.l = WaitWindowEvent()  
Until EventID = #PB_Event_CloseWindow 
but i don't sure this method is soft and Suitable and Permanent...
Indeed this method is good, but i don't sure.
Any Improvement is please and welcome.
Any Your Tip'n'Trick too.
Any...
Thanks in Advanced.
tomi

12K
IconsFolder.rar
http://rapidshare.com/files/209582944/I ... r.rar.html
eJan
Enthusiast
Enthusiast
Posts: 368
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Post by eJan »

Code: Select all

; eddy: http://www.purebasic.fr/english/viewtopic.php?p=258650#258650

ProcedureDLL ConvertToIconImage(image) ; Convert PB Image to PB Icon Image
  ;Check if image source is valid
  If Not IsImage(image) : ProcedureReturn : EndIf
  If ImageWidth(image) <> ImageHeight(image) : ProcedureReturn : EndIf
  Select ImageWidth(image)
    Case 16, 32, 48, 72, 128, 256
    Default : ProcedureReturn
  EndSelect

  ;Create 32-bits-color Icon
  Protected empty = CreateImage(#PB_Any, ImageWidth(image), ImageWidth(image), 1)
  Protected ICONINFO.ICONINFO
  ICONINFO\fIcon = 1
  ICONINFO\hbmMask = ImageID(empty)
  ICONINFO\hbmColor = ImageID(image)
  Protected icon = CreateIconIndirect_(@ICONINFO)
  FreeImage(empty)
  ;Update PB Image
  Protected *Bitmap.Long = IsImage(image) : DeleteObject_(*Bitmap\l)
  *Bitmap\l = icon




  ProcedureReturn image
EndProcedure
ProcedureDLL SetImageMaskColor(color) ; Set color to use as maskcolor
  Global ImageMaskColorForCreateAlphaImage
  ImageMaskColorForCreateAlphaImage = color
EndProcedure
ProcedureDLL CreateAlphaImage(image, alphachannel = 0) ; Create alpha image or masked image (32 bits)
  ;Create 32-bits-color image
  Protected w = ImageWidth(image)
  Protected h = ImageHeight(image)
  Protected paint = CreateImage(#PB_Any, w, h, 32)
  StartDrawing(ImageOutput(paint))
  DrawImage(ImageID(image), 0, 0)
  StopDrawing()

  ;Extract 32-bits-color bitmap
  Protected i, j
  Protected *rgba.RGBQUAD
  Protected bmp.BITMAP
  GetObject_(ImageID(paint), SizeOf(BITMAP), bmp)

  ;Apply Mask or Alpha layer
  If Not IsImage(alphachannel)
    Global ImageMaskColorForCreateAlphaImage
    Protected maskR = Red(ImageMaskColorForCreateAlphaImage)
    Protected maskG = Green(ImageMaskColorForCreateAlphaImage)
    Protected maskB = Blue(ImageMaskColorForCreateAlphaImage)

    For i = 0 To bmp\bmHeight - 1
      For j = 0 To bmp\bmWidthBytes - 1 Step 4
        *rgba = bmp\bmBits + bmp\bmWidthBytes * i + j
        *rgba\rgbReserved = $FF
        *rgba\rgbReserved * (#True XOr (*rgba\rgbBlue = maskB And *rgba\rgbGreen = maskG And *rgba\rgbRed = maskR))
      Next
    Next
  Else
    StartDrawing(ImageOutput(alphachannel))
    For i = 0 To bmp\bmHeight - 1
      For j = 0 To bmp\bmWidthBytes - 1 Step 4
        *rgba = bmp\bmBits + bmp\bmWidthBytes * i + j
        *rgba\rgbReserved = Point(j / 4, i) & $FF
      Next
    Next
    StopDrawing()
  EndIf

  ;Redraw image
  CompilerIf 1
  FreeImage(image)
  CopyImage(paint, image)
  CompilerElse
  CreateImage(image, w, h, 32)
  StartDrawing(ImageOutput(image))
  DrawAlphaImage(ImageID(paint), 0, 0)
  StopDrawing()
  CompilerEndIf
  FreeImage(paint)

  ProcedureReturn image
EndProcedure

;********************
;EXAMPLE
;********************
For ico = 1 To 32
  ;COLORS ( + MASKED COLOR )
  CreateImage(ico, 32, 32, 24)
  StartDrawing(ImageOutput(ico))
  FrontColor(#Black)
  Box(0, 0, 32, 32)

  FrontColor(#Red)
  For a = 0 To 360 Step 20
    r = Random(14) : Box(16 + r * Cos(a), 16 + r * Sin(a), 3, 3)
  Next
  StopDrawing()
  ;//// CREATE MASKED ICON
  SetImageMaskColor(#Black)
  CreateAlphaImage(ico)
  ConvertToIconImage(ico)

  ;COLORS
  icoAlpha = ico + 32
  CreateImage(icoAlpha, 32, 32, 24)
  StartDrawing(ImageOutput(icoAlpha))
  FrontColor(#Blue)
  Box(0, 0, 32, 32)
  StopDrawing()
  ;ALPHACHANNEL
  alphachannel = CreateImage(#PB_Any, 32, 32, 8)
  StartDrawing(ImageOutput(alphachannel))
  FrontColor(#Black)
  Box(0, 0, 32, 32)

  For a = 0 To 360 Step 20
    r = Random(14)
    If r > 5
      FrontColor(256 - 256 * r / 16)
    Else
      FrontColor(255)
    EndIf
    Box(16.0 + r * Cos(a), 16.0 + r * Sin(a), 5, 5)
  Next
  StopDrawing()
  ;//// CREATE ALPHACHANNEL ICON
  CreateAlphaImage(icoAlpha, alphachannel)
  ConvertToIconImage(icoAlpha)
  FreeImage(alphachannel)
Next

win = OpenWindow(1, 0, 0, 300, 300, "Animated Transparent Icon", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
ButtonImageGadget(11, 5, 5, 100, 100, ImageID(1))
ButtonImageGadget(12, 110, 5, 100, 100, ImageID(1))
AddSysTrayIcon(111, win, ImageID(1))

Repeat
  event = WaitWindowEvent(200)

  If EventGadget() = 11
    ShowIconMode = 0
  ElseIf EventGadget() = 12
    ShowIconMode = 1
  EndIf

  If Not event
    anim = (anim + 1)%32

    iconMasked = ImageID(anim + 1)
    SetGadgetAttribute(11, #PB_Button_Image, iconMasked)

    iconAlpha = ImageID(anim + 33)
    SetGadgetAttribute(12, #PB_Button_Image, iconAlpha)

    If ShowIconMode
      SendMessage_(win, #WM_SETICON, 0, iconAlpha)
      ChangeSysTrayIcon(111, iconAlpha)
    Else
      SendMessage_(win, #WM_SETICON, 0, iconMasked)
      ChangeSysTrayIcon(111, iconMasked)
    EndIf
  EndIf
Until event = #PB_Event_CloseWindow
Win 11 25H2 Pro
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Post by Tomi »

Thanks Dear eJan
if somebody has a simple sample, put here please.
many thanks
User avatar
einander
Enthusiast
Enthusiast
Posts: 744
Joined: Thu Jun 26, 2003 2:09 am
Location: Spain (Galicia)

Post by einander »

I remember a snippet by Sparkie (buried on the forums, the snippet, not Sparkie) to put a gadget on caption.
I Can't find it, but here is a faked Animated Icon based on Sparkie's idea.

Code: Select all

Global _AnimICO,_Img,_ImGad
   
Macro NoFlickWin(Win)  ;- NoFlickWin(win) - this one is from Sparkie *************
  SetWindowLongPtr_(WindowID(Win), -20, GetWindowLongPtr_(WindowID(Win), -20) | $2000000)
EndMacro     

Procedure WinCallback(hwnd, msg, wParam, lParam)
  Protected Result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_MOVE,#WM_SIZE,#WM_SIZING,#WM_PAINT
      ResizeWindow(_AnimICO, WindowX(0)+4, WindowY(0) + 6, 20,20)
  EndSelect
  ProcedureReturn Result
EndProcedure

Procedure AnimIco()
  StartDrawing(ImageOutput(_Img))
    Box(Random(20),Random(20),4,4,Random(#White))
  StopDrawing()
  SetGadgetState(_ImGad,ImageID(_Img))
EndProcedure 
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<

hwnd=OpenWindow(0, 0, 0, 300, 100, "  Animated Caption Icon", #WS_OVERLAPPEDWINDOW|1)
StickyWindow(0,1)
_AnimICO=OpenWindow(-1, 30,0,20,20, "", #PB_Window_BorderLess, hwnd)

_Img=CreateImage(-1,20,20)
_ImGad=ImageGadget(-1, 0, 0, 20,20,ImageID(_Img))

SetActiveWindow(0)
SetWindowCallback(@WinCallback())
NoFlickWin(0)
NoFlickWin(_AnimICO)

UseGadgetList(hwnd)
ti=timeGetTime_()
Freq=60 
Repeat
  Ev=WaitWindowEvent(1)
  If timeGetTime_()-ti>Freq
    AnimIco()
    ti=timeGetTime_()
  EndIf
Until Ev= #WM_CLOSE
End
Cheers
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Post by Tomi »

Very thanks Dear einander
one by one recive diffrent methods 8)
Post Reply