unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,
windows;
type
{ TForm1 }
TForm1 = class(TForm)
CheckBox1: TCheckBox;
CheckGroup1: TCheckGroup;
Memo1: TMemo;
Timer1: TTimer;
procedure CheckGroup1ItemClick(Sender: TObject; Index: integer);
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
procedure FormCreate(Sender: TObject);
procedure FormDeactivate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormWindowStateChange(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
public
end;
const
LSFW_LOCK = 1;
LSFW_UNLOCK = 2;
var
Form1: TForm1;
function LockSetForegroundWindow(LSFW_UNLOCK:UINT):WINBOOL; external 'user32' name 'LockSetForegroundWindow';
implementation
{$R *.lfm}
{ TForm1 }
procedure ActivateForm(Handle: HWND);
var
dwCurrentThread: DWORD;
dwFGThread: DWORD;
begin
dwCurrentThread := GetCurrentThreadId();
dwFGThread := GetWindowThreadProcessId(GetForegroundWindow(), NIL);
AttachThreadInput(dwCurrentThread, dwFGThread, TRUE);
// Possible actions you may wan to bring the window into focus.
{SetForegroundWindow(handle);
LockSetForegroundWindow(1); }
if SetForegroundWindow(handle) then
begin
form1.memo1.lines.add('FormActivate-SetForegroundWindow funcionó');
if LockSetForegroundWindow(LSFW_LOCK) then
form1.memo1.lines.add('FormActivate-LockSetForegroundWindow funcionó')
else
form1.memo1.lines.add('FormActivate-LockSetForegroundWindow no funcionó ' + inttostr(getlasterror));
end
else
begin
form1.memo1.lines.add('FormActivate-SetForegroundWindow falló')
end;
//SetCapture(handle);
//Sets the mouse capture to the specified window belonging to the current thread
//SetFocus(handle);
//Sets the keyboard focus to the specified window
//SetActiveWindow(handle);
//Activates a window. The window must be attached to the calling thread's message queue.
EnableWindow(handle, TRUE);
//Enables or disables mouse and keyboard input to the specified window or control.
AttachThreadInput(dwCurrentThread, dwFGThread, FALSE);
{$IfDef WINDOWS}
{if SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_SHOWWINDOW) then
form1.memo1.lines.add('SetWindowsPos funcionó')
else
form1.memo1.lines.add('SetWindowsPos no funcionó') ;
form1.formactivate(form1); }
{$else}
#todo
{$EndIf}
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
end;
procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
LockSetForegroundWindow(2);
end;
procedure TForm1.CheckGroup1ItemClick(Sender: TObject; Index: integer);
begin
case index of
9: begin
Application.terminate;
end;
0..8: begin
inputbox('Opción ' + IntToSTR(index+1), 'cantidad de opción '+ intToStr(index+1),'1');
end;
end;
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnDeactivate:=@FormDeactivate;
Application.OnMinimize:=@FormDeactivate;
end;
procedure TForm1.FormDeactivate(Sender: TObject);
begin
if WindowState=wsMinimized then WindowState:=wsNormal;
memo1.lines.add('FormDeactivate-se desactivo');
ActivateForm(application.Handle);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
LockSetForegroundWindow(2);
end;
procedure TForm1.FormWindowStateChange(Sender: TObject);
begin
end;
procedure TForm1.Timer1Timer(Sender: TObject);
Var
hh: Handle;
begin
checkbox1.checked:= not checkbox1.checked;
end;
end.