Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I see what you are trying to do now, I have achieved this in my application framework called Lucid (it is still a work in progress). For the sake of the answer, your window class will be called <code>Window</code> instead of <code>APP</code>.</p> <p>This is done by passing a global procedure to every window you create. All windows share this same procedure. Every time any window gets a message, that message is sent to the global procedure, the global procedure checks if the <code>HWND</code> belongs to a <code>Window</code> that you created, and if it does, sends the message to that <code>Window</code>s' procedure. Here's an overview of how this works.</p> <pre><code>class Window { public: // The contents of this function can vary from window to window // provided that you make a subclass and override this method. virtual LRESULT procedure(HWND wnd, UINT msg, WPARAM wp, LPARAM lp); // When you create a Window object, add a pointer to it in this map. // Eg. if (this-&gt;hwnd != NULL) createdWindows[this-&gt;hwnd] = this; static map&lt;HWND, Window*&gt; createdWindows; // When you create a window, make this its procedure. static LRESULT CALLBACK routeMessage(HWND wnd, UINT msg, WPARAM wp, LPARAM lp) { if (createdWindows.find(wnd) != createdWindows.end()) { // Message belongs to one of our 'Window' objects. // Pass the message to that window and return the result. return createdWindows[wnd]-&gt;procedure(wnd, msg, wp, lp); } else { // It seems you made 'routeMessage' the procedure // of a window that doesn't belong in the map. Go ahead // and process the message in the default manner. return DefWindowProc(wnd, msg, wp, lp); } } }; </code></pre> <p>Now you will only need a single message loop and a single thread. I hope this helps. If it doesn't, I can give you the source code to my project Lucid that demonstrates this concept, along with event handlers. I have a test project using Lucid that creates 2 windows with different procedures on a single thread with a single message loop:</p> <pre><code>#include "Lucid.h" using namespace Lucid; void sayBye(MessageEventArgs&amp; e) { MessageBox(NULL, "Goodbye!", "Form 2", MB_OK); e.handled = true; } void Program::onStart() { Form* myForm1 = new Form("Hello World!"); myForm1-&gt;show(); Form* myForm2 = new Form("Hello World!"); myForm2-&gt;addMessageHandler(WM_CLOSE, sayBye); myForm2-&gt;show(); // This Program::onStart() function is called // immediately before the single message loop is entered. } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload