Announcement

Collapse
No announcement yet.

Fensterhandle einer gestarteten Anwendung

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

  • Fensterhandle einer gestarteten Anwendung

    Hallo!

    Ich habe folgendes Problem:<br>
    Ich starte aus meiner Anwendung heraus mit Hilfe von ShellExecute ein anderes Programm. Das andere Programm soll dann nach einer gewissen Zeit wieder geschlossen werden, doch dafür bräuchte ich das Fensterhandle. ShellExecute liefert jedoch nur "Instance Handle HINSTANCE" mit dem ich nichts anfangen kann. Gibt es eine möglichkeit daraus das Fensterhandle zu ermitteln? Mit FindWindow kann ich nicht arbeiten, da ich weder die Fensterklasse noch den Fenstertitel zur Laufzeit kenne.

    Danke im Voraus!

    Patrick

  • #2
    Hallo,

    in diesem Fall würde ich auf die API-Funktion <b>ShellExecuteEx</b> ausweichen, denn dort steht über die SHELLEXECUTEINFO-Datenstruktur im Feld <b>hwnd</b> das Fensterhandle der gestarteten Anwendung zur Verfügung. Im Platform-SDK liest sich das so:

    <pre>
    Parameters
    lpExecInfo = Address of a SHELLEXECUTEINFO structure that
    contains and receives information about the
    application being executed.
    </pre>
    Die Struktur sie folgendermassen aus:
    <pre>
    typedef struct _SHELLEXECUTEINFO{
    DWORD cbSize;
    ULONG fMask;
    HWND hwnd;
    LPCTSTR lpVerb;
    LPCTSTR lpFile;
    LPCTSTR lpParameters;
    LPCTSTR lpDirectory;
    int nShow;
    HINSTANCE hInstApp;

    // Optional members
    LPVOID lpIDList;
    LPCSTR lpClass;
    HKEY hkeyClass;
    DWORD dwHotKey;
    union {
    HANDLE hIcon;
    HANDLE hMonitor;
    };
    HANDLE hProcess;
    } SHELLEXECUTEINFO, *LPSHELLEXECUTEINFO;
    </pre>
    hwnd = <i>Window handle to any message boxes that the system may produce while executing this function.</i&gt

    Comment


    • #3
      Hallo Andreas,
      so geht's leder nicht!
      Denn

      Specifies an enumerated type that defines flags used with the IShellFolder::EnumObjects method.

      The SHELLEXECUTEINFO structure contains information used by the ShellExecuteEx function.

      typedef struct _SHELLEXECUTEINFO { // sei
      DWORD cbSize;
      ULONG fMask;
      HWND hwnd;
      LPCSTR lpVerb;
      LPCSTR lpFile;
      LPCSTR lpParameters;
      LPCSTR lpDirectory;
      int nShow;
      HINSTANCE hInstApp;

      // Optional members
      LPVOID lpIDList;
      LPCSTR lpClass;
      HKEY hkeyClass;
      DWORD dwHotKey;
      HANDLE hIcon;
      HANDLE hProcess;
      } SHELLEXECUTEINFO, FAR *LPSHELLEXECUTEINFO;



      Members

      cbSize

      Specifies the size, in bytes, of the structure.

      fMask

      This is an array of flags that indicate the content and validity of the other structure members. You can specify a combination of the following values:

      Value Meaning
      SEE_MASK_CLASSKEY Use the class key given by the hkeyClass member.
      SEE_MASK_CLASSNAME Use the class name given by the lpClass member.
      SEE_MASK_CONNECTNETDRV The lpFile member is a Universal Naming Convention (UNC) path of a file on a network. Validate the share and connect to a drive letter.
      SEE_MASK_DOENVSUBST Expand any environment variables specified in the string given by the lpDirectory or lpFile member.
      SEE_MASK_FLAG_DDEWAIT Wait for the DDE conversation to terminate before returning, if the ShellExecuteEx function causes a DDE conversation to start.
      SEE_MASK_FLAG_NO_UI Do not display an error message box if an error occurs.
      SEE_MASK_HOTKEY Use the hot key given by the dwHotKey member.
      SEE_MASK_ICON Use the icon given by the hIcon member.
      SEE_MASK_IDLIST Use the item identifier list given by the lpIDList member.
      SEE_MASK_INVOKEIDLIST Use the item identifier list given by the lpIDList member to invoke an application. If this member is NULL, the function creates an item identifier list and invokes the application. SEE_MASK_INVOKEIDLIST overrides SEE_MASK_IDLIST.
      SEE_MASK_NOCLOSEPROCESS Leave the process running after the ShellExecuteEx function exits. The hProcess member receives the handle of the process.


      hwnd

      Handle to the parent window for any message boxes that the system may produce while executing this function (for example, for error reporting).

      lpVerb

      Pointer to a string specifying the name of a verb. The verb specifies an action for the application to perform. This member defaults to "Open" if no verb is specified.

      ....

      Wie also zu sehen ist, bestimmt HWND das Handle des parent window!!!

      ??? Wo bekomme ich denn nun aber das Fenster-Handle der gestarteten Anwendung her???

      Helmut, [email protected]

      Comment

      Working...
      X