Article View: borland.public.cppbuilder.nativeapi
Article #1942Re: EnumWindows etc.
From: Matthew
Date: Sat, 09 Jun 2007 01:00
Date: Sat, 09 Jun 2007 01:00
97 lines
3552 bytes
3552 bytes
Bob Gonder wrote:
>How to differentiate what?
>You will only get windows.
>Are you asking how to know the name of the app that the windows
>belongs to?
Well - I'm using example code, and it does call EnumWindows,
But it lists all processes and all apps that are running. I
don't know why it does both. I am far from an API guy... I
usually do straight C++ code for crunching numbers (number
theory).
>More straight-forward way:
> DWORD Pid;
> GetWindowThreadProcessId(hWnd, &Pid);
>
>But I don't think I would bother with that, and go for
> char title[1024];
> GetWindowText( hWnd, title, 1023 );
>
I will look into this - excellent.
>Add the hWnd and text to a list (pointer to list passed in lparam)
>After the Enum, display and select from the list, use the associated
>hWnd to SetForegroundWindow( );
>> how do I select (code) within my program to maximize it?
>
> if( IsIconic( hWnd ) )
> { ShowWindow( hWnd, SW_RESTORE );
> }else{
> SetForegroundWindow( hWnd );
> };
This is excellent!!! Thank you very much.
>There should be no naked processes if you are using EnumWindows
Well there is - so, instead of a nice short list of running
windows (apps) there's about 40+ processes listed as well...
Here is the function that does the work:
bool __stdcall EnumProc(HWND hWnd,/*LPARAM*/long/*lp*/)
{
unsigned long* pPid; //LPDWORD
unsigned long result; //DWORD
void *hg; //HGLOBAL
unsigned long id;
if(hWnd==NULL)
return false;
hg = GlobalAlloc(GMEM_SHARE,sizeof(unsigned long));
pPid = (unsigned long *)GlobalLock(hg);
result = GetWindowThreadProcessId(hWnd,pPid);
// the pPid is what is
// also acquiring the
// procs ???
if(result){
char title[110];
char className[95];
char totalStr[256];
GetClassName(hWnd,className,95);
GetWindowText(hWnd,title,110);
id=*pPid;
ultoa(id,totalStr,10);
strcat(totalStr,"\t");
if(title){
strcat(totalStr,title);
strcat(totalStr,"\t");
}
strcat(totalStr,className);
FormMain->ListBox1->Items->Add((AnsiString)totalStr);
}
else{
GlobalUnlock(hg);
GlobalFree(hg);
return false;
}
GlobalUnlock(hg);
GlobalFree(hg);
return true;
}
Please note I working from example code. And I also hope I
haven't broken protocol by attaching that much code.
Bob - thanks for the help. I really appreciate you time.
Matthew.
Technical Details
Message-ID:
<4669fbaf$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4668d902$1@newsgroups.borland.com> <l2ri63pmm23tsci1u4subhitr6cchmm147@4ax.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,859e738ad5fa0eae X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Matthew" <atomkey@yahoo.com> Sender: "Matthew" <atomkey@yahoo.com> Reply-To: "Matthew" <atomkey@yahoo.com> Subject: Re: EnumWindows etc. Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 74.196.1.72 References: <4668d902$1@newsgroups.borland.com> <l2ri63pmm23tsci1u4subhitr6cchmm147@4ax.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <4669fbaf$1@newsgroups.borland.com> Date: 8 Jun 2007 18:00:31 -0700 X-Trace: newsgroups.borland.com 1181350831 207.105.83.66 (8 Jun 2007 18:00:31 -0700) Lines: 97 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail