任务栏,任务管理器,应用程序列表,进程列表
function GetText ( Wnd : HWND ): string ;
var
textlength : integer ;
text : PChar ;
begin
textlength := SendMessage ( Wnd , WM_GETTEXTLENGTH , 0 , 0 );
if textlength = 0 then
Result := ''
else
begin
getmem ( text , textlength + 1 );
SendMessage ( Wnd , WM_GETTEXT , textlength + 1 , Integer ( text ));
Result := text ;
freemem ( text );
end ;
end ;
function EnumWindowsProc ( Wnd : HWND ; LParam : LPARAM ): BOOL ; stdcall ;
begin
Result := True ;
if ( IsWindowVisible ( Wnd ) or IsIconic ( wnd )) and
(( GetWindowLong ( Wnd , GWL_HWNDPARENT ) = 0 ) or
( GetWindowLong ( Wnd , GWL_HWNDPARENT ) = GetDesktopWindow )) and
( GetWindowLong ( Wnd , GWL_EXSTYLE ) and WS_EX_TOOLWINDOW = 0 ) then
Form1 . Listbox1 . items . add ( 'Handle: ' + Inttostr ( Wnd ) + ',Text: ' + GetText ( Wnd ));
end ;
procedure TForm1 . Button1Click ( Sender : TObject );
var
Param : Longint ;
begin
EnumWindows (@ EnumWindowsProc , Param );
end ;
---------------------------------------
模拟Alt + Tab的切换
{ Wenn man die ALT + TAB Funktion von Windows über einen Button des eigenen
Programms realisieren mreicht es nicht aus, einfach nur das Drücken
der Tasten ALT + TAB zu simulieren, weil bei jedem Klick auf den eigenen
Button, das eigene Programm den Fokus erhund an den Anfang der List
gestellt wird.
Deshalb muss man sich alle aktiven Programm "merken" und selber ihnen selber
per Liste den Fokus geben. }
{ If you want to simulate the ALT + TAB function of windows, by clicking a
button of your own program, you cant only simulate to press the ALT and TAB
keys, because in the moment, when you click on your button, your program will
get the focus and will be set at the beginning of the List. Because of this
you have to remember all the active programs and to give them the focus by your
own list. }
var
Index: INTEGER;
// Save description of all active windows to listbox
function EnumWindowsProc(Wnd: HWND; lParam: lParam): BOOL; stdcall;
var
Bezeichnung: array[0..200] of Char;
begin
if (IsWindowVisible(Wnd) or IsIconic(wnd)) and
((GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) or
(GetWindowLong(Wnd, GWL_HWNDPARENT) = GetDesktopWindow)) and
(GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0) then
begin
GetWindowText(Wnd, Bezeichnung, 256);
if Bezeichnung <> 'GDI+ Window' then
Form1.Listbox1.Items.Append(Bezeichnung);
end;
end;
procedure TForm1.Refresh;
begin
Listbox1.Clear;
EnumWindows(@EnumWindowsProc, 1);
end;
// Simulate ALT + TAB
procedure Forwardtab;
var
hWnd: DWORD;
begin
Refresh;
if Index < Listbox1.Count - 1 then
Inc(Index)
else
Index := 0;
hWnd := FindWindow(nil, PChar(Listbox1.Items[Index]));
if hWnd <> 0 then
begin
windows.ShowWindow(hwnd, 1);
windows.SetForegroundWindow(hWnd);
windows.SetFocus(hWnd);
end;
end;
// Simulate ALT + TAB (Backwards)
procedure Backwardtab;
var
hWnd: DWORD;
begin
Refresh;
if Index > 0 then
Dec(Index)
else
Index := listbox1.Count - 1;
hWnd := FindWindow(nil, PChar(Listbox1.Items[Index]));
if hWnd <> 0 then
begin
windows.ShowWindow(hwnd, 1);
windows.SetForegroundWindow(hWnd);
windows.SetFocus(hWnd);
end;
end;