Mega Code Archive

 
Categories / Delphi / Examples
 

How to simulate ALT + TAB

Title: How to simulate ALT + TAB 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; Usage Examples: 1.Simulate ALT + TAB procedure Forwardtab; var hWnd: DWORD; begin Refresh; if Index .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; Usage Examples: 2.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;