interaction between GUIs

Windows 11, Visual Studio 2022, C++, GUI programming.

This project was created under Windows Desktop Application, but maybe one of the other project types. Some GUIs need to communicate with others, meaning call functions in the other. The only way I know how to do that is to start in one GUI, get the address of the other, create a pointer, then use that pointer. I suspect there is a much better way.

Here are some example names for this particular conversation. A GUI called Worker does an essential task. A GUI called Tester is to verify that the functions of Worker do work correctly. What is/are the best methods to call functions in Worker from Tester?

Just for completeness, in Tester I put an #include for a class in Worker, then tried to call a function in that class. The build tool reported: ‘clear_one_edit_control’: identifier not found.

Side question. I wanted to bold the words Worker and Tester. The words were highlighted, the B was clicked on in the tool bar at the bottom for each, the click Preview. From the Preview page I could not get back to my original question. What did I do wrong?
Last edited on
Some GUIs need to communicate with others, meaning call functions in the other

Are we talking about different windows (or views etc.) within the same process, or completely separate processes?

I'm going to assume you mean different (or views etc.) windows within the same process.

I think you should re-design your code, if your one window (or view etc.) needs to call a function from another. Instead, you should be following a Model-View-Controller (MVC) pattern. In short, if any "state" in your application needs to be updated, then the logic (function) to modify the state goes into the controller. The function in the controller manipulates the state in the model as needed. Finally, whenever the "state" in the model changes, all the view(s), i.e. the GUIs, that are connected to the model will updated themselves accordingly.

In other words, you generally don't call a function in one view (GUI) from another. Instead, from the GUI (e.g. user input) you invoke the suitable function in the controller, so that the controller can manipulate the "state" in the model. This will, in turn, allow the other views (GUIs) to update themselves as needed. This design provides a nice decoupling of all the views in your application!

https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

____

How do the views (GUIs) know when something in the model has changed?

The observer pattern is your friend here:
https://en.wikipedia.org/wiki/Observer_pattern

Simply put, the model is the "subject" here, and the views (GUIs) are the "subscribers". This allows the views (GUIs) to subscribe to the model. So, whenever a change to the state in the model occurs, the model notifies all the views (GUIs).

____

Honstely, these days, you can simple enter a query like "Simple but complete Model-View-Controller example with pure Win32 API" into ChatGPT (or whatever LLMs you prefer) and that should give you something that gets your started.
Last edited on
I was completely unaware of MVC. This is not a web application and a complete re-write seems like tremendous overkill just to share access between GUIs. Seems like having separate GUIs for different purposes and being able to call each other's functions would be a common concept. I am looking into the MVC concept.

The Observer patten looks like a possibility so am looking there.

There are two other methods, I suspect. Each GUI gets a pointer to modules it needs, as I have done with two of them. It is a bit awkward, must be certain the other GUI already exists, but once the pointer is set it provides fast interface.

Or use a shared module, something I just discovered for Visual Studio and maybe other development systems for multiple GUIs. I found a description about that. Maybe use it to hold and share pointers to every GUI.

Thank you for your time.
Last edited on
Registered users can post here. Sign in or register to post.