[FIXED]: Balloon click [callback] not working consistently

Just starting out? Need help? Post your questions and find answers here.
ctg
User
User
Posts: 21
Joined: Mon Sep 15, 2008 1:43 am

[FIXED]: Balloon click [callback] not working consistently

Post by ctg »

G'day. :D

I have another problem to throw out there which when fixed will hopefully see the app I'm working on completed and mostly without bugs.

This is something I cannot figure out. I'm using balloontip code posted here on the forums [http://www.purebasic.fr/english/viewtop ... ht=balloon] and it works seemlessly without problems when run in it's original form. I've added it to my code and have added code since for quite a while, but do not know when the problem started occurring, so I cannot try to recall what I did to cause it.

Basically, I have a balloontip that spawns from a tray icon, which, when clicked, is suposed to do whatever I need it to. As a test, I have made it simply end the program. The callback only seems to work when it feels like it, and I cannot see the reason for its sporadic working/non-working state.

I have a debug line to show when the balloon callback is processed and the app is closed. The code is very messy, and I apologise for this. I have removed a ton of code to slim it down as best I can to try to pinpoint the cause and make it easier to understand when posted here. Half of this code has been ripped from examples here, and I wouldn't have much of an idea how it works.

If anyone is brave enough to take a stab at it, please do so. I am definitely not experienced in any form of programming language, so please bear with me if I appear to not understand or look like an idiot :lol:


Now to the code ;)...:

Code: Select all

Global str_logofilename$
Global str_archivesizewithscaling$
Global int_killstatusballooncountdown
Global int_balloonid

Structure IconData
  cbSize.l
  hwnd.l
  uID.l
  uFlags.l
  uCallbackMessage.l
  hIcon.l
  szTip.b[128]
  dwState.l
  dwStateMask.l
  szInfo.b[256]
  StructureUnion
    uTimeout.l
    uVersion.l
  EndStructureUnion
  szInfoTitle.b[64]
  dwInfoFlags.l
EndStructure

  #TRAY_ID = 999
  #NIM_ADD = $0
  #NIM_MODIFY = $1
  #NIM_DELETE = $2
  #NIF_MESSAGE = $1
  #NIF_ICON = $2
  #NIF_TIP = $4
  #NIF_STATE = $8
  #NIF_INFO = $10
  #NIS_SHAREDICON = $2
  #NIFF_NONE = $0
  #NIIF_INFO = $1
  #NIIF_WARNING = $2
  #NIIF_ERROR = $3
  #NIIF_NOSOUND = $10
  #NIN_BALLOONSHOW=$402
  #NIN_BALLOONHIDE=$403
  #NIN_BALLOONTIMEOUT =$404
  #NIN_BALLOONUSERCLICK=$405
  #NOTIFYICON_VERSION = $3
  #NOTIFYICONDATA_V1_SIZE = 88
  #NOTIFYICONDATA_V2_SIZE = 488
  #NOTIFYICONDATA_V3_SIZE = 504

Enumeration 
  #Window_0
  #Icon_Main
EndEnumeration

Define.l Event, EventWindow, EventGadget, EventType, EventMenu

Procedure.w GetDataSize()
 
If OpenLibrary(1,"VERSION.DLL")
  BuffSize.l= CallFunction(1,"GetFileVersionInfoSizeA","shell32.dll",0)
  If BuffSize>0
    databuf.s=Space(BuffSize-1)
    ;Dim databuf.b(BuffSize-1)
    Result=CallFunction(1,"GetFileVersionInfoA","shell32.dll",0,BuffSize,@databuf)
    Result=CallFunction(1,"VerQueryValueA",@databuf,"\",@lpBuffer,@puLen)
    CopyMemory(lpBuffer+10,@nVerMajor,2)
  EndIf
  CloseLibrary(1)
  Select nVerMajor
    Case 6
      ProcedureReturn #NOTIFYICONDATA_V3_SIZE
     
    Case 5
      ProcedureReturn #NOTIFYICONDATA_V2_SIZE
     
    Default
      ProcedureReturn #NOTIFYICONDATA_V1_SIZE
  EndSelect
EndIf

EndProcedure

Procedure StatusAreaAddIcon(tooltiptext.s)
  Balloon.IconData\cbSize=GetDataSize()
  Balloon\hwnd = WindowID(#Window_0)
  Balloon\uID = #TRAY_ID
  Balloon\uFlags = #NIF_MESSAGE | #NIF_ICON | #NIF_TIP
  Balloon\hIcon = ImageID(#Icon_Main)
  Balloon\dwState = #NIS_SHAREDICON
  Balloon\uCallbackMessage=#WM_USER
  If OSVersion() < #PB_OS_Windows_2000
    Balloon\uVersion = 0
  Else
    Balloon\uVersion = #NOTIFYICON_VERSION
  EndIf
  Balloon\uTimeout = 10000 ; The balloon will not disappear if you don't move the mouse!
  Balloon\dwInfoFlags = #NIIF_INFO
  If Balloon.IconData\cbSize=#NOTIFYICONDATA_V1_SIZE
    PokeS(@Balloon\szTip, tooltiptext,64)
  Else
    PokeS(@Balloon\szTip, tooltiptext,128)
  EndIf
 
  Result= CallFunction(0,"Shell_NotifyIcon",#NIM_ADD,@Balloon)
EndProcedure

Procedure StatusAreaRemoveIcon()
  Balloon.IconData\cbSize=GetDataSize()
  Balloon\hwnd = WindowID(#Window_0)
  Balloon\uID = #TRAY_ID
  Result= CallFunction(0,"Shell_NotifyIcon",#NIM_DELETE,@Balloon)
;   CloseWindow(#Window_0)
EndProcedure

Procedure ShowBalloonTip(title.s,maintext.s,tooltiptext.s,IconType.l)
  Balloon.IconData\cbSize=GetDataSize()
 
  Balloon\hwnd = WindowID(#Window_0)
  Balloon\uID = #TRAY_ID
  Balloon\uFlags =  #NIF_INFO | #NIF_MESSAGE | #NIF_ICON | #NIF_TIP
  Balloon\hIcon = ImageID(#Icon_Main)
  Balloon\dwState = #NIS_SHAREDICON
  Balloon\uCallbackMessage=#WM_USER
  Balloon\uTimeout = 30000
  If OSVersion() < #PB_OS_Windows_2000
    Balloon\uVersion = 0
  Else
    Balloon\uVersion = #NOTIFYICON_VERSION
  EndIf
  Balloon\dwInfoFlags = IconType
 
  If Balloon.IconData\cbSize=#NOTIFYICONDATA_V1_SIZE
    PokeS(@Balloon\szTip, tooltiptext,64)
  Else
    PokeS(@Balloon\szTip, tooltiptext,128)
    PokeS(@Balloon\szInfo,maintext.s,255)
    PokeS(@Balloon\szInfoTitle,title.s,63)
  EndIf
  Result= CallFunction(0,"Shell_NotifyIcon",#NIM_MODIFY,@Balloon)
EndProcedure

Procedure MyWindowCallback(WindowID, Message, wParam, lParam)
  Result = #PB_ProcessPureBasicEvents
  Select Message
    Case #WM_USER
      Select lParam
        Case #NIN_BALLOONUSERCLICK
          Debug "clicked"
          int_balloontipcountdown = 0
          StatusAreaRemoveIcon()
          End
        EndSelect
  EndSelect
  ProcedureReturn Result
EndProcedure

Procedure Timerbox(void)
StatusAreaAddIcon("Test script")
int_balloontipcountdown = 30
    While int_balloontipcountdown > 0
        int_balloontipcountdown = int_balloontipcountdown - 1
        Debug int_balloontipcountdown
        ShowBalloonTip("Test","Test text","Tooltip",#NIIF_WARNING)
        Delay(1000)
    Wend
    ShowBalloonTip("","","",#NIFF_NONE)
    int_balloontipcountdowncheck = 1
EndProcedure

Procedure SysTrayEvent(void)
OpenWindow(#Window_0, 0, 0, 0, 0, "", #PB_Window_Invisible)

While 1
Debug "test"
    Event = WaitWindowEvent()
    If Event = #PB_Event_SysTray
        If EventType() = #PB_EventType_LeftClick
;             Debug "Tray Icon Clicked"
        EndIf
    EndIf
Wend
EndProcedure

CreateThread(@SysTrayEvent(),0)

OpenLibrary(0,"shell32.dll")
OpenWindow(#Window_0,0,0,0,0,"",#PB_Window_Invisible)
If CreateGadgetList(WindowID(#Window_0))
    CatchImage(#Icon_Main,?Icon_Main)
    
    StatusAreaAddIcon("Test script")
EndIf
SetWindowCallback(@MyWindowCallback(),#Window_0)

If CreateGadgetList(WindowID(#Window_0))
    SetWindowCallback(@MyWindowCallback(),#Window_0)
    timerballoon = CreateThread(@TimerBox(),0)
    WaitThread(timerballoon)
EndIf

DataSection
Icon_Main:
IncludeBinary "Path to test icon"
Icon_End:
EndDataSection
Sample icon: http://converticon.com/images/122221537 ... 28x128.ico

Cheers :D
Last edited by ctg on Fri Sep 26, 2008 1:28 am, edited 2 times in total.
ctg
User
User
Posts: 21
Joined: Mon Sep 15, 2008 1:43 am

Post by ctg »

I have found most of the problem, but I do not know how to correctly fix it. I have posted the amended code below. Basically, WaitWindowEvent() is required to be run on every run of the loop, to catch input and pass it to the window callback [am I right here?].

This, however, requires that the WaitWindowEvent be in its own loop, which I cannot implement from what I can tell.

Code: Select all

Global int_killstatusballooncountdown
Global int_countdown

Structure IconData
  cbSize.l
  hwnd.l
  uID.l
  uFlags.l
  uCallbackMessage.l
  hIcon.l
  szTip.b[128]
  dwState.l
  dwStateMask.l
  szInfo.b[256]
  StructureUnion
    uTimeout.l
    uVersion.l
  EndStructureUnion
  szInfoTitle.b[64]
  dwInfoFlags.l
EndStructure

  #TRAY_ID = 999
  #NIM_ADD = $0
  #NIM_MODIFY = $1
  #NIM_DELETE = $2
  #NIF_MESSAGE = $1
  #NIF_ICON = $2
  #NIF_TIP = $4
  #NIF_STATE = $8
  #NIF_INFO = $10
  #NIS_SHAREDICON = $2
  #NIFF_NONE = $0
  #NIIF_INFO = $1
  #NIIF_WARNING = $2
  #NIIF_ERROR = $3
  #NIIF_NOSOUND = $10
  #NIN_BALLOONSHOW=$402
  #NIN_BALLOONHIDE=$403
  #NIN_BALLOONTIMEOUT =$404
  #NIN_BALLOONUSERCLICK=$405
  #NOTIFYICON_VERSION = $3
  #NOTIFYICONDATA_V1_SIZE = 88
  #NOTIFYICONDATA_V2_SIZE = 488
  #NOTIFYICONDATA_V3_SIZE = 504

Enumeration 
  #Window_0
  #Icon_Main
EndEnumeration

Define.l Event, EventWindow, EventGadget, EventType, EventMenu

Procedure MyWindowCallback(WindowID, Message, wParam, lParam)
  Result = #PB_ProcessPureBasicEvents
  Select Message
    Case #WM_USER
      Select lParam
        Case #WM_LBUTTONDOWN
          Debug "Left mousebutton click on Icon"
         
        Case #WM_RBUTTONDOWN
          Debug "Right mousebutton click on Icon"

        Case #WM_LBUTTONDBLCLK
          Debug "Left button doublecklick on Icon"
         
        Case #WM_MOUSEMOVE
          ;Debug "Mouse moved over TrayIcon"
         
        Case #NIN_BALLOONSHOW
          Debug "Show balloon"
         
        Case #NIN_BALLOONTIMEOUT
          Debug "Timeout or X pressed" ; The 'X' doesn't seem to be available in W2K?!
        Case #NIN_BALLOONUSERCLICK
          Debug "Balloon user click"
;           StatusAreaRemoveIcon()
          End
         
        Case #NIN_BALLOONHIDE
          Debug "Balloon closed"
         
      EndSelect
EndSelect
 
  ProcedureReturn Result
EndProcedure

Procedure.w GetDataSize()
 
If OpenLibrary(1,"VERSION.DLL")
  BuffSize.l= CallFunction(1,"GetFileVersionInfoSizeA","shell32.dll",0)
  If BuffSize>0
    databuf.s=Space(BuffSize-1)
    ;Dim databuf.b(BuffSize-1)
    Result=CallFunction(1,"GetFileVersionInfoA","shell32.dll",0,BuffSize,@databuf)
    Result=CallFunction(1,"VerQueryValueA",@databuf,"\",@lpBuffer,@puLen)
    CopyMemory(lpBuffer+10,@nVerMajor,2)
  EndIf
  CloseLibrary(1)
  Select nVerMajor
    Case 6
      ProcedureReturn #NOTIFYICONDATA_V3_SIZE
     
    Case 5
      ProcedureReturn #NOTIFYICONDATA_V2_SIZE
     
    Default
      ProcedureReturn #NOTIFYICONDATA_V1_SIZE
  EndSelect
EndIf

EndProcedure

Procedure StatusAreaAddIcon(tooltiptext.s)
  Balloon.IconData\cbSize=GetDataSize()
 
  Balloon\hwnd = WindowID(#Window_0)
  Balloon\uID = #TRAY_ID
  Balloon\uFlags = #NIF_MESSAGE | #NIF_ICON | #NIF_TIP
  Balloon\hIcon = ImageID(#Icon_Main)
  Balloon\dwState = #NIS_SHAREDICON
  Balloon\uCallbackMessage=#WM_USER
  If OSVersion() < #PB_OS_Windows_2000
    Balloon\uVersion = 0
  Else
    Balloon\uVersion = #NOTIFYICON_VERSION
  EndIf
  Balloon\uTimeout = 11000 ; The balloon will not disappear if you don't move the mouse!
  Balloon\dwInfoFlags = #NIIF_INFO
  If Balloon.IconData\cbSize=#NOTIFYICONDATA_V1_SIZE
    PokeS(@Balloon\szTip, tooltiptext,64)
  Else
    PokeS(@Balloon\szTip, tooltiptext,128)
  EndIf
 
  Result= CallFunction(0,"Shell_NotifyIcon",#NIM_ADD,@Balloon)
EndProcedure

Procedure StatusAreaRemoveIcon()
  Balloon.IconData\cbSize=GetDataSize()
  Balloon\hwnd = WindowID(#Window_0)
  Balloon\uID = #TRAY_ID
  Result= CallFunction(0,"Shell_NotifyIcon",#NIM_DELETE,@Balloon)
EndProcedure

Procedure ShowBalloonTip(title.s,maintext.s,tooltiptext.s,IconType.l)
  Balloon.IconData\cbSize=GetDataSize()
 
  Balloon\hwnd = WindowID(#Window_0)
  Balloon\uID = #TRAY_ID
  Balloon\uFlags =  #NIF_INFO | #NIF_MESSAGE | #NIF_ICON | #NIF_TIP
  Balloon\hIcon = ImageID(#Icon_Main)
  Balloon\dwState = #NIS_SHAREDICON
  Balloon\uCallbackMessage=#WM_USER
  Balloon\uTimeout = 10000
  If OSVersion() < #PB_OS_Windows_2000
    Balloon\uVersion = 0
  Else
    Balloon\uVersion = #NOTIFYICON_VERSION
  EndIf
  Balloon\dwInfoFlags = IconType
 
  If Balloon.IconData\cbSize=#NOTIFYICONDATA_V1_SIZE
    PokeS(@Balloon\szTip, tooltiptext,64)
  Else
    PokeS(@Balloon\szTip, tooltiptext,128)
    PokeS(@Balloon\szInfo,maintext.s,255)
    PokeS(@Balloon\szInfoTitle,title.s,63)
  EndIf
  Result= CallFunction(0,"Shell_NotifyIcon",#NIM_MODIFY,@Balloon)
EndProcedure

Procedure Timerbox()
int_balloontipcountdown = int_countdown
    While int_balloontipcountdown > 0
        WaitWindowEvent()
        int_balloontipcountdown = int_balloontipcountdown - 1
        Debug int_balloontipcountdown
        ShowBalloonTip("Test","Test text","Tooltip",#NIIF_WARNING)
        Delay(1000)
    Wend
    ShowBalloonTip("","","",#NIFF_NONE)
    int_balloontipcountdowncheck = 1
    StatusAreaRemoveIcon()
    End
EndProcedure

int_countdown = 10 ; Use this to change the timer value

OpenLibrary(0,"shell32.dll")

If OpenWindow(#Window_0,0,0,0,0,"",#PB_Window_Invisible)
    CatchImage(#Icon_Main,?Icon_Main)
    SetWindowCallback(@MyWindowCallback())
    StatusAreaAddIcon("Tool tip text")
    TimerBox()
; ==========================================================================================
;{ Uncomment the lines in this block and comment the line above to see the alternate method
;     int_balloontipcountdown = int_countdown 
;     While int_balloontipcountdown > 0
;         int_balloontipcountdown = int_balloontipcountdown - 1
;         Debug int_balloontipcountdown
;         ShowBalloonTip("Test","Test text","Tooltip",#NIIF_WARNING)
;         Delay(1000)
;     Wend
;     ShowBalloonTip("","","",#NIFF_NONE)
;     int_balloontipcountdowncheck = 1
; 
; Repeat
;   EventID = WaitWindowEvent()
;   If int_balloontipcountdowncheck = 1
;     Break
;   EndIf
; Until EventID = #PB_Event_CloseWindow
;}
; ==========================================================================================
EndIf
StatusAreaRemoveIcon()
CloseLibrary(0)

DataSection
Icon_Main:
IncludeBinary "Path to test icon"
Icon_End:
EndDataSection
If the method above is used, the callback will work, but only on 1000ms intervals [when the loop is run]. For some reason it will also stop after 5 seconds into the countdown and the countdown will no longer work, but the callback does. Weird.

If the commented code is uncommented and the line calling the proc is commented out, it will work, but only once the loop has completed will the callback receive all of the window events.

If someone could help me out here, it'd be excellent. Thanks. ;)
ctg
User
User
Posts: 21
Joined: Mon Sep 15, 2008 1:43 am

Post by ctg »

Well, I think I've fixed the problem. Added a separate procedure to count the 1 second delay, and used the loop I had previously to check whether the count variable had been incremented, and if so, show the balloon.

It's probably hard to understand my explanation, but anyway.

Code: Select all

Global str_archivesizewithscaling$
Global int_killstatusballooncountdown
Global int_countdown
Global int_countup
Global int_countupcheck

Structure IconData
  cbSize.l
  hwnd.l
  uID.l
  uFlags.l
  uCallbackMessage.l
  hIcon.l
  szTip.b[128]
  dwState.l
  dwStateMask.l
  szInfo.b[256]
  StructureUnion
    uTimeout.l
    uVersion.l
  EndStructureUnion
  szInfoTitle.b[64]
  dwInfoFlags.l
EndStructure

  #TRAY_ID = 999
  #NIM_ADD = $0
  #NIM_MODIFY = $1
  #NIM_DELETE = $2
  #NIF_MESSAGE = $1
  #NIF_ICON = $2
  #NIF_TIP = $4
  #NIF_STATE = $8
  #NIF_INFO = $10
  #NIS_SHAREDICON = $2
  #NIFF_NONE = $0
  #NIIF_INFO = $1
  #NIIF_WARNING = $2
  #NIIF_ERROR = $3
  #NIIF_NOSOUND = $10
  #NIN_BALLOONSHOW=$402
  #NIN_BALLOONHIDE=$403
  #NIN_BALLOONTIMEOUT =$404
  #NIN_BALLOONUSERCLICK=$405
  #NOTIFYICON_VERSION = $3
  #NOTIFYICONDATA_V1_SIZE = 88
  #NOTIFYICONDATA_V2_SIZE = 488
  #NOTIFYICONDATA_V3_SIZE = 504

Enumeration 
  #Window_0
  #Icon_Main
EndEnumeration

Define.l Event, EventWindow, EventGadget, EventType, EventMenu
Declare StatusAreaRemoveIcon()

Procedure MyWindowCallback(WindowID, Message, wParam, lParam)
  Result = #PB_ProcessPureBasicEvents
  Select Message
    Case #WM_USER
      Select lParam
        Case #WM_LBUTTONDOWN
          Debug "Left mousebutton click on Icon"
         
        Case #WM_RBUTTONDOWN
          Debug "Right mousebutton click on Icon"

        Case #WM_LBUTTONDBLCLK
          Debug "Left button doublecklick on Icon"
         
        Case #WM_MOUSEMOVE
          ;Debug "Mouse moved over TrayIcon"
         
        Case #NIN_BALLOONSHOW
          Debug "Show balloon"
         
        Case #NIN_BALLOONTIMEOUT
          Debug "Timeout or X pressed" ; The 'X' doesn't seem to be available in W2K?!
        Case #NIN_BALLOONUSERCLICK
          Debug "Balloon user click"
          StatusAreaRemoveIcon()
          End
         
        Case #NIN_BALLOONHIDE
          Debug "Balloon closed"
         
      EndSelect
EndSelect
 
  ProcedureReturn Result
EndProcedure

Procedure.w GetDataSize()
 
If OpenLibrary(1,"VERSION.DLL")
  BuffSize.l= CallFunction(1,"GetFileVersionInfoSizeA","shell32.dll",0)
  If BuffSize>0
    databuf.s=Space(BuffSize-1)
    ;Dim databuf.b(BuffSize-1)
    Result=CallFunction(1,"GetFileVersionInfoA","shell32.dll",0,BuffSize,@databuf)
    Result=CallFunction(1,"VerQueryValueA",@databuf,"\",@lpBuffer,@puLen)
    CopyMemory(lpBuffer+10,@nVerMajor,2)
  EndIf
  CloseLibrary(1)
  Select nVerMajor
    Case 6
      ProcedureReturn #NOTIFYICONDATA_V3_SIZE
     
    Case 5
      ProcedureReturn #NOTIFYICONDATA_V2_SIZE
     
    Default
      ProcedureReturn #NOTIFYICONDATA_V1_SIZE
  EndSelect
EndIf

EndProcedure

Procedure StatusAreaAddIcon(tooltiptext.s)
  Balloon.IconData\cbSize=GetDataSize()
 
  Balloon\hwnd = WindowID(#Window_0)
  Balloon\uID = #TRAY_ID
  Balloon\uFlags = #NIF_MESSAGE | #NIF_ICON | #NIF_TIP
  Balloon\hIcon = ImageID(#Icon_Main)
  Balloon\dwState = #NIS_SHAREDICON
  Balloon\uCallbackMessage=#WM_USER
  If OSVersion() < #PB_OS_Windows_2000
    Balloon\uVersion = 0
  Else
    Balloon\uVersion = #NOTIFYICON_VERSION
  EndIf
  Balloon\uTimeout = 11000 ; The balloon will not disappear if you don't move the mouse!
  Balloon\dwInfoFlags = #NIIF_INFO
  If Balloon.IconData\cbSize=#NOTIFYICONDATA_V1_SIZE
    PokeS(@Balloon\szTip, tooltiptext,64)
  Else
    PokeS(@Balloon\szTip, tooltiptext,128)
  EndIf
 
  Result= CallFunction(0,"Shell_NotifyIcon",#NIM_ADD,@Balloon)
EndProcedure

Procedure StatusAreaRemoveIcon()
  Balloon.IconData\cbSize=GetDataSize()
  Balloon\hwnd = WindowID(#Window_0)
  Balloon\uID = #TRAY_ID
  Result= CallFunction(0,"Shell_NotifyIcon",#NIM_DELETE,@Balloon)
EndProcedure

Procedure ShowBalloonTip(title.s,maintext.s,tooltiptext.s,IconType.l)
  Balloon.IconData\cbSize=GetDataSize()
 
  Balloon\hwnd = WindowID(#Window_0)
  Balloon\uID = #TRAY_ID
  Balloon\uFlags =  #NIF_INFO | #NIF_MESSAGE | #NIF_ICON | #NIF_TIP
  Balloon\hIcon = ImageID(#Icon_Main)
  Balloon\dwState = #NIS_SHAREDICON
  Balloon\uCallbackMessage=#WM_USER
  Balloon\uTimeout = 10000
  If OSVersion() < #PB_OS_Windows_2000
    Balloon\uVersion = 0
  Else
    Balloon\uVersion = #NOTIFYICON_VERSION
  EndIf
  Balloon\dwInfoFlags = IconType
 
  If Balloon.IconData\cbSize=#NOTIFYICONDATA_V1_SIZE
    PokeS(@Balloon\szTip, tooltiptext,64)
  Else
    PokeS(@Balloon\szTip, tooltiptext,128)
    PokeS(@Balloon\szInfo,maintext.s,255)
    PokeS(@Balloon\szInfoTitle,title.s,63)
  EndIf
  Result= CallFunction(0,"Shell_NotifyIcon",#NIM_MODIFY,@Balloon)
EndProcedure

Procedure Timerbox()
int_balloontipcountdown = int_countdown
    While int_balloontipcountdown > 0
        WaitWindowEvent()
        int_balloontipcountdown = int_balloontipcountdown - 1
        Debug int_balloontipcountdown
        ShowBalloonTip("Test","Test text","Tooltip",#NIIF_WARNING)
        Delay(1000)
    Wend
    ShowBalloonTip("","","",#NIFF_NONE)
    int_balloontipcountdowncheck = 1
    StatusAreaRemoveIcon()
    End
EndProcedure

Procedure CountIndex()
  While 1
    int_countup = int_countup + 1
    If int_balloontipcountdowncheck = 1
      Break
    ElseIf int_balloontipcountdowncheck = 0
      Delay(500)
      int_countupcheck = int_countup
      Delay(500)
    EndIf
  Wend
EndProcedure

int_countdown = 10 ; Use this to change the timer value

OpenLibrary(0,"shell32.dll")


If OpenWindow(#Window_0,0,0,0,0,"",#PB_Window_Invisible)
    CatchImage(#Icon_Main,?Icon_Main)
    SetWindowCallback(@MyWindowCallback())
    StatusAreaAddIcon("Tool tip text")
;     TimerBox()
; ==========================================================================================
;{ Uncomment the lines in this block and comment the line above to see the alternate method
    int_balloontipcountdown = int_countdown
    CreateThread(@CountIndex(),0)
    While int_balloontipcountdown > 0
        WindowEvent()
        Debug int_countup
        If int_countup > int_countupcheck 
            int_countupcheck = int_countup
            int_balloontipcountdown = int_balloontipcountdown - 1
            Debug int_balloontipcountdown
            ShowBalloonTip("Test","Test text","Tooltip",#NIIF_WARNING)
        EndIf
        Delay(50)
    Wend
    ShowBalloonTip("","","",#NIFF_NONE)
    int_balloontipcountdowncheck = 1
;}
; ==========================================================================================
EndIf
StatusAreaRemoveIcon()
CloseLibrary(0)

DataSection
Icon_Main:
IncludeBinary "Path to test icon"
Icon_End:
EndDataSection
Post Reply