Thread View: borland.public.cppbuilder.nativeapi
2 messages
2 total messages
Started by Patryk B.
Tue, 16 Oct 2007 13:37
Enumerating windows like ALT+TAB
Author: Patryk B.
Date: Tue, 16 Oct 2007 13:37
Date: Tue, 16 Oct 2007 13:37
35 lines
1854 bytes
1854 bytes
Im trying to enumerate windows that show when press alt+tab.
I have code:
void __fastcall TForm6::Button1Click(TObject *Sender)
{
ListView1->Items->Clear();
EnumDesktopWindows(NULL,(WNDENUMPROC)EnumWindowsProc,(LPARAM)ListView1);
}
//---------------------------------------------------------------------------
bool CALLBACK EnumWindowsProc(HWND hWnd, TListView *ListView)
{
char WindowName[80], ClassName[80];
GetWindowText(hWnd, WindowName, 80);
if(IsWindowVisible(hWnd) && AnsiString(WindowName).Length()!=0)
{
ListView->Items->Add();
int i=ListView->Items->Count-1;
ListView->Items->Item[i]->Caption=AnsiString(WindowName);
ListView->Items->Item[i]->Update();
}
return true;
}
But it show more window than alt+tab, and it will not work for all windows
i think.
Anyone know how to do it?
Thanks,
Patryk.
Re: Enumerating windows like ALT+TAB
Author: Remy Lebeau (TeamB)
Date: Tue, 16 Oct 2007 16:52
Date: Tue, 16 Oct 2007 16:52
52 lines
2564 bytes
2564 bytes
"Patryk B." <pbobak@no.spam.o2.pl> wrote in message
news:op.t0algg2iwzezly@dune.intranet...
> EnumDesktopWindows(NULL,(WNDENUMPROC)EnumWindowsProc,(LPARAM)ListView1);
Since you are not specifying anything for the HDESK parameter, use
EnumWindows() instead.
> ListView->Items->Add();
> int i=ListView->Items->Count-1;
> ListView->Items->Item[i]->Caption=AnsiString(WindowName);
> ListView->Items->Item[i]->Update();
Rather than indexing into the Items[] property over and over, use the
TListItem that Add() returns instead:
TListItem *Item = ListView->Items->Add();
Item->Caption=AnsiString(WindowName);
Item->Update();
> But it show more window than alt+tab
That is because you are not doing any kind of filtering of the windows. Not
all windows appear in the Alt+Tab dialog, but you are not checking for the
same kind of conditions that the dialog looks for.
Try this instead:
void __fastcall TForm6::Button1Click(TObject *Sender)
{
ListView1->Items->Clear();
EnumWindows((WNDENUMPROC)EnumWindowsProc, (LPARAM)ListView1);
}
bool CALLBACK EnumWindowsProc(HWND hWnd, TListView *ListView)
{
if( IsWindowVisible(hWnd) &&
(GetWindow(hWnd, GW_OWNER) == NULL) &&
((GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW) == 0) )
{
char WindowName[256] = {0};
GetWindowText(hWnd, WindowName, 255);
ListView->Items->Add()->Caption = WindowName;
}
return TRUE;
}
Gambit
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