🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #17219

Re: ShellExecute

#17219
From: Ed Mulroy [TeamB]
Date: Thu, 03 Apr 2003 15:47
52 lines
2103 bytes
You could do FindWindow for   filename - Notepad  and hope.

To get it without assuming anything, use the instance handle returned by
ShellExecute do an EnumWindows and for each HWND received compare the handle
to GetWindowLong(hwnd, GWL_HINSTANCE).


-----------------------
struct HwndInfo
  {
  HINSTANCE hinst;
  HWND hwnd;
  };

BOOL CALLBACK MyEnumProc)
    HWND hwnd, LPARAM lp)
  {
  HwndInfo *hi_ptr = (HwndInfo *) lp;

  if (GetWindowLong(hwnd, GWL_HINSTANCE) ==
     hi_ptr->hinst)
      {
      hi_ptr->hwnd = hwnd;
      return FALSE;
      }

  return TRUE;
  }
-----------------------

and in your code which looks up the window handle:

-----------------------
  HwndInfo hi = { 0 };

  EnumWindows(MyEnumProc, (LPARAM) &hi);
-----------------------

after which hi.hwnd will either be NULL if Notepad did not start or the HWND
of the Notepad window.

.  Ed

> RaynorPao wrote in message
>  news:3e8c0ea4@newsgroups.borland.com...
>
> I can use API ShellExecute to execute notepad.
>
> ShellExecute(handle, "open", "test.txt", NULL,
> NULL, SW_SHOWNORMAL);
>
> But, how can I get the HWND of this notepad?
Technical Details
Message-ID: <3e8c5793$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3e8c0ea4@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,bff1fa0e8e8777f2
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-04-03 07:53:09 PST
From: "Ed Mulroy [TeamB]" <ed@mulroy.org>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3e8c0ea4@newsgroups.borland.com>
Subject: Re: ShellExecute
Date: Thu, 3 Apr 2003 10:47:28 -0500
Lines: 54
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 24.74.175.102
Message-ID: <3e8c5793$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1049384851 24.74.175.102 (3 Apr 2003 07:47:31 -0800)
X-Authenticated-User: edmulroy
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail