🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: ShellExecute

#17220
From: RaynorPao
Date: Thu, 03 Apr 2003 16:30
86 lines
2997 bytes
Hi Ed:

Thanks for your reply.
My code is as below:

HWND ghwnd;
BOOL CALLBACK MyEnumWndProc(HWND hWnd, LPARAM lParam);

BOOL CALLBACK MyEnumWndProc(HWND hWnd, LPARAM lParam)
{
   HINSTANCE hInst=(HINSTANCE)lParam;
   HINSTANCE hGetInst=(HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE);
   if(hInst==hGetInst)
   {
      ghwnd=hWnd;
      return FALSE;
   }
   return TRUE;
}

void __fastcall TForm1::Button3Click(TObject *Sender)
{
   HINSTANCE hinst=ShellExecute(NULL, "open", "test.txt", NULL, NULL,
SW_SHOWNORMAL);
   if(!EnumWindows((WNDENUMPROC)MyEnumWndProc, (LPARAM)hinst))
   {
      // It didn't execute to this block.
      char szCaption[256]={0};
      GetWindowText(ghwnd, szCaption, 256);
      ShowMessage(szCaption);
   }
}

But, it still can't find the window which is created with ShellExecute.
Is there something wrong what I do? Please help me.

Thanks.
RaynorPao.


"Ed Mulroy [TeamB]" <ed@mulroy.org> ���g��l��
news:3e8c5793$1@newsgroups.borland.com...
> 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
Technical Details
Message-ID: <3e8c5dce@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!newshosting.com!news-xfer2.atl.newshosting.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3e8c0ea4@newsgroups.borland.com> <3e8c5793$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 10cc67,bff1fa0e8e8777f2
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-04-03 08:18:15 PST
From: "RaynorPao" <RaynorPao.nospam@nospam.pchome.com.tw>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3e8c0ea4@newsgroups.borland.com> <3e8c5793$1@newsgroups.borland.com>
Subject: Re: ShellExecute
Date: Fri, 4 Apr 2003 00:30:28 +0800
Lines: 89
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4807.1700
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
NNTP-Posting-Host: 61.221.176.28
Message-ID: <3e8c5dce@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1049386446 61.221.176.28 (3 Apr 2003 08:14:06 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!newshosting.com!news-xfer2.atl.newshosting.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail