How to generate a brief self-closing message

Just starting out? Need help? Post your questions and find answers here.
User avatar
jacdelad
Addict
Addict
Posts: 1993
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: How to generate a brief self-closing message

Post 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:
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: How to generate a brief self-closing message

Post 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:
Last edited by Kuron on Thu Oct 12, 2023 11:43 pm, edited 1 time in total.
Best wishes to the PB community. Thank you for the memories. ♥️
User avatar
jacdelad
Addict
Addict
Posts: 1993
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: How to generate a brief self-closing message

Post by jacdelad »

I still like it. Especially my one.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Oso
Enthusiast
Enthusiast
Posts: 595
Joined: Wed Jul 20, 2022 10:09 am

Re: How to generate a brief self-closing message

Post 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
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: How to generate a brief self-closing message

Post 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)
Egypt my love
Oso
Enthusiast
Enthusiast
Posts: 595
Joined: Wed Jul 20, 2022 10:09 am

Re: How to generate a brief self-closing message

Post 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. :(
bsilver
User
User
Posts: 27
Joined: Tue Jun 27, 2023 3:36 pm

Re: How to generate a brief self-closing message

Post 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/
User avatar
HeX0R
Addict
Addict
Posts: 1189
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: How to generate a brief self-closing message

Post 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.
Oso
Enthusiast
Enthusiast
Posts: 595
Joined: Wed Jul 20, 2022 10:09 am

Re: How to generate a brief self-closing message

Post 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.
Oso
Enthusiast
Enthusiast
Posts: 595
Joined: Wed Jul 20, 2022 10:09 am

Re: How to generate a brief self-closing message

Post 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
User avatar
jacdelad
Addict
Addict
Posts: 1993
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: How to generate a brief self-closing message

Post by jacdelad »

It should be enough to create your invisible window on startup and reuse it whenever you need it. Just minimal improvement.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Post Reply