Toast Notification's Utility

  • Ramón San Félix Ramón
  • Ramón San Félix Ramón's Avatar Code Author
  • Offline
More
6 months 1 week 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.

More
2 months 3 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
2 months 3 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
3 months 2 days 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
4 months 2 weeks 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
4 months 2 weeks 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
4 months 2 weeks 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.

More
4 months 2 weeks ago #502 by Sivaprakash BKR
Sivaprakash BKR replied the code: Toast Notification's Utility
Hello,
Thanks for the nice utility. I did incorporate that into my application. It's working fine under most circumstances. And I did face one issue on this condition.
1. I have two windows, a. Login window b. Profile creation window
2. From login window, I open the profile creation window, which is a response window.
3. I add one entry and use the notification utility to inform as such. The toast waits for 5 seconds and then goes off.
4. If I wait for that 5 seconds, then close that profile creation window, no issues.
5. If I don't wait for 5 seconds, immediately close the profile creation window, the control is back to login window. When the control is in login window, keeping it idle makes the application to close.
6. This issue is not there, when I wait for that 5 seconds, then close [ Toast Notification will go off ], the profile window.

Any workaround to solve this issue.

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

Moderators: Appeon Administrator