🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages Started by Tom Thu, 06 Apr 2006 15:46
which app is curently having focus
#3946
Author: Tom
Date: Thu, 06 Apr 2006 15:46
21 lines
1571 bytes
I use the following code to determine the processes that are running, 
but how can I find out which application has the focus (in which 
application user is currently working)

  ListBox1->Items->Clear();
  HANDLE snapshot;
  PROCESSENTRY32 processinfo;
  processinfo.dwSize = sizeof(processinfo);
  snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
  if (snapshot == NULL)
   return;
  bool status = Process32First(snapshot, &processinfo);
  while(status)
   {
   ListBox1->Items->Add(processinfo.szExeFile);
   status = Process32Next(snapshot, &processinfo);
   }
  Form1->Caption = IntToStr(ListBox1->Items->Count);

thanks in advance
tom
Re: which app is curently having focus
#3947
Author: Ed Mulroy
Date: Thu, 06 Apr 2006 16:06
26 lines
1887 bytes
The window with which the user is currently working can be found with the 
Windows API function GetForegroundWindow.  You might then use the returned 
HWND in a call to GetWindowProcessId.

.  Ed

> Tom wrote in message
> news:443537a4$1@newsgroups.borland.com...
>I use the following code to determine the processes that are running, but 
>how can I find out which application has the focus (in which application 
>user is currently working)
>
>  ListBox1->Items->Clear();
>  HANDLE snapshot;
>  PROCESSENTRY32 processinfo;
>  processinfo.dwSize = sizeof(processinfo);
>  snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
>  if (snapshot == NULL)
>   return;
>  bool status = Process32First(snapshot, &processinfo);
>  while(status)
>   {
>   ListBox1->Items->Add(processinfo.szExeFile);
>   status = Process32Next(snapshot, &processinfo);
>   }
>  Form1->Caption = IntToStr(ListBox1->Items->Count);
Re: which app is curently having focus
#3955
Author: Tom
Date: Fri, 07 Apr 2006 11:06
33 lines
1986 bytes
thanks, it works.


"Ed Mulroy" <dont_email_me@bitbuc.ket> wrote in message
news:44353c9a$1@newsgroups.borland.com...
> The window with which the user is currently working can be found with the
> Windows API function GetForegroundWindow.  You might then use the returned
> HWND in a call to GetWindowProcessId.
>
> .  Ed
>
> > Tom wrote in message
> > news:443537a4$1@newsgroups.borland.com...
> >I use the following code to determine the processes that are running, but
> >how can I find out which application has the focus (in which application
> >user is currently working)
> >
> >  ListBox1->Items->Clear();
> >  HANDLE snapshot;
> >  PROCESSENTRY32 processinfo;
> >  processinfo.dwSize = sizeof(processinfo);
> >  snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
> >  if (snapshot == NULL)
> >   return;
> >  bool status = Process32First(snapshot, &processinfo);
> >  while(status)
> >   {
> >   ListBox1->Items->Add(processinfo.szExeFile);
> >   status = Process32Next(snapshot, &processinfo);
> >   }
> >  Form1->Caption = IntToStr(ListBox1->Items->Count);
>
>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads