' ' Scheduler ' (C) 2003-09-09 MaWeSo ' ' Contact: mailto:martin.wehner@firemail.de ' Homepage: http://mitglied.lycos.de/maweso/ ' ' Compile this source code with the RapidQ Compiler ' (available at http://www.basicguru.com/rapidq). ' For better runtime stability it is highly recommended ' to use the patched Rapid-Q Library Files available ' at http://www.angelfire.com/space/netcensus/ when ' compiling this source. ' ' The program runs as tray application. Every full hour ' between 9:00 and 18:00 a message window with a time ' stamp pops up. If you replace ShowMessage(TIME$) by ' RUN [command] you can execute an external command ' instead. ' Right click on the tray icon to open a popup menu. ' The menu item "Exit" terminates the tray application. ' ' This source code is distributed under GNU General ' Public License. ' CONST NIM_ADD = &H0 CONST NIM_MESSAGE = &H1 CONST NIM_DELETE = &H2 CONST NIM_ICON = &H2 CONST NIM_TIP = &H4 CONST SW_HIDE = &H0 CONST WM_SIZE = &H5 CONST WM_LBUTTONDOWN = &H201 CONST WM_RBUTTONDOWN = &H204 CONST WM_RBUTTONUP = &H205 CONST WM_USER = &H400 CONST WM_USERTRAYMSG = WM_USER + &H200 CONST GWL_HWNDPARENT = (-8) DECLARE FUNCTION ShowWindowAPI LIB "user32" ALIAS "ShowWindow" _ (ByVal hwnd AS LONG, ByVal nCmdShow AS LONG) AS LONG DECLARE FUNCTION Shell_NotifyIconAPI LIB "shell32" ALIAS "Shell_NotifyIconA" _ (ByVal dwMessage AS LONG, ByVal lpData AS QNOTIFYICONDATA) AS LONG DECLARE FUNCTION SetForegroundWindowAPI LIB "user32" ALIAS "SetForegroundWindow" _ (hWnd AS LONG) AS LONG DECLARE FUNCTION SetWindowLongAPI LIB "user32" ALIAS "SetWindowLongA" _ (ByVal hwnd AS LONG, ByVal nIndex AS LONG, ByVal dwNewLong AS LONG) AS LONG DIM TimerInterrupt AS QTIMER DIM TrayMenu AS QPOPUPMENU DIM TrayExitItem AS QMENUITEM DIM TrayForm AS QFORM DIM hour AS INTEGER hour = VAL(LEFT$(TIME$, 2)) DIM nid AS QNOTIFYICONDATA nid.hWnd = TrayForm.Handle nid.uID = Application.hInstance nid.uFlags = NIM_ICON OR NIM_MESSAGE OR NIM_TIP nid.hIcon = Application.Icon nid.uCallBackMessage = WM_USERTRAYMSG nid.szTip = "Scheduler" + CHR$(0) Shell_NotifyIconAPI(NIM_ADD, nid) SUB TrayClose Shell_NotifyIconAPI(NIM_DELETE, nid) TrayForm.Close Application.Terminate ' Necessary to kill the process when message windows are still open END SUB SUB TrayInterrupt DIM h AS INTEGER h = VAL(LEFT$(TIME$, 2)) IF hour <> h THEN hour = h SELECT CASE hour CASE 9 TO 18 SetForegroundWindowAPI(TrayForm.Handle) ShowMessage(TIME$) ' Replace this by RUN [command] END SELECT END IF END SUB SUB WndProc (hWnd AS LONG, uMsg AS LONG, wParam AS LONG, lParam AS LONG) SELECT CASE uMsg CASE WM_SIZE IF TrayForm.Visible THEN ShowWindowAPI(hWnd, SW_HIDE) CASE WM_USERTRAYMSG SELECT CASE lParam AND &HFFFF CASE WM_LBUTTONDOWN, WM_RBUTTONDOWN SetForegroundWindowAPI(TrayForm.Handle) CASE WM_RBUTTONUP TrayMenu.Popup(Screen.MouseX, Screen.MouseY) SetForegroundWindowAPI(TrayForm.Handle) END SELECT CASE WM_QUERYENDSESSION TrayClose ' Windows session is terminating END SELECT END SUB SetWindowLongAPI(TrayForm.Handle, GWL_HWNDPARENT, 0) SetWindowLongAPI(Application.Handle, GWL_HWNDPARENT, TrayForm.Handle) TimerInterrupt.Enabled = 1 TimerInterrupt.Interval = 60000 ' Check every minute (60000 ms) TimerInterrupt.OnTimer = TrayInterrupt TrayExitItem.Caption = "E&xit" TrayExitItem.OnClick = TrayClose TrayMenu.AddItems TrayExitItem TrayForm.Width = 0 TrayForm.Height = 0 TrayForm.WndProc = WndProc TrayForm.ShowModal