Article View: borland.public.cppbuilder.nativeapi
Article #3517Re: I Can't call this function more than once?
From: Jeff
Date: Wed, 07 Jun 2006 16:52
Date: Wed, 07 Jun 2006 16:52
46 lines
2360 bytes
2360 bytes
Awesome, thanks, I didn't realize that.
"Boba" <Boba@somewhere.world> wrote in message
news:448701e9@newsgroups.borland.com...
> "Jeff" <Jeff@nospam.com> wrote in message
> news:4486fe87$1@newsgroups.borland.com...
>> I've build a function that returns the handle to a window who's
> caption
>> starts with the String passed to it (see code below). The problem I'm
>> having is that when I call it a second time, say in a loop, it throws
> an
>> EAccessViolation. Any thoughts?
>>
>> HWND TfrmMain::FindWindowLike(String strWinText)
>> {
>> HWND hWindow; //Window handle
>> char *ptr_chrTitle = ""; //Window title
>>
>
> how much memory you think you have pointed by ptr_chrTitle?
>
>> hWindow = FindWindow(NULL, NULL); //Start with the first window
>>
>> do
>> {
>> SendMessage(hWindow, WM_GETTEXT, GetWindowTextLength(hWindow) + 1,
>> (LPARAM)ptr_chrTitle); //Get the window's caption
>
> make sure you don't exceed the memory size pointed by ptr_chrTitle.
>
>> if (static_cast<String>(ptr_chrTitle).Pos(strWinText) == 1)
> //Matches!
>> "Visual SourceSafe Explorer --..."
>> return hWindow; //Return the handle
>> else
>> hWindow = GetNextWindow(hWindow, GW_HWNDNEXT); //Get the handle to
> the
>> next window
>> } while (hWindow != NULL); //Search until we run out of windows
>>
>> return hWindow; //Return the handle
>> }
>>
>>
>
>
Technical Details
Message-ID:
<44870465$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4486fe87$1@newsgroups.borland.com> <448701e9@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,5a83417f22065f8d X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Jeff" <Jeff@nospam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <4486fe87$1@newsgroups.borland.com> <448701e9@newsgroups.borland.com> Subject: Re: I Can't call this function more than once? Date: Wed, 7 Jun 2006 10:52:54 -0600 Lines: 48 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2869 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 NNTP-Posting-Host: 198.68.195.241 Message-ID: <44870465$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1149699173 198.68.195.241 (7 Jun 2006 09:52:53 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail