Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proper/accepted design of accessing application variables from a window class?

My immediate context is the Windows platform, however I might also ask this same question when working on a ui for another gui host. I'm working in fairly plain c++ winapi, without ATL/MFC. I'm not interested in using globals, but rather a more oop accepted practice of performing "Window" related tasks with "Application" data.

I've considered implementing mvvw or mvc style patterns to this, but before I go ahead I'd like some community opinions, from what I imagine are countless experienced developers and designers.

My Application class has Window members. Should the Window class be designed with an Application reference? Or is there a better way than this?

like image 708
chrisp Avatar asked Jan 18 '12 04:01

chrisp


People also ask

Which two processes need to access a critical section of code?

Two processes, P1 and P2, need to access a critical section of code. Consider the following synchronization construct used by the processes:Here, wants1 and wants2 are shared variables, which are initialized to false. Which one of the following statements is TRUE about the above construct?v (A) It does not ensure mutual exclusion.

What are the different types of access methods supported by IBM?

Other systems, such as those of IBM, support many access methods, and choosing the right one for a particular application is a major design problem. There are three ways to access a file into a computer system: Sequential-Access, Direct Access, Index sequential Method.

What is an application properties file?

This file contains the different configuration which is required to run the application in a different environment, and each environment will have a different property defined by it. Inside the application properties file, we define every type of property like changing the port, database connectivity, connection to the eureka server, and many more.

What are the application properties in Spring Boot?

Inside the application properties file, we define every type of property like changing the port, database connectivity, connection to the eureka server, and many more. Now let’s see some examples for better understanding. Sometimes when you run your spring application you may encounter the following type of error


1 Answers

The Win API of a Window gives you a Set/GetProperty() which allows you to define a pointer to whatever you'd like (i.e. your own window object.) However, from experience I know that's rather slow.

The other possibility is to use a map where the pointer of the Win API windows are used as keys and the value is your window object. This is a lot faster, but where do you put that map if you don't have any globals?

As suggested by Samuel, a singleton allows you to get an object which is pretty much the same as a global. Then you can get your window object using the Win API window pointer as the key and it returns your object.

This is required to map incoming events to your window objects. Everything else should anyway be done the other way around (As you'd expect, call functions only on your window object that are mapped in a similar way as the system windows.)

Why aren't you using Qt? it's already in C++ and you don't have to worry about those details...

like image 145
Alexis Wilke Avatar answered Nov 11 '22 11:11

Alexis Wilke