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. Pointer to another Window

Pointer to another Window

Scheduled Pinned Locked Moved C / C++ / MFC
questioncomhelp
7 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.
  • T Offline
    T Offline
    tjkrz
    wrote on last edited by
    #1

    Within my program, I want to bring a window to another program to the foreground. I'm doing the following: CWnd *pFV; pFV = CWnd::FindWindow(NULL, _T("Another Program Title")); Then if FindWindow was successful, I call pFV->SetForegroundWindow() to bring it to the front. This works great in most cases, but it sometimes fails... The program I'm referencing changes its name in the titlebar depending on which options are selected. I don't have the source to the program, so I can't modify it. How can I get a pointer to this window without knowing what the title is going to be? Is there a way to link to the process name? I also know that the first x characters in the title will always be the same. Is there some way to search through all the titles of open windows to do a comparison? Any help would be greatly appreciated. Thanks. Todd Krzeminski tkrzeminski@nlxcorp.com

    A D J 3 Replies Last reply
    0
    • T tjkrz

      Within my program, I want to bring a window to another program to the foreground. I'm doing the following: CWnd *pFV; pFV = CWnd::FindWindow(NULL, _T("Another Program Title")); Then if FindWindow was successful, I call pFV->SetForegroundWindow() to bring it to the front. This works great in most cases, but it sometimes fails... The program I'm referencing changes its name in the titlebar depending on which options are selected. I don't have the source to the program, so I can't modify it. How can I get a pointer to this window without knowing what the title is going to be? Is there a way to link to the process name? I also know that the first x characters in the title will always be the same. Is there some way to search through all the titles of open windows to do a comparison? Any help would be greatly appreciated. Thanks. Todd Krzeminski tkrzeminski@nlxcorp.com

      A Offline
      A Offline
      Antti Keskinen
      wrote on last edited by
      #2

      The most efficient method here would be to use Microsoft Spy++ to find out the class name of the window, then use FindWindow on the class name instead of window caption. Just start Spy++, start the target program, and detect it's class name. If you do not know how to use Spy++, refer to it's help files, they are very throughout. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

      T 1 Reply Last reply
      0
      • T tjkrz

        Within my program, I want to bring a window to another program to the foreground. I'm doing the following: CWnd *pFV; pFV = CWnd::FindWindow(NULL, _T("Another Program Title")); Then if FindWindow was successful, I call pFV->SetForegroundWindow() to bring it to the front. This works great in most cases, but it sometimes fails... The program I'm referencing changes its name in the titlebar depending on which options are selected. I don't have the source to the program, so I can't modify it. How can I get a pointer to this window without knowing what the title is going to be? Is there a way to link to the process name? I also know that the first x characters in the title will always be the same. Is there some way to search through all the titles of open windows to do a comparison? Any help would be greatly appreciated. Thanks. Todd Krzeminski tkrzeminski@nlxcorp.com

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        tjkrz wrote: How can I get a pointer to this window without knowing what the title is going to be? How about the window's class name?


        Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

        1 Reply Last reply
        0
        • A Antti Keskinen

          The most efficient method here would be to use Microsoft Spy++ to find out the class name of the window, then use FindWindow on the class name instead of window caption. Just start Spy++, start the target program, and detect it's class name. If you do not know how to use Spy++, refer to it's help files, they are very throughout. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

          T Offline
          T Offline
          tjkrz
          wrote on last edited by
          #4

          I tried that, but for the class name I get an long string (Afx:4000...) that seems to vary each time I run it. Am I doing something wrong? Thanks, Todd Krzeminski tkrzeminski@nlxcorp.com

          A 1 Reply Last reply
          0
          • T tjkrz

            Within my program, I want to bring a window to another program to the foreground. I'm doing the following: CWnd *pFV; pFV = CWnd::FindWindow(NULL, _T("Another Program Title")); Then if FindWindow was successful, I call pFV->SetForegroundWindow() to bring it to the front. This works great in most cases, but it sometimes fails... The program I'm referencing changes its name in the titlebar depending on which options are selected. I don't have the source to the program, so I can't modify it. How can I get a pointer to this window without knowing what the title is going to be? Is there a way to link to the process name? I also know that the first x characters in the title will always be the same. Is there some way to search through all the titles of open windows to do a comparison? Any help would be greatly appreciated. Thanks. Todd Krzeminski tkrzeminski@nlxcorp.com

            J Offline
            J Offline
            Joel Lucsy
            wrote on last edited by
            #5

            If you can't use the class name, then the best alternative is to use EnumWindows. This will call a function you provide. With each callback you get will need to retrieve the titlebar text and do your own matching. Once you've found the window you can return FALSE to stop the enumeration early. Hope that helps. -- Joel Lucsy

            T 1 Reply Last reply
            0
            • T tjkrz

              I tried that, but for the class name I get an long string (Afx:4000...) that seems to vary each time I run it. Am I doing something wrong? Thanks, Todd Krzeminski tkrzeminski@nlxcorp.com

              A Offline
              A Offline
              Antti Keskinen
              wrote on last edited by
              #6

              This type of class name means that the program uses MFC to register a new class for itself always when it is run. This means that the class name of the window is not an usable option. The other poster suggested using window enumeration callback routine. I find this the best alternative as well. Just get the caption of each window and compare X characters of it to see if there is a match. I remember you saying that certain characters of the window title always remain constant, so this would sound like the best course of action. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

              1 Reply Last reply
              0
              • J Joel Lucsy

                If you can't use the class name, then the best alternative is to use EnumWindows. This will call a function you provide. With each callback you get will need to retrieve the titlebar text and do your own matching. Once you've found the window you can return FALSE to stop the enumeration early. Hope that helps. -- Joel Lucsy

                T Offline
                T Offline
                tjkrz
                wrote on last edited by
                #7

                Thanks, I got it working with EnumWindows.

                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