Author Topic: Alert user without interrupting active window?  (Read 733 times)

gberk

  • Newbie
  • *
  • Posts: 3
Alert user without interrupting active window?
« 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?

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

  • Pundit
  • *****
  • Posts: 777
Re: Alert user without interrupting active window?
« Reply #1 on: January 22, 2018, 01:04:07 pm »
Would you have the ability to use OfficeCommunicatorAPI and send the alert as an IM?

JTaylor

  • Pundit
  • *****
  • Posts: 907
    • Data & Stuff Inc.
Re: Alert user without interrupting active window?
« Reply #2 on: January 22, 2018, 01:58:20 pm »
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

  • Tech Support
  • *****
  • Posts: 2538
    • WinBatch
Re: Alert user without interrupting active window?
« Reply #3 on: January 22, 2018, 02:15:15 pm »
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.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


gberk

  • Newbie
  • *
  • Posts: 3
Re: Alert user without interrupting active window?
« Reply #4 on: January 22, 2018, 04:20:54 pm »
Thanks for the suggestions!  I'll look into them and post back if I get it working.

stanl

  • Pundit
  • *****
  • Posts: 777
Re: Alert user without interrupting active window?
« Reply #5 on: January 23, 2018, 04:03:23 am »
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

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

  • Full Member
  • ***
  • Posts: 222
Re: Alert user without interrupting active window?
« Reply #6 on: January 23, 2018, 07:12:54 am »
Would something like this help?

Code: Winbatch
; 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

  • Tech Support
  • *****
  • Posts: 2538
    • WinBatch
Re: Alert user without interrupting active window?
« Reply #7 on: January 23, 2018, 09:49:30 am »
Very good idea.  It certainly addresses the focus issue.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


gberk

  • Newbie
  • *
  • Posts: 3
Re: Alert user without interrupting active window?
« Reply #8 on: July 18, 2018, 10:20:31 am »
Would something like this help?

Code: Winbatch
; 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

  • Tech Support
  • *****
  • Posts: 2538
    • WinBatch
OT: Alert user without interrupting active window?
« Reply #9 on: July 18, 2018, 11:25:01 am »
Looks like WindowOnTop needs to be added to the GeSHi php script.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates