Page 1 of 2

How to generate a brief self-closing message

Posted: Thu Oct 12, 2023 7:00 pm
by Oso
Hi all, is there a way to show users a brief status message, without requiring the user to close it — a transient message in other words that isn't obtrusive? Something like the below. It's for Windows 64-bit only.

Image

A caveat :

This is for a background process. Currently it's running under test as a console desktop application, which when completed, will run as an automatic startup process.
I guess that means it can't create a window.

If this isn't straightforward, I would be happy with a system tray icon perhaps, but haven't yet tried doing that.

Re: How to generate a brief self-closing message

Posted: Thu Oct 12, 2023 7:15 pm
by jacdelad
Reading freaks answer to this viewtopic.php?p=97529 tells me that you can create windows etc. just like always. So you can create your statuswindow, wait, and close it as you like.

Re: How to generate a brief self-closing message

Posted: Thu Oct 12, 2023 7:43 pm
by Oso
jacdelad wrote: Thu Oct 12, 2023 7:15 pm Reading freaks answer to this viewtopic.php?p=97529 tells me that you can create windows etc. just like always. So you can create your statuswindow, wait, and close it as you like.
Thanks jacdelad good that you found that old post :)

I'll give it a try and see how I get on with a window. It will be interesting if it appears when the console is running as background.

Re: How to generate a brief self-closing message

Posted: Thu Oct 12, 2023 8:51 pm
by Oso
It works fine. The application can be set up in the Windows Task Scheduler, with the trigger "At system startup". Interestingly, the console window also appears (obviously from the OpenConsole()), even though it's running in background. I thought I tried this recently as a test, to check that I could run my console application in the background and I don't remember the console appearing then. :? Anyway, that isn't a problem. I plan to remove all console display messages and write them to a log file instead.

The #PB_Window_Tool was useful, otherwise it creates an unwanted taskbar item.

Code: Select all

OpenWindow(0, 0 ,0 , 500, 90, "Status", #PB_Window_ScreenCentered | #PB_Window_Tool )
TextGadget(1, 20, 30, 470, 90, "Please wait, network connection is being re-established.")
Delay(2000)
CloseWindow(0)
EDIT — Although it works, the unfortunate effect is that it doesn't appear above any other windows.

Re: How to generate a brief self-closing message

Posted: Thu Oct 12, 2023 9:20 pm
by jacdelad
If your program stays for Windows only, have a look at AnimateWindow_(). Might be a cool, wanted effect (sliding or blending).
https://learn.microsoft.com/en-us/windo ... matewindow

Re: How to generate a brief self-closing message

Posted: Thu Oct 12, 2023 9:36 pm
by firace
This could help:
(Adapted from older code by Rashad)

Code: Select all

#TTF_TRACK     =  $20
#TTF_ABSOLUTE  =  $80


Structure GadgetGlobals
  CurrentWindow.i
  FirstOptionGadget.i
  DefaultFont.i
  *PanelStack
  PanelStackIndex.l
  PanelStackSize.l
  ToolTipWindow.i
EndStructure

Import ""
  PB_Object_GetThreadMemory(*Mem)
  PB_Gadget_Globals
EndImport

Procedure ToolTipID() 
  Protected *gg.GadgetGlobals 
  *gg = PB_Object_GetThreadMemory(PB_Gadget_Globals) 
  ProcedureReturn *gg\ToolTipWindow 
EndProcedure



Procedure TTip_Command(win,gad,x,y,dTime)
  
  shared ttip 
  
  ti.TOOLINFO
  ti\cbSize = SizeOf(ti)
  ti\hInst = GetModuleHandle_(0)
  ti\uFlags = #TTF_TRACK  | #TTF_ABSOLUTE  
  SendMessage_(TTip, #TTM_DELTOOL, 0, ti)
  
  text$ = "Connected as:" + #CRLF$ +   "Since 18:37 (58s)" + #CRLF$ +  "IP address: 10.66.5.10"
  ti\lpszText = @Text$
  
  SendMessage_(TTip, #TTM_ADDTOOL, 0, ti)  
  SendMessage_(TTip, #TTM_SETMAXTIPWIDTH, 0, 150)
  
  SendMessage_(TTip,#TTM_TRACKACTIVATE,0,ti)
  SendMessage_(TTip,#TTM_TRACKACTIVATE,1,ti)                     
  SendMessage_(TTip,#TTM_TRACKPOSITION,0,x+10 + (y+10)<<16)                   
  Delay(dTime)
  SendMessage_(TTip, #TTM_DELTOOL, 0, ti)    
EndProcedure


Procedure InitODToolTip()
  shared ttip
  StringGadget(1,10,10,200,20,"dummy gadget") : HideGadget(1, 1)
  
  GadgetToolTip(1, "dummy tooltip")
  ttip = ToolTipID()
EndProcedure   



OpenWindow(0,220,110,320,240,"" ,#PB_Window_SystemMenu )

InitODTooltip()

ButtonGadget(4,100,200,130,30,"Trigger tooltip")

Repeat
  Select WaitWindowEvent()     
    Case #PB_Event_CloseWindow
      Quit = 1
      
    Case #PB_Event_Gadget
      Select EventGadget()
          
        Case 4
          TTip_Command(0,2,1150,600,2000)
      EndSelect         
  EndSelect
  
Until Quit = 1

Re: How to generate a brief self-closing message

Posted: Thu Oct 12, 2023 9:41 pm
by idle
this was an old joke. IT played YMCA village people and said You've got Male! then jumped up and down to the music.
I've edited so it just slides out and back again

Code: Select all


#WindowLength=180
#WindowHeight=90
Global rect.RECT

Procedure ShowWindow(window)
  HideWindow(Window, 0)
  sy.l 
  sf.f = (1-#WindowLength) / (1-255)
  sfy.f = (1-#WindowHeight) /(1-255)
  ;PlaySound(0)
  For i=0 To 255 Step 10
    sX = (i * sf) - #WindowLength
    MoveWindow_(WindowID(window),rect\right-#WindowLength-Sx,(rect\bottom-#WindowHeight)-Sy,#WindowLength,#WindowHeight,1)
    SetLayeredWindowAttributes_(WindowID(window), 0, i, 2)
    Delay(30)
  Next
  Delay(2000)
  
  For i=255 To 0 Step -2
    sX = (i * sf) - #WindowLength
    MoveWindow_(WindowID(window),rect\right-#WindowLength-Sx,(rect\bottom-#WindowHeight)-Sy,#WindowLength,#WindowHeight,1)
    SetLayeredWindowAttributes_(WindowID(window), 0, i, 2)
    Delay(30)
  Next
 
EndProcedure

Procedure.l CreatePopupMessage(con.s,time.s,ip.s,in.f,out.f)
  Define Window.l, DummyWindow.l, i.l, TextGadget
  SystemParametersInfo_(#SPI_GETWORKAREA,0,rect.RECT,0)
  DummyWindow.l=OpenWindow(#PB_Any, 0, 0, 0, 0, "", #PB_Window_Invisible)
  Window=OpenWindow(#PB_Any, rect\right-#WindowLength, rect\bottom-#WindowHeight, #WindowLength, #WindowHeight, "Audio Device", #WS_POPUPWINDOW|#WS_DISABLED|#PB_Window_Invisible, WindowID(DummyWindow))
  SetWindowLong_(WindowID(window), #GWL_EXSTYLE,GetWindowLong_(WindowID(window),#GWL_EXSTYLE)|#WS_EX_LAYERED )
  If Window
    If CreateGadgetList(WindowID(Window))
      TextGadget=TextGadget(#PB_Any, 10, 10, 160, 90, "connected as " + con + #CRLF$ + "since " + time  + #CRLF$ + "IP address " + ip + #CRLF$ + StrF(in,2)+ " KB " + "Out " + StrF(out,2))
      SetGadgetColor(TextGadget,#PB_Gadget_BackColor,RGB(255,255,255))
    EndIf
    StickyWindow(Window, 1)
    SetWindowColor(Window, RGB(255, 255, 255))
    tid = CreateThread(@ShowWindow(),window)
  EndIf
  Repeat:
    WaitWindowEvent(1)
  Until Not IsThread(tid)
  CloseWindow(Window)
  CloseWindow(DummyWindow)
EndProcedure

; InitSound()
; UseOGGSoundDecoder()
; len = CatchSound(0, ?Music,154116)

CreatePopupMessage("admin","10:00 (58s)","10.66.5.10",12.59,20.69)


; DataSection 
; 
; Music: IncludeBinary "c:\msg.ogg"
; 
; EndDataSection



Re: How to generate a brief self-closing message

Posted: Thu Oct 12, 2023 10:09 pm
by Oso
jacdelad wrote: Thu Oct 12, 2023 9:20 pm If your program stays for Windows only, have a look at AnimateWindow_(). Might be a cool, wanted effect (sliding or blending).
https://learn.microsoft.com/en-us/windo ... matewindow
Interesting, I found that it was necessary to add SetForegroundWindow_(WindowID(0)) to get the message window to appear. I'm not sure why, but in a simple test routine with just OpenConsole(), the window appears reliably, but something in the main app. is affecting it.

It would be good if something like the Windows 10 message displayer is available. That's what I was looking for earlier, but Stormshield VPN wasn't always displaying the message I wanted. It's the below...

Image

Re: How to generate a brief self-closing message

Posted: Thu Oct 12, 2023 10:15 pm
by Oso
idle wrote: Thu Oct 12, 2023 9:41 pm this was an old joke. IT played YMCA village people and said You've got Male! then jumped up and down to the music.
I've edited so it just slides out and back again
Very good, I like the effect.

Code: Select all

; DataSection 
; 
; Music: IncludeBinary "c:\msg.ogg"
; 
; EndDataSection
You really should have left it in, I could do with a laugh to keep me going at this hour — a long day :x

Re: How to generate a brief self-closing message

Posted: Thu Oct 12, 2023 10:23 pm
by jacdelad
Oso wrote: Thu Oct 12, 2023 10:09 pm It would be good if something like the Windows 10 message displayer is available. That's what I was looking for earlier, but Stormshield VPN wasn't always displaying the message I wanted. It's the below...
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
I wanted to put it into a module, but that's a lot of work and I'm still busy with my Gerber module.
Here's some more helpful links:
https://learn.microsoft.com/en-us/uwp/s ... dfrom=MSDN
https://learn.microsoft.com/en-us/previ ... =win.10%29
https://learn.microsoft.com/en-us/windo ... ast-schema
https://docs.telerik.com/devtools/winfo ... -templates
Note that all pictures which shall be displayed in the messages have to be placed as a file on the disk (at least as far as I know).

Re: How to generate a brief self-closing message

Posted: Thu Oct 12, 2023 10:23 pm
by Oso
firace wrote: Thu Oct 12, 2023 9:36 pm This could help:
(Adapted from older code by Rashad)

Code: Select all

  text$ = "Connected as:" + #CRLF$ +   "Since 18:37 (58s)" + #CRLF$ +  "IP address: 10.66.5.10"
Amazing, even got my IP address correct :D I've tried it in my main code and it's fine, but it needs a window to work, as far as I can see. So running it from a console app, it's necessary to just open a dummy window set to invisible. So yes, that works okay.

Re: How to generate a brief self-closing message

Posted: Thu Oct 12, 2023 10:26 pm
by RASHAD
For Windows
Adapt it for your needs

Code: Select all

Prototype SplashMessageSetup(hWnd,lpText$,lpCaption$,uType,wLanguageID.w,dwMilliseconds)

Procedure SplashMessage(title$,text$,ms=1000,icon=0)
  lib=OpenLibrary(#PB_Any,"user32.dll")
  If lib
    SplashMessageSetup.SplashMessageSetup=GetFunction(lib,"MessageBoxTimeoutW")
    SplashMessageSetup(GetForegroundWindow_(),text$,title$,#MB_SETFOREGROUND|#MB_TOPMOST|#MB_TASKMODAL|icon,0,ms)
    CloseLibrary(lib)
  EndIf
EndProcedure

Beep_(800,beep)
inf.s = "User Name : " + UserName() + #LF$
inf.s + "Computer Name : " + ComputerName() + #LF$
inf.s + "CPU Name : " + CPUName()+ #LF$
inf.s + "No. of CPUs : " + CountCPUs()+ #LF$
inf.s + "Total Physical memory : " + Str(MemoryStatus(#PB_System_TotalPhysical)/1000/1024/1024)+"  GB"+ #LF$
inf.s + "Free Physical memory  : " + Str(MemoryStatus(#PB_System_FreePhysical)/1000/1024/1024)+"  GB"+ #LF$


flags = #PB_Window_SystemMenu| #PB_Window_MaximizeGadget| #PB_Window_MinimizeGadget| #PB_Window_ScreenCentered | #PB_Window_SizeGadget
OpenWindow(0,0,0,800,600,"Test",Flags)
ButtonGadget(1,10,570,80,24,"Close")

Repeat           
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1
          SplashMessage("Info",inf,2500,#MB_ICONINFORMATION)
      EndSelect          
  EndSelect
Until Quit = 1

Re: How to generate a brief self-closing message

Posted: Thu Oct 12, 2023 10:29 pm
by Oso
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.

Re: How to generate a brief self-closing message

Posted: Thu Oct 12, 2023 10:35 pm
by Oso
RASHAD wrote: Thu Oct 12, 2023 10:26 pm For Windows Adapt it for your needs
Amazing, thanks. That can actually be run from a console screen without a window :D :

Code: Select all

OpenConsole()

Prototype SplashMessageSetup(hWnd,lpText$,lpCaption$,uType,wLanguageID.w,dwMilliseconds)

Procedure SplashMessage(title$,text$,ms=1000,icon=0)
  lib=OpenLibrary(#PB_Any,"user32.dll")
  If lib
    SplashMessageSetup.SplashMessageSetup=GetFunction(lib,"MessageBoxTimeoutW")
    SplashMessageSetup(GetForegroundWindow_(),text$,title$,#MB_SETFOREGROUND|#MB_TOPMOST|#MB_TASKMODAL|icon,0,ms)
    CloseLibrary(lib)
  EndIf
EndProcedure

inf.s = "User Name : " + UserName() + #LF$
inf.s + "Computer Name : " + ComputerName() + #LF$
inf.s + "CPU Name : " + CPUName()+ #LF$
inf.s + "No. of CPUs : " + CountCPUs()+ #LF$
inf.s + "Total Physical memory : " + Str(MemoryStatus(#PB_System_TotalPhysical)/1000/1024/1024)+"  GB"+ #LF$
inf.s + "Free Physical memory  : " + Str(MemoryStatus(#PB_System_FreePhysical)/1000/1024/1024)+"  GB"+ #LF$

SplashMessage("Info",inf,2500,#MB_ICONINFORMATION)

Re: How to generate a brief self-closing message

Posted: Thu Oct 12, 2023 11:00 pm
by idle
Oso wrote: Thu Oct 12, 2023 10:15 pm
idle wrote: Thu Oct 12, 2023 9:41 pm this was an old joke. IT played YMCA village people and said You've got Male! then jumped up and down to the music.
I've edited so it just slides out and back again
Very good, I like the effect.

Code: Select all

; DataSection 
; 
; Music: IncludeBinary "c:\msg.ogg"
; 
; EndDataSection
You really should have left it in, I could do with a laugh to keep me going at this hour — a long day :x
It was from 2008 the track is long gone but you can make it go bing, I've edited out the jumping. IT's works quite well