Announcement

Collapse
No announcement yet.

Instance Parent

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Instance Parent

    Looked around but not see anything directly related to this...

    Is it possible for an application to determine what application started it?

    For example, can an application determine whether is was started on the command line by the windows shell, rather then shelled to from another program?

    I want to center an application based on who started it, centered on desktop if was started by itself, or center on the calling application is was shelled from within it.
    <b>George W. Bleck</b>
    <img src='http://www.blecktech.com/myemail.gif'>

    #2
    I reworded my search keywords and came up with this... a few weeks old

    User to user discussions about the PB/Win (formerly PB/DLL) product line. Discussion topics include PowerBASIC Forms, PowerGEN and PowerTree for Windows.


    I will look into it.
    <b>George W. Bleck</b>
    <img src='http://www.blecktech.com/myemail.gif'>

    Comment


      #3
      Ok that link looks like it is very usefull and the link here http://www.powerbasic.com/support/pb...parent+process really hits home.

      Just thinking to myself about this issue (and documenting it here so people don't go through the same steps) it appears there is an unavoidable flaw in my process.

      Even if I get the calling instance, there could be multiple windows open by the instance...which windows do I center on???. Getting Z order might help but it might not always be the top most window that the application would center on.

      Seems like it is not 100% answerable unless I can track back to the actually calling window handle as well.
      <b>George W. Bleck</b>
      <img src='http://www.blecktech.com/myemail.gif'>

      Comment


        #4
        May we assume this is a non-cooperating application?
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


          #5
          My application is a standalone EXE and is called from other applications (or from the desktop directly).

          I do not control the 3rd party apps except in the fact that they can shell out and call my app. I can't control the parameters passed to it.
          <b>George W. Bleck</b>
          <img src='http://www.blecktech.com/myemail.gif'>

          Comment


            #6
            What you need to do is get a list of processes currently running and find the parent process info.

            Using CreateToolhelp32Snapshot, this info is in the PROCESSENTRY32 structure returned by the Process32First/Next functions called against that ToolHelp handle. You will have to xref against the parentProcessID member. The EXE used to launch any process is in the SzEXE name member of PROCESSENTRY32.

            Hey, you asked!

            MCM
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


              #7
              Oh thats the easy part... I got that already

              The part that becomes the problem is to determine which sub window of an application is the one to center on.

              If an application has 3 open windows how does a shelled one know which one to center on... answer...it doesn't unless that parameter is passed...which I can't pass.
              <b>George W. Bleck</b>
              <img src='http://www.blecktech.com/myemail.gif'>

              Comment


                #8
                What are you centering on this other window, that you can't just center on the desktop?

                Surely if the user is to 'enter' something on this window, centered on the desktop can't be all bad.. since you want the user's attention.

                But FWIW, since you have the snapshot you can get a handle or id of each thread of the target 'parent' app.. and from that you can use EnumThreadWindows to get a list of all the windows created by that thread; put em all together you have a list of all windows created by the application. Then you can find the zorder (I think they are enumed in zorder) and assume the window first in that z-order is that process' current active window. You'll have to make a good guess as to which thread of the target application is current, but with luck this foreign application has only one GUI window, and you can use the enum'd list from that one thread. You could try to AttachThreadInput() ... if that fails the thread is not a GUI thread and you can eliminate that thread from your "suspect list."

                You asked.

                MCM
                Last edited by Michael Mattias; 23 Mar 2009, 05:05 PM.
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                  #9
                  Then again, maybe you could just OpenProcess() of the owner process and get the command line used?

                  Maybe that would tell you something.
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                    #10
                    Or, you could do your client a service and sell him a program which does what he needs instead of spending thousands of dollars trying to work with what he has now.
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                      #11
                      Im the client so I'm seeling my own goods.

                      I have a 3 monitor setup (21" - 24" - 21"), and certain applications I use in my day to day operations allow me to shell out certain things. But thats just it.. a shell, and I wanted the application I'm shelling to to pop up on the correct monitor so it makes sense as to which app did the shelling.

                      The other apps I'm using I did not write, but I am writing the pop-up app. Hope that makes a bit more sense.
                      <b>George W. Bleck</b>
                      <img src='http://www.blecktech.com/myemail.gif'>

                      Comment


                        #12
                        If an application has 3 open windows how does a shelled one know which one to center
                        on... answer...it doesn't unless that parameter is passed...which I can't pass.
                        If the application is in the foreground or background, you can center over the window that is
                        at the top of the z-order within the application. The window at the top of the z-order implies
                        that it has the input focus or had the input focus when the application was in the foreground.
                        This assumes, however, that the windows are not in an owner/owned relationship.

                        Once you know the window you want to be over, popping up on the correct monitor is a simple matter.
                        Dominic Mitchell
                        Phoenix Visual Designer
                        http://www.phnxthunder.com

                        Comment


                          #13
                          Aye, I did think of that as a possible solution, but the topmost window may not always be the one that shelled out the program.

                          I was trying to create a "catch all" solution which is not possible without being able to send the correct window handle, which I cant do.

                          I was just trying to think out loud.
                          <b>George W. Bleck</b>
                          <img src='http://www.blecktech.com/myemail.gif'>

                          Comment


                            #14
                            What about GetParent? Have you looked to see if windows will return the "parent" of the program?
                            Furcadia, an interesting online MMORPG in which you can create and program your own content.

                            Comment


                              #15
                              >but the topmost window may not always be the one that shelled out the program.

                              Windows don't SHELL or CreateProcess or ShellExecute[Ex]; processes do. A window in one process has no relationship to any other process. For that matter, it has no relationship to any other thread other than that in which it was created and executes.
                              Michael Mattias
                              Tal Systems (retired)
                              Port Washington WI USA
                              [email protected]
                              http://www.talsystems.com

                              Comment


                                #16
                                Is it possible for an application to determine what application started it?
                                Yes it is, and I could have sworn I had it posted in the source code forum, but can not find it.

                                I will have to look back, but the one thing I do remember is having to do with "GetModuleHandle" was the key to all the rest.

                                Not sure about differences between SHELL and ShellExecute, or commandline, but I know I was able to determine if I was the parent, or if running under another parent (of sorts)

                                overall one of those things that I thought I had stockpiled for my next big project, and now that it can help someone else, danged if I know where I put it.

                                GetModuleHandle is the key though
                                Engineer's Motto: If it aint broke take it apart and fix it

                                "If at 1st you don't succeed... call it version 1.0"

                                "Half of Programming is coding"....."The other 90% is DEBUGGING"

                                "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                                Comment


                                  #17


                                  The above link basically gives you all you need as a template. It was designed to delete the parent, but if you just utilize the information it obtains you have almost everything you need.

                                  The only part I needed above and beyond that code was what window in a multi-window application would receive the attention of the child.
                                  <b>George W. Bleck</b>
                                  <img src='http://www.blecktech.com/myemail.gif'>

                                  Comment


                                    #18
                                    Can you post what you have for centering???

                                    Aside from that, I believe the attached might be what you are looking for (I am still buggered how Magui feed themselves and run off into the sprinklers after midnight) but the attached should show how you can determine if your app (or dll) is the parent, or "Child" as in your app is a Dll loaded into another "Parent" app



                                    Let me know if this is along the lines of what you were trying. (still a work of progress...or a rework actually) so just for demo purposes.

                                    If Dll...then you see you as a "Child" of the "Parent" exe, if a EXE then you ARE the "Parent" so results are the same...

                                    No idea (yet) how to tell if YOU are spawned from another process but I believe you meant ("Am I part of another program???" sort of results???)

                                    Attached Files
                                    Engineer's Motto: If it aint broke take it apart and fix it

                                    "If at 1st you don't succeed... call it version 1.0"

                                    "Half of Programming is coding"....."The other 90% is DEBUGGING"

                                    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                                    Comment


                                      #19
                                      I will take a look on Friday (not near my dev machine)

                                      But in my case it is NOT part of another program (ie DLL called by an EXE) it is a shelled programed created by me call by a 3rd party program that can spawn something else (exe, bat, etc.).

                                      I can pass static command line parameters (switches etc.) to my program, but not dynamic stuff like window handles, etc.
                                      <b>George W. Bleck</b>
                                      <img src='http://www.blecktech.com/myemail.gif'>

                                      Comment


                                        #20
                                        >Can you post what you have for centering???
                                        This is close.
                                        Code:
                                        LOCAL rdw AS RECT, rDLG AS RECT 
                                        
                                                       GetClientRect hWndParent, Rdw
                                                       GetWindowRect hDlg, rDlg
                                                       SetWindowPos hDlg,_
                                                                    %HWND_TOP,_
                                                                   ((rDW.nright   - rDW.nleft + 1) - (rDlg.nright - rDlg.nleft +1)) \2, _
                                                                   ((rDw.nBottom  - rDW.nTop + 1) - (rDlg.nbottom - rDlg.nTop + 1)) \ 2, _
                                                                    %NULL, _
                                                                    %NULL, _
                                                                    %SWP_NOSIZE             ' zorder and location parameters are valid
                                        Michael Mattias
                                        Tal Systems (retired)
                                        Port Washington WI USA
                                        [email protected]
                                        http://www.talsystems.com

                                        Comment

                                        Working...
                                        X
                                        😀
                                        🥰
                                        🤢
                                        😎
                                        😡
                                        👍
                                        👎