
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

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
Cheers
