Handle to a window
-
I am trying to send a message from a worker thread to a specific class/window in the main dialog. How do I find the HWND of this dialog in order to call PostMessage/SendMessage with the appropriate parameters?
Your question is similar to the question: "I am trying to send a letter from my work location to someone downtown. How do I find the address of that person in order to put an address on the letter?" We cannot help without either guessing or asking you a lot of questions and if you answer all the questions then you will probably have answered your question yourself.
-
Your question is similar to the question: "I am trying to send a letter from my work location to someone downtown. How do I find the address of that person in order to put an address on the letter?" We cannot help without either guessing or asking you a lot of questions and if you answer all the questions then you will probably have answered your question yourself.
-
I am trying to send a message from a worker thread to a specific class/window in the main dialog. How do I find the HWND of this dialog in order to call PostMessage/SendMessage with the appropriate parameters?
-
Roger, I'm pretty sure that FindWindow will return a valid hwnd for any window currently in the zorder. You need only pass the window title to the function to return the hwnd. Check the docs or search msdn for FindWindow. Good luck, Frank
-
The windows I am mostly working with are child windows with no title. I noticed the FindWindow function takes one of two parameters, class name or window name. What do you do if you do not have a title for the window? How do you find the class name?
You can use Spy++ to retrieve the class name. It should have been installed with VC++ 6. Spy will allow you to select a window to "spy" and then it will give you all the relevant information about that window. You can also use spy to "spy" :) on window messages. Nice utility. Frank
-
You can use Spy++ to retrieve the class name. It should have been installed with VC++ 6. Spy will allow you to select a window to "spy" and then it will give you all the relevant information about that window. You can also use spy to "spy" :) on window messages. Nice utility. Frank
-
When using Spy++ I can find the correct dialog, but all of the dialogs that are open have the same classname, #32770 (that is the classname for ALL dialogs on the application). How do I differentiate between thm when using FindWindow and using the class name parameter?
-
When using Spy++ I can find the correct dialog, but all of the dialogs that are open have the same classname, #32770 (that is the classname for ALL dialogs on the application). How do I differentiate between thm when using FindWindow and using the class name parameter?
Hello, I think you are on the wrong track with FindWindow. Why don't you just store the pointers to the ChildWindows in a nice collection class (e.g. in the parent or in your application object) when they are created, and remove them when you destroy them. You can even make them searchable on a particular key (hey, you are the boss, so you decide what the key should be). Then don't use (p_whatever)->SendMessage(...); // p_whatever is a pointer to a CWnd but use HWND theWindow = (p_whatever)->GetSafeHwnd(); if (theWindow != NULL) { SendMessage(theWindow, ...); } or better use PostMessage. better still when sending messages to other threads use PostThreadMessage. Don't over-complicate things...
-
Hello, I think you are on the wrong track with FindWindow. Why don't you just store the pointers to the ChildWindows in a nice collection class (e.g. in the parent or in your application object) when they are created, and remove them when you destroy them. You can even make them searchable on a particular key (hey, you are the boss, so you decide what the key should be). Then don't use (p_whatever)->SendMessage(...); // p_whatever is a pointer to a CWnd but use HWND theWindow = (p_whatever)->GetSafeHwnd(); if (theWindow != NULL) { SendMessage(theWindow, ...); } or better use PostMessage. better still when sending messages to other threads use PostThreadMessage. Don't over-complicate things...
Thanks for the advice, I am currently using PostMessage back to the main window then handling messages from there. Although your advice sounds very interesting about storing them as they are created. It is nice to be the boss and be able to do it how you want isn't it, THANKS!!!
-
Roger, I'm pretty sure that FindWindow will return a valid hwnd for any window currently in the zorder. You need only pass the window title to the function to return the hwnd. Check the docs or search msdn for FindWindow. Good luck, Frank