Re: Passing a GUI handle to a socket and Postmessage back to GUI
"KW" <KW@there.com> wrote in message
news:uyJqKKnoJHA.996@TK2MSFTNGP03.phx.gbl...
This is workable, but a better OOP design would pass 'this' to the
constructor of the client. Then the client would depend only on the code
that creates it.
Your answer here is what I thought - there must be a better way to
do this, however, I still am not sure how to accomplish
it.
How would I pass "this" to the client and from where? I assume I
would need to get the HWND from the "this" pointer. Correct?
You would pass 'this' instead of the HWND. The client can store and use
that pointer to call the socket object that created it. That socket object
has the HWND, and can use it in PostMessage, or perhaps can make a direct
call to the object that created it. The point is that the low level client
object need not know or care what is ultimately done with the message.
But your MySocket object still has a dependency on the application window.
For the ultimate in OOP you could make the MySocket object, and its client
socket object, reusable in other projects by designing an interface class.
It would inherit from MySocket, and MySocket would call a virtual function
with received messages. Each application then adds a tiny wrapper class
inherited from the reusable interface and customizes it to pass the message
to wherever it is needed in that particular application.
--
Scott McPhillips [VC++ MVP]