Page 2 of 2

Re: How to generate a brief self-closing message

Posted: Thu Oct 12, 2023 11:13 pm
by jacdelad
Oso wrote: Thu Oct 12, 2023 10:29 pm
jacdelad wrote: Thu Oct 12, 2023 10:23 pm The magic word is "toast message". But that's a piece of work. I started after infratec and breeze4me gave us a headstart:
http://forums.purebasic.com/english/vie ... 1&start=15
Yup, I remember absolutely your post last year about Toast, and looking it up at the time to see what it was. This is the problem with me working on legacy apps. all the time, it means I don't get to remember the latest ideas. :D

To be honest though, it looks like a lot of work, just for a message.
I also have a really cool working ribbon menu gadget, but I don't dare to release it... :wink:

Re: How to generate a brief self-closing message

Posted: Thu Oct 12, 2023 11:35 pm
by Kuron
jacdelad wrote: Thu Oct 12, 2023 11:13 pm I also have a really cool working ribbon menu gadget, but I don't dare to release it... :wink:
I think even MS is slowly giving up on the ribbon gadget, based on some of the recent screenshots I have seen. :mrgreen:

Re: How to generate a brief self-closing message

Posted: Thu Oct 12, 2023 11:41 pm
by jacdelad
I still like it. Especially my one.

Re: How to generate a brief self-closing message

Posted: Fri Oct 13, 2023 3:33 pm
by Oso
I've played around with all these ideas and the problem is that, since my process runs as a Windows background task, started on boot-up, it doesn't display anything on the user's desktop.

I've also tried using the system tray, but again it only works if the application is run in foreground. Is there any other way, short of having a helper routine running in foreground?

Code: Select all

If OpenWindow(0, 0, 0, 300, 100, "", #PB_Window_Invisible)
  AddSysTrayIcon(0, WindowID(0), LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/CdPlayer.ico"))
  Delay(60000)
  RemoveSysTrayIcon(0)
EndIf

Re: How to generate a brief self-closing message

Posted: Fri Oct 13, 2023 4:46 pm
by RASHAD
If Toast notification is somehow complicated you can use System Tray Balloon instead

Code: Select all

   Structure _NOTIFYICONDATA Align #PB_Structure_AlignC
      cbSize.l
      hwnd.i
      uId.l
      uFlags.l
      uCallbackMessage.l
      hIcon.i
      StructureUnion
         szTip.s{64}
         szTipEx.s{128}
      EndStructureUnion
      dwState.l
      dwStateMask.l
      szInfo.s{256}
      StructureUnion
         uTimeout.l
         uVersion.l
      EndStructureUnion
      szInfoTitle.s{64}
      dwInfoFlags.l
      guidItem.GUID
      hBalloonIcon.i
   EndStructure

Global icon = LoadIcon_(#Null,#IDI_EXCLAMATION)
Global ToolInfo.TOOLINFO
Global SysTrayInfo._NOTIFYICONDATA

Procedure SystrayBalloon(Title.s,Text.s,Flag,Msg=#NIM_MODIFY)
  
  If OSVersion() >= #PB_OS_Windows_Vista
    SysTrayInfo\cbSize=SizeOf(_NOTIFYICONDATA) 
  EndIf
  
  If SysTrayInfo\cbSize
    If Message=#NIM_ADD      
      SysTrayInfo\uVersion = #NOTIFYICON_VERSION
      SysTrayInfo\uCallbackMessage = #WM_NOTIFYICON
      SysTrayInfo\uId = 0
      SysTrayInfo\uFlags = #NIF_ICON|#NIF_INFO|#NIF_MESSAGE|#NIF_TIP;|#TTS_NOPREFIX
      SysTrayInfo\uTimeout = 10000
      
      SysTrayInfo\hwnd = WindowID(0)
      SysTrayInfo\hIcon = icon
      SysTrayInfo\hBalloonIcon = icon      
      SysTrayInfo\dwInfoFlags = #NIIF_INFO 
      SysTrayInfo\dwState = #NIS_SHAREDICON
    EndIf
    
    If Flag = 0
      SysTrayInfo\dwInfoFlags=#NIIF_INFO 
    ElseIf Flag = 1
      SysTrayInfo\dwInfoFlags=#NIIF_WARNING 
    EndIf
    
    SysTrayInfo\szInfoTitle=Left(Title,255)
    SysTrayInfo\szInfo=Left(Text,255)
    
    ProcedureReturn Shell_NotifyIcon_(Msg,@SysTrayInfo)
  EndIf
  
  ProcedureReturn #False
  
EndProcedure

OpenWindow(0,0,0,400,300,"System Tray Balloon",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ButtonGadget(0,10,270,80,24,"RUN")

Repeat
  Select WaitWindowEvent()      
    Case #PB_Event_CloseWindow    
      Quit = 1
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          SystrayBalloon("Info"," "+#CRLF$+"This application will end after 4 sec"+#CRLF$+" ",0,#NIM_ADD)
          Delay(4000)
          SysTrayInfo\szInfo = ""
          Shell_NotifyIcon_(#NIM_MODIFY,SysTrayInfo)
          Quit = 1
      EndSelect
      
  EndSelect
  
Until Quit = 1

SystrayBalloon("","",0,#NIM_DELETE)

Re: How to generate a brief self-closing message

Posted: Fri Oct 13, 2023 7:36 pm
by Oso
RASHAD wrote: Fri Oct 13, 2023 4:46 pm If Toast notification is somehow complicated you can use System Tray Balloon instead
Thanks, it looks great, but I thought that style was "toast"...
jacdelad wrote: ↑Thu Oct 12, 2023 10:23 pm
The magic word is "toast message". But that's a piece of work. I started after infratec and breeze4me gave us a headstart:
http://forums.purebasic.com/english/vie ... 1&start=15
... which was sent in response to my sample of this :

Image

The same style as yours?

But alas, although it looks good, it doesn't appear to display from a background process, with or without a window, or with 'invisible' window. :(

Re: How to generate a brief self-closing message

Posted: Fri Oct 13, 2023 7:44 pm
by bsilver
Doesn't the desktop require certain permissions in order to have access to the logged-in user's desktop session? Maybe you could get a trace of what's happening with some of the sysinternals tools on https://learn.microsoft.com/en-us/sysin ... downloads/

Re: How to generate a brief self-closing message

Posted: Fri Oct 13, 2023 7:51 pm
by HeX0R
I guess you mean "runs as service" instead of "runs as background process", right?
Then yes, since... dunno Windows 10 I think, services are no longer allowed to show windows.

Re: How to generate a brief self-closing message

Posted: Fri Oct 13, 2023 11:47 pm
by Oso
HeX0R wrote: Fri Oct 13, 2023 7:51 pm I guess you mean "runs as service" instead of "runs as background process", right?
Then yes, since... dunno Windows 10 I think, services are no longer allowed to show windows.
Hi HeX0R no, I mean background process, that I've set to run from Task Scheduler - Task Scheduler Library. The process runs at system start-up, so it isn't as complex as a service.

I've tried Windows Server 2016 and Windows 10. Neither shows the system tray icon, or Rashad's toast message, at the time it's meant to, unless its been started by the user, in which case they all work fine anyway. I think it's as you say — part of Windows now. A separate foreground application may be needed to interact with the desktop but I'm trying to keep it simple really though, because the application will be set-up by end-user folks in my absence.

Re: How to generate a brief self-closing message

Posted: Mon Oct 16, 2023 10:48 pm
by Oso
Thanks to those who offered help with this. The simple answer to this limitation of not being able to present some form of status indication on the desktop, from a task-scheduler process started at bootup, was to instead execute my process from the task scheduler when the user logs in.

The application has no window, but creates one with #PB_Window_Invisible whenever it needs to generate a message, or a system-tray icon, like so :

Code: Select all

  If OpenWindow(0, 0, 0, 300, 100, "", #PB_Window_Invisible)
    AddSysTrayIcon(0, WindowID(0), LoadImage(0, "disconnect-icon.bmp"))
  EndIf

Re: How to generate a brief self-closing message

Posted: Tue Oct 17, 2023 9:40 am
by jacdelad
It should be enough to create your invisible window on startup and reuse it whenever you need it. Just minimal improvement.