Toast Notification's Utility

  • Ramón San Félix Ramón
  • Ramón San Félix Ramón's Avatar Code Author
  • Offline
More
1 year 1 month ago #487 by Ramón San Félix Ramón
Ramón San Félix Ramón created the code: Toast Notification's Utility
I want to share with the appeon community an example that I published on my blog in March 2023.

These are toast notifications, which I think add a touch of modernity to our PowerBuilder applications.

The first thing I have to thank is Chris Pollach who has published an example with his Framework on which I have based it.
Here is the link to the Windows Notification Utility project:

sourceforge.net/projects/stdfndclass/files/Applications/PowerBuilder/Notification

Well, the first thing I did was separate the nc_systemtray_master class from its framework.

To do this I have created a non-visual object called n_cst_systemtray in which I have copied all the logic from nc_systemtray_master. It was quite simple, I just had to create the ib_rc variable that is in the ancestor of nc_systemtray_master (nc_master) and I eliminated the oe_documentation event. With this I have now been able to use only the class without anything else from the framework.

For my example I have added a variable called ib_HideWindow, since I do not want the window that calls the notification to become invisible, so I have modified the of_add_to_systemtray() functions by adding the IF condition ib_HideWindow THEN ao_window.Hide().

I had to create a function called of_get_systemtray_active() to know when we have sent the window to the SystemTray, it simply returns the private variable ib_systemtray_active, I could have put this public variable but I have chosen to respect the original class as much as possible.

As a last modification to the class I have added that the state is saved in the private variable ib_systemtray_active within the of_delete_from_systemtray() function. This way I will know when the Systemtray notification has been removed.

Once I had the class prepared, I had several headaches to make the notifications independent of the application and eliminate themselves after a few seconds.

After several tests, I remembered an example of programming in MultiThread or MultiThead and I tried to apply those concepts in this example.

To do this I had to create the n_cst_systemtray_shared class and the n_cst_systemtray_callback class to help me achieve it.

In summary, you have to create an object that is executed in another thread, in this case the n_cst_systemtray_shared object. This is responsible for waiting a few seconds before calling the other n_cst_systemtray_callback object that will eliminate the notification.

The summary explanation of why two objects must be used is because the shared object used for Multithreading cannot invoke any object that is visual, that must be done by the second object...

Since I don't want to make this article much longer, I leave you a link to an interesting article that talks about the topic:

Community.appeon.com/.../339-free-my-gui-multi-threading-in-powerbuilder

Anyway, I leave the link to the project on GitHub and on my blog, where I have extended the explanation a little more in Spanish.

github.com/rasanfe/toast

rsrsystem.blogspot.com/2023/03/toast-notifications-utility.html

Additionally, I upload the zipped project as an attachment here.

This message has an attachment file.
Please log in or register to see it.

Please Log in or Create an account to join the conversation.

  • Ramón San Félix Ramón
  • Ramón San Félix Ramón's Avatar Code Author
  • Offline
More
3 hours 52 minutes ago #578 by Ramón San Félix Ramón
Ramón San Félix Ramón replied the code: Toast Notification's Utility
When you compile, do you compile to 32 or 64 bits? I don't remember if I set the example to 64 bits, I imagine so, but it doesn't matter, make sure that when you run it in the IDE you are in 32 or 64 bits according to what works for you in compilation.

Please Log in or Create an account to join the conversation.

  • Alessandro Malaguti
  • Alessandro Malaguti's Avatar
  • Away
More
16 hours 59 minutes ago #577 by Alessandro Malaguti
Alessandro Malaguti replied the code: Toast Notification's Utility
Hi to all,
works very fine, thank you very much!

Please Log in or Create an account to join the conversation.

More
5 days 4 hours ago #576 by Vassilis Filippopoulos
Vassilis Filippopoulos replied the code: Toast Notification's Utility
Hi to all.
Excellent job.
When I create an executable it works fine. But the toast notification is not shown from the development environment (Powerbuilder IDE).Nothing happens when I run it from the environment.
Any ideas ?

Please Log in or Create an account to join the conversation.

More
5 days 4 hours ago #575 by Vassilis Filippopoulos
Vassilis Filippopoulos replied the code: Toast Notification's Utility
Hi to all.
Excellent job.
When I create an executable it works fine. But the toast notification is not shown from the development environment (Powerbuilder IDE).Nothing happens.
Any ideas ?

Please Log in or Create an account to join the conversation.

More
10 months 2 weeks ago #511 by Marcelo Gil
Marcelo Gil replied the code: Toast Notification's Utility
Genial! muchas gracias

Please Log in or Create an account to join the conversation.

  • Ramón San Félix Ramón
  • Ramón San Félix Ramón's Avatar Code Author
  • Offline
More
10 months 2 weeks ago #510 by Ramón San Félix Ramón
Ramón San Félix Ramón replied the code: Toast Notification's Utility
Hola Marcelo,

Esta utilidad no usa ninguna librería .Net, usa declaración de funciones externas para manejar funciones de Windows.

Saludos.

Please Log in or Create an account to join the conversation.

More
10 months 3 weeks ago #509 by Marcelo Gil
Marcelo Gil replied the code: Toast Notification's Utility
Hola Ramon! como estas ?
Esta funcionalidad aplica para PB 2022 R2 ?
Entiendo que a partir de esta version de PB no se pueden utilizar DLL generadas en .net framework. (pasan a .net core)

Muchas gcs
Sldos

Please Log in or Create an account to join the conversation.

  • Ramón San Félix Ramón
  • Ramón San Félix Ramón's Avatar Code Author
  • Offline
More
1 year 4 days ago #505 by Ramón San Félix Ramón
Ramón San Félix Ramón replied the code: Toast Notification's Utility
With the example you sent me, I have passed the logic of the notification call to the w_open window, which is now the main one. So if you close the w_main window as soon as you press the test button, nothing happens.
Now in the w_main window, by pressing the test button we execute a global function to call the notification. With this global function we can easily call notifications from anywhere in the application.
In the global function we check that the w_open window exists and launch the notification, if it does not exist, we launch a messagebox instead of the notification.
That's more or less how I have it and it works well for me, w_open would be the main window in this case of the application.
I attach your modified example as indicated. (pb2022 R2 Build 2828)

This message has an attachment file.
Please log in or register to see it.

Please Log in or Create an account to join the conversation.

More
1 year 4 days ago #504 by Sivaprakash BKR
Sivaprakash BKR replied the code: Toast Notification's Utility
Thanks Ramon for your reply. Let me be more clear.

When I close the second window, from which the notification has been calls, even before the notification disappears, it makes the first window also to close automatically, there by the application.

**********************
In my case, I have a function in the main window of the application that triggers the notification. Since this window is never closed, if the application is not closed there is no problem. In the closequery event of that window I have a code to remove the notification if it closes, so that there is no error.
**********************
It seems that the code in the closequery event is closing the active window. In my case, since I manually closed the notification calling window, the code is closing the current active window, which should not happen.

Attached is the slightly modified copy of the toast program (PB 2022 R2 build 2819). To test
1. Run the application
2. It opens a window with a button
3. Click the button
4. That opens your toast window
5. Click Test
6. It displays the toast
7. Even before the toast notification goes off, close your toast window
8. Now the first window will be active
9. Just wait. First window automatically gets closed, by that way the application.

This message has an attachment file.
Please log in or register to see it.

Please Log in or Create an account to join the conversation.

  • Ramón San Félix Ramón
  • Ramón San Félix Ramón's Avatar Code Author
  • Offline
More
1 year 5 days ago #503 by Ramón San Félix Ramón
Ramón San Félix Ramón replied the code: Toast Notification's Utility
Hi Sivaprakash BKR,

The problem is that the window that calls the notification closes?

In my case, I have a function in the main window of the application that triggers the notification. Since this window is never closed, if the application is not closed there is no problem. In the closequery event of that window I have a code to remove the notification if it closes, so that there is no error.

Best Regards
Ramón.

Please Log in or Create an account to join the conversation.

Moderators: Appeon Administrator