Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > API de Windows
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 05-01-2020
MaxiDucoli MaxiDucoli is offline
Miembro
 
Registrado: feb 2006
Posts: 134
Poder: 19
MaxiDucoli Va por buen camino
Optimizar código

Hola, buenas tardes.
Aprovecho que hay un gurú que sabe bocha de WinApi y quería preguntar lo siguiente:

Tengo este código insertado en un Timer dentro de un formulario que se ejecuta como "Loading Screen" mientras se carga un emulador de fondo.
Una vez que abrió el emulador el código busca el Caption del mismo y lo trae al frente y luego se cierra.
Hay alguna manera de optimizar el código este o sí o sí se tiene que hacer de una manera como esta?

Se pueden buscar los exe en ejecución y terminarlos directamente? Eso sería de mucha ayuda para el programa principal así puedo cerrar los emuladores al presionar ESCAPE (que ya me solucionaron como hacerlo, pero lo hago algo "Sucio" y a veces falla).

Les dejo el código y muchas gracias de ante mano!!!!


Código Delphi [-]
unit close;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, jpeg, pngimage, Vcl.Forms,TLHelp32, Vcl.Dialogs, JvBackgrounds, Vcl.ExtCtrls;

type
  TFrmLaunchIMG = class(TForm)
    JvBackground1: TJvBackground;
    TmrClose: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure TmrCloseTimer(Sender: TObject);

  private
    { Private declarations }

  public
    { Public declarations }
  end;

var
  FrmLaunchIMG: TFrmLaunchIMG;
  Contador : integer;
  Win2 : HWND;
  Mensaje : String;

implementation

{$R *.dfm}



function FindWindowExtd(partialTitle: string): HWND;
var
  hWndTemp: hWnd;
  iLenText: Integer;
  cTitletemp: array [0..254] of Char;
  sTitleTemp: string;
begin
  hWndTemp := FindWindow(nil, nil);
  while hWndTemp <> 0 do begin
    iLenText := GetWindowText(hWndTemp, cTitletemp, 255);
    sTitleTemp := cTitletemp;
    sTitleTemp := UpperCase(copy( sTitleTemp, 1, iLenText));
    partialTitle := UpperCase(partialTitle);
    if pos( partialTitle, sTitleTemp ) <> 0 then
      Break;
    hWndTemp := GetWindow(hWndTemp, GW_HWNDNEXT);
  end;
  result := hWndTemp;
end;

procedure TFrmLaunchIMG.FormCreate(Sender: TObject);
begin
FrmLaunchIMG.Height := Screen.Height;
FrmLaunchIMG.Width := Screen.Width;
JVBackGround1.Image.Picture.LoadFromFile(ParamStr(1));
Contador := 0;
end;

procedure TFrmLaunchIMG.TmrCloseTimer(Sender: TObject);
begin
SetWindowPos(FrmLaunchIMG.Handle, HWND_TOPMOST, 0, 0, 0, 0,
                 SWP_NoMove or SWP_NoSize);
 inc(Contador);

 if Contador > 5 then Contador := 0;


      if Contador = 5 then
      Begin

            Win2 :=  FindWindowExtd('RetroArch');
            if IsWindow(Win2) then
            begin
                Sleep(200);
                //SetForegroundWindow(Win2);
                SetWindowPos(Win2, HWND_TOPMOST, 0, 0, 0, 0,
                SWP_NoMove or SWP_NoSize);
                application.Terminate;
            end;

            Win2 :=  FindWindowExtd('PPSSPP ');
            if IsWindow(Win2) then
            begin
                Sleep(200);
                //SetForegroundWindow(Win2);
                SetWindowPos(Win2, HWND_TOPMOST, 0, 0, 0, 0,
                SWP_NoMove or SWP_NoSize);
                application.Terminate;
            end;

            Win2 :=  FindWindowExtd('Slot');
            if IsWindow(Win2) then
            begin
                Sleep(200);
                //SetForegroundWindow(Win2);
                SetWindowPos(Win2, HWND_TOPMOST, 0, 0, 0, 0,
                SWP_NoMove or SWP_NoSize);
                application.Terminate;
            end;

            Win2 :=  FindWindowExtd('Cemu');
            if IsWindow(Win2) then
            begin
                Sleep(200);
                //SetForegroundWindow(Win2);
                SetWindowPos(Win2, HWND_TOPMOST, 0, 0, 0, 0,
                SWP_NoMove or SWP_NoSize);
                application.Terminate;
            end;

            Win2 :=  FindWindowExtd('Redream');
            if IsWindow(Win2) then
            begin
                Sleep(200);
                //SetForegroundWindow(Win2);
                SetWindowPos(Win2, HWND_TOPMOST, 0, 0, 0, 0,
                SWP_NoMove or SWP_NoSize);
                application.Terminate;
            end;

            Win2 :=  FindWindowExtd('FS-UAE');
            if IsWindow(Win2) then
            begin
                Sleep(200);
                //SetForegroundWindow(Win2);
                SetWindowPos(Win2, HWND_TOPMOST, 0, 0, 0, 0,
                SWP_NoMove or SWP_NoSize);
                application.Terminate;
            end;

            Win2 :=  FindWindowExtd('Future');
            if IsWindow(Win2) then
            begin
                Sleep(200);
                //SetForegroundWindow(Win2);
                SetWindowPos(Win2, HWND_TOPMOST, 0, 0, 0, 0,
                SWP_NoMove or SWP_NoSize);
                application.Terminate;
            end;

            Win2 :=  FindWindowExtd('MAME');
            if IsWindow(Win2) then
            begin
                Sleep(200);
                //SetForegroundWindow(Win2);
                SetWindowPos(Win2, HWND_TOPMOST, 0, 0, 0, 0,
                SWP_NoMove or SWP_NoSize);
                application.Terminate;
            end;

            Win2 :=  FindWindowExtd('scummvm');
            if IsWindow(Win2) then
            begin
                Sleep(200);
                //SetForegroundWindow(Win2);
                SetWindowPos(Win2, HWND_TOPMOST, 0, 0, 0, 0,
                SWP_NoMove or SWP_NoSize);
                application.Terminate;
            end;

            Win2 :=  FindWindowExtd('Dolphin');
            if IsWindow(Win2) then
            begin
                Sleep(200);
                //SetForegroundWindow(Win2);
                SetWindowPos(Win2, HWND_TOPMOST, 0, 0, 0, 0,
                SWP_NoMove or SWP_NoSize);
                application.Terminate;
            end;

            Win2 :=  FindWindowExtd('WINGAMES');
            if IsWindow(Win2) then
            begin
                Sleep(200);
                //SetForegroundWindow(Win2);
                SetWindowPos(Win2, HWND_TOPMOST, 0, 0, 0, 0,
                SWP_NoMove or SWP_NoSize);
                application.Terminate;
            end;

            Win2 :=  FindWindowExtd('DAPHNE');
            if IsWindow(Win2) then
            begin
                Sleep(200);
                //SetForegroundWindow(Win2);
                SetWindowPos(Win2, HWND_TOPMOST, 0, 0, 0, 0,
                SWP_NoMove or SWP_NoSize);
                application.Terminate;
            end;
      End;
end;



end.
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Optimizar codigo n03l Varios 3 28-11-2013 21:07:11
optimizar el codigo en menos lineas darkbits Varios 5 19-07-2013 13:32:40
Ayuda como Optimizar Código JerS OOP 3 24-06-2011 05:59:44
optimizar codigo acrophet Varios 5 16-01-2011 23:28:39
Optimizar el sgte codigo BlueSteel Varios 9 14-08-2007 22:33:24


La franja horaria es GMT +2. Ahora son las 17:30:39.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi