Alert user without interrupting active window?

Started by gberk, January 22, 2018, 08:44:04 AM

Previous topic - Next topic

gberk

We have a script that a few users run daily.  It runs continuously and checks for records to appear in a database every few minutes.  Then it alerts the user with the Display command and plays a wav file, so they can take action.

The script works exactly as designed, but now they are asking if there is a way that it can alert them without interrupting the active window (while they are typing).  For example, in the way that Outlook pops up a "new e-mail" alert without changing the active window.

Does WinBatch have the ability to do this directly, or via some creative coding?

Here is the portion of the script that handles the alert currently.

x=1
While x < 2 ;loop forever
  found=0 ;set record count to 0
  WoList="---------------------------------------------------------------------------------------------------------------%@crlf%%@crlf%"
  Gosub READ
  if found > 0 then
  WoList = Strcat(WoList,"%@crlf%---------------------------------------------------------------------------------------------------------------")
    currentvolume = SoundVolume(-1) ;get current volume setting
    if currentvolume < 25 then
      SoundVolume( 75 )         ; Sets the speaker volume.
    endif
    PlayWaveForm("C:\WINDOWS\Media\ringin.wav", 0 ) ; Plays a WAV sound file.  Computer should beep if wav file not found.
    SoundVolume(currentvolume) ;set volume back to previous level
        Display(10,"Workorder in WRQ Status",WoList)         ; Displays a message to the user for a specified period of time
    endif
  delay(delaytime) ;Wait specified delaytime (seconds) before checking file again
end while

Thanks,
Gary

stanl

Would you have the ability to use OfficeCommunicatorAPI and send the alert as an IM?

JTaylor

IntControl 1007 may be a possibility.   I was getting ready to suggest a email as an option as well but Stan beat me to it :)

Jim

td

Quote from: gberk on January 22, 2018, 08:44:04 AM
We have a script that a few users run daily.  It runs continuously and checks for records to appear in a database every few minutes.  Then it alerts the user with the Display command and plays a wav file, so they can take action.

The script works exactly as designed, but now they are asking if there is a way that it can alert them without interrupting the active window (while they are typing).  For example, in the way that Outlook pops up a "new e-mail" alert without changing the active window.

Does WinBatch have the ability to do this directly, or via some creative coding?


In other words, you need something to display but not also take the input focus.   Unfortunately, WinBatch's IntControl 1007 does not provide popup notification functionality when running from the system tray.  There is no direct support for "toast" message at this time either.     I suppose you could use IntControl 1007 to change the icon of the notification tray icon to something that a user might notice and hope the user notices it.

Windows's action center has been made available to native desktop applications as of Windows 10.  I guess Windows 10 is getting long enough in the tooth to consider adding something to WinBatch. 

I believe there are one or two examples of using Win32 API's with DllCall to create popup windows someplace in the Tech Database but I don't recall if they handle the focus issue.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

gberk

Thanks for the suggestions!  I'll look into them and post back if I get it working.

stanl

Quote from: td on January 22, 2018, 02:15:15 PM
I believe there are one or two examples of using Win32 API's with DllCall to create popup windows someplace in the Tech Database but I don't recall if they handle the focus issue.

Perhaps something like.... [untested]

Code (WINBATCH) Select


oPopup = CreateObject("WScript.Shell")
btn = oPopup.Popup("Data Is Ready", 5, "ALERT", )  ; OK Button with 5 second TimeOut
oPopup = 0



EDIT: when I said untested, not sure if that takes focus from WB Window

kdmoyers

Would something like this help?

Code (winbatch) Select

; what window is active now?
win = wingetactive()

;put up my window, and make it float on top
boxesup("500,500,600,600",@normal)
boxtext("hello there ")
windowontop("",1)

; reassert previously active window
winactivate(win)

; show stuff to user
for i = 10 to 1 by -1
  timedelay(1)
  boxtext(i)
next i


; all done
exit
The mind is everything; What you think, you become.

td

Very good idea.  It certainly addresses the focus issue.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

gberk

Quote from: kdmoyers on January 23, 2018, 07:12:54 AM
Would something like this help?

Code (winbatch) Select

; what window is active now?
win = wingetactive()

;put up my window, and make it float on top
boxesup("500,500,600,600",@normal)
boxtext("hello there ")
windowontop("",1)

; reassert previously active window
winactivate(win)

; show stuff to user
for i = 10 to 1 by -1
  timedelay(1)
  boxtext(i)
next i


; all done
exit


Thanks kdmoyers!  It took me a while to get back on this task, but that was exactly what I needed!  Works like a charm!

td

Looks like WindowOnTop needs to be added to the GeSHi php script.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade