I am building a custom data structure that is a binary tree of objects and binary trees. ie: each node in the top level tree could be an "object" or an "objectContainer" (which in turn could have "object"s or "objectContainer"s for nodes).
I have a message pump in my main thread, through this pump I handle all the windows messages intended for my main window (clicks, drags and resizing, button presses). And when it is not dealing with windows messages it ticks a timer and updates the scene. When the main window receives a specific key stroke it (currently) spins off a new thread, that thread then creates a new object (or objectContainer) and, during the new object's creation, a modal (blocking) dialog box is spawned so that the user can interact with/input initial values for the newly created object. Upon clicking OK, if the name provided is unique (with regards to the contents of the top level container), the new object is added to the top level container. Finally, if a modal dialog box (spawned from inside yet another thread) that displays the contents of a (in this case the top level) container, is open, I send a WM_message to said dialog box that is intended to tell it to add the new item's name to a list box of strings. I am having issues with the sending of these messages to dialog boxes. For instance, when I create an objectContainer the correct name appears in the list right away after pressing the OK button, but not if I am creating an object. I assumed it may have something to do with threading, but I do not know. Each type of object uses the same addObject() function, which is where the container's displaying box is tested to be open or not and the message is sent.
What I have tried:
I have read articles that say never use threading… unless you absolutely have to! And that all UI should be done in the same thread. Some even say to only do UI through the main thread. I have tried variations of my application with some of the techniques I feel like the authors of these articles are suggesting but something is not right.
I made a version in which, when the button is pressed, the main thread spawns a modeless dialog that does the work of interacting with the newly created object. This works well except for, if say the user is dragging around a modeless dialog box for a long period of time, the main process gets stalled. I have a function after the IsDialogMessage part of the main message pump that calculates frame rate and it tanks when the modeless dialog box is clicked and held by the user. I don’t think I want that happening, the functions that update the scene are not run until the user lets go. (come to think of it, if i drag around the main window the frame rate processing stalls too... but i suspect that is unavoidable, right? unless that processing is in its own thread...?)
I have also created a version where once the button is clicked the main thread spins off a new thread, the new thread creates the new object or objectContainer and right after the new item is created it spawns a modeless dialog box to editObject(). With the modeless dialog box the calling thread is not blocked and so I added a message pump directly after the creation of said modeless dialog box and it appears to be working. I have not yet tested past the adding of the objects and verifying that the name is unique in the top level container. I do not know if the wm_messages will reach the correct window and control the dialog box's string list box as I wish.
I am having issues with each of my design attempts and would just like to know your thoughts on design before I waste more time debugging a bad design. Should the main thread spin off a thread and call a modal dialog box? Or should all dialog boxes be called from the main thread and I, somehow, move what I think needs to be continually processing to its own thread? Or should the main thread spin off a thread and then use modeless dialog boxes?