Created a function that creates additional windows in win api. Only one problem, the window is registered and created by pressing a button, and subsequent clicks on a new register class. How to create a condition that if the class of this window is already registered, then it is not necessary to register it on a new one?
1 answer
If I understand you correctly, the desired behavior is in the presence of no more than one open window of a class. I offer a couple of options for this task.
Method 1. Declare a pointer to the object of this window, assign nullptr . Then, when creating an object, first check this variable - if it is nullptr , then create a window and save the object in a pointer; otherwise do nothing.
Probably, when you close that window, you need this pointer to be set to zero again. To do this, you will need to add feedback to the class in the destructor: a pointer to the object that spawned it, and there already call the method to clear the first pointer.
Method 2 is simpler. In the class of the additional window, add a private static integer variable - a count of the number of open windows. In the constructor, add one, subtract it in the destructor. Also, a public static method that returns this value in order to check it again for equality to zero before creating a new object.