Ver Mensaje Individual
  #4  
Antiguo 10-04-2017
Avatar de escafandra
[escafandra] escafandra is offline
Miembro Premium
 
Registrado: nov 2007
Posts: 2.197
Reputación: 20
escafandra Tiene un aura espectacularescafandra Tiene un aura espectacular
El siguiente código usa un Timer para encontrar la ventana activa, si se trata del notepad se colocará el formulario sobre él:

Código Delphi [-]
function GetExeNameByWnd(Wnd: HWND): String;
var
  snp: THANDLE;
  lppe: TPROCESSENTRY32;
  dwProcessId: DWORD;
begin
  Result:= '';
  GetWindowThreadProcessId(Wnd, dwProcessId);
  snp:= CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  try
  begin
    lppe.dwSize:= sizeof(lppe);
    if Process32First(snp, lppe) then
      repeat
        if lppe.th32ProcessID = dwProcessId then
        begin
           Result:= AnsiString(lppe.szExeFile);
           break;
        end;
      until not Process32Next(snp, lppe);
  end;
  finally
     CloseHandle(snp);
  end;
end;


procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Label1.Caption:= 'Me pongo sobre el notepad';
  if GetExeNameByWnd(GetForegroundWindow) = 'notepad.exe' then
  begin
    Application.Restore();
    SetWindowPos(Handle, HWND_TOPMOST,0,0,0,0, SWP_NOSIZE or SWP_NOMOVE);
  end;
end;


Saludos.
Responder Con Cita