Seems like I am asking more questions lately than doing anything but I am getting there. The constant heat and nearby fires sort of kill the enthusiasm a bit.
I want to start a thread in the background to monitor activity and when there is none for a user specified period, lock the program to the taskbar.
The thread and the lock I already do but how would I go about monitoring 'inactivity'?
1 Run a thread to monitor activity.
2 When there is any activity, the thread would restart again
3 If timeout is reached, lock to tray and kill thread.
4 When program is unlocked, start thread again.
Lock program to taskbar after specified inactivity?
- Fangbeast
- PureBasic Protozoa
- Posts: 4749
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Lock program to taskbar after specified inactivity?
Amateur Radio, D-STAR/VK3HAF
Re: Lock program to taskbar after specified inactivity?
Minimises the window after the specified period of inactivity (set to five seconds here):Fangbeast wrote:...start a thread in the background to monitor activity and when there is none for a user specified period, lock the program to the taskbar...
Code: Select all
Global inactivityTimer, monitoringThread, appQuit
Procedure activityMonitor(*dummy)
Repeat
If ElapsedMilliseconds() - inactivityTimer > 5000
SetWindowState(0, #PB_Window_Minimize)
PauseThread(monitoringThread)
EndIf
Delay(250)
Until appQuit
EndProcedure
OpenWindow(0, 0, 0, 400, 70, "Monitoring Inactivity",
#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
monitoringThread = CreateThread(@activityMonitor(), 0)
inactivityTimer = ElapsedMilliseconds()
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_CloseWindow
appQuit = 1
Case #PB_Event_RestoreWindow
SetWindowState(0, #PB_Window_Normal)
SetActiveWindow(0)
ResumeThread(monitoringThread)
EndSelect
inactivityTimer = ElapsedMilliseconds()
Until appQuit
Code: Select all
Global inactivityTimer, monitoringThread, appQuit
Procedure activityMonitor(*dummy)
Repeat
If ElapsedMilliseconds() - inactivityTimer > 5000
HideWindow(0, 1)
PauseThread(monitoringThread)
EndIf
Delay(250)
Until appQuit
EndProcedure
sysTrayIcon$ = #PB_Compiler_Home + "examples\sources\Data\CdPlayer.ico"
sysTrayIcon = LoadImage(0, sysTrayIcon$)
OpenWindow(0, 0, 0, 400, 70, "Monitoring Inactivity",
#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
AddSysTrayIcon(0, WindowID(0), sysTrayIcon)
SysTrayIconToolTip(0, "My Application")
monitoringThread = CreateThread(@activityMonitor(), 0)
inactivityTimer = ElapsedMilliseconds()
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_CloseWindow
appQuit = 1
Case #PB_Event_SysTray
HideWindow(0, 0)
SetActiveWindow(0)
ResumeThread(monitoringThread)
EndSelect
inactivityTimer = ElapsedMilliseconds()
Until appQuit
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel
- Fangbeast
- PureBasic Protozoa
- Posts: 4749
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Re: Lock program to taskbar after specified inactivity?
Woohoo!! Thank you! That's great. I'm still adding the font substitutes routine to all my other windows and than I can do this. Maybe even release an updated MyInfo this month! (I hope)TI-994A wrote:Minimises the window after the specified period of inactivity (set to five seconds here):Fangbeast wrote:...start a thread in the background to monitor activity and when there is none for a user specified period, lock the program to the taskbar...Same thing, but this one minimises the window to the system tray instead:Code: Select all
Global inactivityTimer, monitoringThread, appQuit Procedure activityMonitor(*dummy) Repeat If ElapsedMilliseconds() - inactivityTimer > 5000 SetWindowState(0, #PB_Window_Minimize) PauseThread(monitoringThread) EndIf Delay(250) Until appQuit EndProcedure OpenWindow(0, 0, 0, 400, 70, "Monitoring Inactivity", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) monitoringThread = CreateThread(@activityMonitor(), 0) inactivityTimer = ElapsedMilliseconds() Repeat event = WaitWindowEvent() Select event Case #PB_Event_CloseWindow appQuit = 1 Case #PB_Event_RestoreWindow SetWindowState(0, #PB_Window_Normal) SetActiveWindow(0) ResumeThread(monitoringThread) EndSelect inactivityTimer = ElapsedMilliseconds() Until appQuit
Code: Select all
Global inactivityTimer, monitoringThread, appQuit Procedure activityMonitor(*dummy) Repeat If ElapsedMilliseconds() - inactivityTimer > 5000 HideWindow(0, 1) PauseThread(monitoringThread) EndIf Delay(250) Until appQuit EndProcedure sysTrayIcon$ = #PB_Compiler_Home + "examples\sources\Data\CdPlayer.ico" sysTrayIcon = LoadImage(0, sysTrayIcon$) OpenWindow(0, 0, 0, 400, 70, "Monitoring Inactivity", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) AddSysTrayIcon(0, WindowID(0), sysTrayIcon) SysTrayIconToolTip(0, "My Application") monitoringThread = CreateThread(@activityMonitor(), 0) inactivityTimer = ElapsedMilliseconds() Repeat event = WaitWindowEvent() Select event Case #PB_Event_CloseWindow appQuit = 1 Case #PB_Event_SysTray HideWindow(0, 0) SetActiveWindow(0) ResumeThread(monitoringThread) EndSelect inactivityTimer = ElapsedMilliseconds() Until appQuit
Amateur Radio, D-STAR/VK3HAF
Re: Lock program to taskbar after specified inactivity?
Heres some code that uses the WinApi to se if there is some inactivity.
Its global and not tied to a window.
Code:
Its global and not tied to a window.
Code:
Code: Select all
Procedure.i IsInactive(TimeOut.i)
Protected lii.LASTINPUTINFO
If GetLastInputInfo_(@lii)
ProcedureReturn Bool(GetTickCount_() - lii\dwTime) > TimeOut)
EndIf
EndProcedure