I am using ModuleOnWithWindow and either need to find a way to make a window like this modal, or to close it if it looses focus.
I looked but could not find a uiConnect event for focus? Is there a way to get an event when a window looses focus, either at the window level or to monitor at the topology level?
Todd Malone
how to get an event when window/module goes behind?
- tmalone
- Posts:192
- Joined: Mon Nov 22, 2010 11:21 pm
how to get an event when window/module goes behind?
- hpuchegger
- Posts:86
- Joined: Fri Oct 08, 2021 10:38 am
Re: how to get an event when window/module goes behind?
Maybe the ChatGPT answer can help you in this case:
In WinCC OA, to create a modal window, you can use the ChildPanelOnModuleModal function, which opens a child panel modally. This ensures that the child panel must be closed before the user can interact with the parent panel again. Here's the function signature:
void ChildPanelOnModuleModal(string FileName, string PanelName, string ModuleName, dyn_string Parameter, int x, int y);
If you want to close the window when it loses focus, you can utilize the uiConnect function to monitor window events. However, there is no direct event for "focus lost" in the UI global events. Instead, you can use the windowStateChanged event to check if the window state changes, which might indicate a loss of focus.
Here’s an example of how to connect to the windowStateChanged event:
uiConnect("myCallbackFunction", "windowStateChanged");
In your callback function, you can check the state and decide to close the window if it has lost focus
Br, Herbert
In WinCC OA, to create a modal window, you can use the ChildPanelOnModuleModal function, which opens a child panel modally. This ensures that the child panel must be closed before the user can interact with the parent panel again. Here's the function signature:
void ChildPanelOnModuleModal(string FileName, string PanelName, string ModuleName, dyn_string Parameter, int x, int y);
If you want to close the window when it loses focus, you can utilize the uiConnect function to monitor window events. However, there is no direct event for "focus lost" in the UI global events. Instead, you can use the windowStateChanged event to check if the window state changes, which might indicate a loss of focus.
Here’s an example of how to connect to the windowStateChanged event:
uiConnect("myCallbackFunction", "windowStateChanged");
In your callback function, you can check the state and decide to close the window if it has lost focus
Br, Herbert
- gschijndel
- Posts:376
- Joined: Tue Jan 15, 2019 3:12 pm
Re: how to get an event when window/module goes behind?
To keep a module on top you could try the stayOnTop function.
Guess that with the 'WindowActive' state it could be checked if it has the focus.
But I would suggest to use the undocumented popup feature, which is also used by the Popup Menu. It uses childPanel with in the optional parameters 'windowFlags' with the value 'Popup'. The details can be found in the popup menu implementation.
Guess that with the 'WindowActive' state it could be checked if it has the focus.
But I would suggest to use the undocumented popup feature, which is also used by the Popup Menu. It uses childPanel with in the optional parameters 'windowFlags' with the value 'Popup'. The details can be found in the popup menu implementation.
- tmalone
- Posts:192
- Joined: Mon Nov 22, 2010 11:21 pm
Re: how to get an event when window/module goes behind?
thanks for the suggestions.
The AI bot helped me a little bit, but "windowStateChanged" does not help for a loss of focus, only when the window functions are called like minimize.
the stayOnTop might be some magic. Let me see if that would be useful.
Some more background, I am making these calls from the infoModule in topology and so all the child panel functions are messy, center is wrong, location is goofy, etc.
The AI bot helped me a little bit, but "windowStateChanged" does not help for a loss of focus, only when the window functions are called like minimize.
the stayOnTop might be some magic. Let me see if that would be useful.
Some more background, I am making these calls from the infoModule in topology and so all the child panel functions are messy, center is wrong, location is goofy, etc.
- tmalone
- Posts:192
- Joined: Mon Nov 22, 2010 11:21 pm
Re: how to get an event when window/module goes behind?
solution for me:
stayOnTop(TRUE);
windowStyle(myModuleName(), "", 0, 0);
that forces the window to be always on top, and also disables the minimize and close function in the window title bar. The title bar allows the window to be moved to see behind it. (the help AI bot helped me find the windowStyle call.
I like this solution.
Todd Malone
stayOnTop(TRUE);
windowStyle(myModuleName(), "", 0, 0);
that forces the window to be always on top, and also disables the minimize and close function in the window title bar. The title bar allows the window to be moved to see behind it. (the help AI bot helped me find the windowStyle call.
I like this solution.
Todd Malone