Arsip: Simulasi ALT+TAB


by LuriDarmawan in Sistem more 18 years ago 1653
Jika rekan-2 ingin mensimulasikan fungsi ALT+TAB windows dengan melakukan penekanan suatu tombol dari program sendiri, kode berikut amat sanget berguna.
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;
Syntax Highlighted with https://pascal-id.org/syntax



ref: http://www.swissdelphicenter.ch/torry/showcode.php?id=2103
Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com