Announcement

Collapse
No announcement yet.

Instance Parent

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

  • John Montenigro
    replied
    From the deep dark shadows of DOS...

    I have not explored this topic for a number of years, so I don't know how recent versions of Windows handles it now, BUT, back in the days of DOS, a "child" program would inherit its "environment" from the caller. It was possible for the parent to set an environment variable such that the child could check it and obtain what you are calling "instance" information.

    I know that the command.com structures no longer operate literally in the same way, but I believe I read somewhere in the MSDN that the passing of environment values had been carried over through some new mechanism...

    If this still holds true, then you could invoke the parent application from a .BAT file (yes, they still work) in which you set the value of an environment variable. Then when it calls your app, you can check that variable.

    Honestly, I don't have the time right now to track this down to either verify or reject it, so please take it as a "possible" answer that would require more research.

    Leave a comment:


  • Cliff Nichols
    replied
    If wanting to detect if your program was started by commandline, or shelled from a program, or from a shortcut, or other, I am fairly sure you can not detect that from your exe.

    I tried each of those while watching "SysInternals - Process Explorer" and all copies appeared under "Explorer.exe" (All with the exception of "ShellExecute" which the program appeared under its own process

    Leave a comment:


  • Michael Mattias
    replied
    >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

    Leave a comment:


  • George Bleck
    replied
    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.

    Leave a comment:


  • Cliff Nichols
    replied
    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

    Leave a comment:


  • George Bleck
    replied
    http://www.powerbasic.com/support/pb...t.php?p=171800

    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.

    Leave a comment:


  • Cliff Nichols
    replied
    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

    Leave a comment:


  • Michael Mattias
    replied
    >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.

    Leave a comment:


  • colin glenn
    replied
    What about GetParent? Have you looked to see if windows will return the "parent" of the program?

    Leave a comment:


  • George Bleck
    replied
    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.

    Leave a comment:


  • Dominic Mitchell
    replied
    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.

    Leave a comment:


  • George Bleck
    replied
    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.

    Leave a comment:


  • Michael Mattias
    replied
    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.

    Leave a comment:


  • Michael Mattias
    replied
    Then again, maybe you could just OpenProcess() of the owner process and get the command line used?

    Maybe that would tell you something.

    Leave a comment:


  • Michael Mattias
    replied
    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.

    Leave a comment:


  • George Bleck
    replied
    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.

    Leave a comment:


  • Michael Mattias
    replied
    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

    Leave a comment:


  • George Bleck
    replied
    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.

    Leave a comment:


  • Michael Mattias
    replied
    May we assume this is a non-cooperating application?

    Leave a comment:


  • George Bleck
    replied
    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.

    Leave a comment:

Working...
X