Taking control of main thread in windows c ++ application
I am writing code that I like can work with any window, like a window created via the windows API, MFC, wxWidgets, etc.
The problem is that for some things, I need to use the same thread that created the window, which in many cases just sits in a message loop.
My first thought was to send a callback message to the window, which will then call a function in my code when it receives a message using one of the parameters and a function pointer of some roles. However, there doesn't seem to be a standard Windows message for this, and I can't create my own message since I don't control the Windows code, so I can't add the code I need to the message handler to implement the callback ...
Is there any other way to get the thread that created the input box for my function?
EDIT: John Z clarified that I connected windows messages. If I do this, is there a way to get the "IDs" for the custom posts without risking bumping into any custom posts that are already in the window?
For example, I could do
WM_CALLBACK = WM_APP+1
But if the window I am hooking has already done something with WM_APP + 1, I will have problems.
EDIT2: Just found RegisterWindowMessage :)
source to share
If you are in the same process as a window, you can wire its messages by subclassing it. Check http://msdn.microsoft.com/en-us/library/ms633570(VS.85).aspx
The key API is SetWindowLong.
// Subclass the edit control.
wpOrigEditProc = (WNDPROC) SetWindowLong(hwndEdit, GWL_WNDPROC, (LONG)EditSubclassProc);
// Remove the subclass from the edit control.
SetWindowLong(hwndEdit, GWL_WNDPROC, (LONG)wpOrigEditProc);
source to share