Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe "startsaver.exe"
#Dim All
%Unicode=1
#Include "win32api.inc"
#Resource Icon logo, "screen.ico"
%WM_Tray = %WM_User + 1
%Tray_Quit = %WM_User + 40
%ID_TImer = 500
Global hDlg, hTrayMenu As Dword
Global xEvents, MaxSeconds As Long
Function PBMain() As Long
Local temp$
Menu New PopUp To htraymenu
Menu Add String, htraymenu, "Quit", %tray_quit, %MF_Enabled
Open "seconds.txt" For Input As #1
Line Input #1, temp$
MaxSeconds = Val(temp$)
Close #1
Dialog New Pixels, %HWND_Desktop, "", 0, 0, 0, 0, 0, %WS_Ex_Topmost Or %WS_Ex_ToolWindow To hdlg
Dialog Set Icon hDlg, "logo"
Dialog Show Modeless hdlg Call DlgProc ' start the tray program
Dialog Show State hdlg, %SW_Hide ' hide it
Do : Dialog DoEvents To xevents : Loop Until xevents = 0 'message pump until quit was clicked
End Function
CallBack Function DlgProc () As Long
Static tn As notifyicondata, shown, iResult As Long
Local pt As PointAPI
Select Case CbMsg
Case %WM_InitDialog
tn.cbsize = SizeOf(tn)
tn.hwnd = hDlg
tn.uid = GetModuleHandle(ByVal %NULL)
tn.uflags = %nif_icon Or %nif_message Or %nif_tip
tn.ucallbackmessage = %WM_Tray
' tn.hicon = loadicon(%null,ByVal Mak(Long, %idi_application,0))
tn.hicon = loadicon(tn.uid, "logo")
tn.sztip = "Start ScreenSaver"
Shell_NotifyIcon %nim_add, tn
SetTimer hDlg, %ID_Timer, 500, ByVal %Null
Case %WM_Timer
iResult = GetIdle
If iResult > MaxSeconds Then StartScreenSaver
Case %WM_Destroy
Shell_NotifyIcon %nim_delete, tn
KillTimer hDlg, %ID_Timer
Case %WM_Tray
Select Case Cb.LParam
Case %WM_RButtonDown
GetCursorPos pt
TrackPopupMenu hTrayMenu, %TPM_BottomAlign Or %TPM_RightAlign, pt.x, pt.y, 0, hDlg, ByVal %null
PostMessage hDlg, %WM_Null, 0, 0
Case %WM_LButtonDblClk
StartScreenSaver
End Select
Case %WM_Command
Select Case Cb.Ctl
Case %Tray_Quit 'context menu item from tray icon
xEvents = 0
Dialog End hDlg
End Select
End Select
End Function
Sub StartScreenSaver
SendMessage(hDlg, %WM_SYSCOMMAND, %SC_ScreenSave, 0&)
End Sub
Function GetIdle As Single
Local rtn As Long, temp As Single, tick As Dword
Local sample As LASTINPUTINFO
sample.cbSize=SizeOf(sample)
rtn= GetLastInputInfo(sample)
If rtn = 0 Then Exit Function
temp = sample.dwTime
tick=GetTickCount
temp = (tick-temp)/1000!
Function = temp
End Function
http://www.garybeene.com/sw/gbsnippets.htm