Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Handle to a window

Handle to a window

Scheduled Pinned Locked Moved C / C++ / MFC
question
11 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Roger
    wrote on last edited by
    #1

    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?

    S F 2 Replies Last reply
    0
    • R Roger

      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?

      S Offline
      S Offline
      Sam Hobbs
      wrote on last edited by
      #2

      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.

      R 1 Reply Last reply
      0
      • S Sam Hobbs

        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.

        R Offline
        R Offline
        Roger
        wrote on last edited by
        #3

        Ok, whatever the hell that is supposed to mean.

        1 Reply Last reply
        0
        • R Roger

          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?

          F Offline
          F Offline
          Frank Deo
          wrote on last edited by
          #4

          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

          R S 2 Replies Last reply
          0
          • F Frank Deo

            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

            R Offline
            R Offline
            Roger
            wrote on last edited by
            #5

            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?

            F 1 Reply Last reply
            0
            • R Roger

              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?

              F Offline
              F Offline
              Frank Deo
              wrote on last edited by
              #6

              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

              R 1 Reply Last reply
              0
              • F Frank Deo

                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

                R Offline
                R Offline
                Roger
                wrote on last edited by
                #7

                Thank ya much, never used Spy++, could be a neat adventure.

                R 1 Reply Last reply
                0
                • R Roger

                  Thank ya much, never used Spy++, could be a neat adventure.

                  R Offline
                  R Offline
                  Roger
                  wrote on last edited by
                  #8

                  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?

                  G 1 Reply Last reply
                  0
                  • R Roger

                    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?

                    G Offline
                    G Offline
                    GBO
                    wrote on last edited by
                    #9

                    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...

                    R 1 Reply Last reply
                    0
                    • G GBO

                      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...

                      R Offline
                      R Offline
                      Roger
                      wrote on last edited by
                      #10

                      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!!!

                      1 Reply Last reply
                      0
                      • F Frank Deo

                        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

                        S Offline
                        S Offline
                        Sam Hobbs
                        wrote on last edited by
                        #11

                        Notice that in his original question he did not specify that the dialogs he is trying to find were created by him. Since they are, GBO's suggestion is more relevant. This is what happens when questions are not clear.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups