Forçar abertura de janela já aberta no windows
Pessoal,
eu preciso saber como eu posso maximizar ou ativar um programa que já esteja aberto no windows?
por exemplo:
No clique de um botão, eu verifico se o programa IBExpert já está aberto no windows. Caso esteja aberto e eu não esteja nele, ele abre como se eu tivesse clicado nele na barra de tarefas.
eu preciso saber como eu posso maximizar ou ativar um programa que já esteja aberto no windows?
por exemplo:
No clique de um botão, eu verifico se o programa IBExpert já está aberto no windows. Caso esteja aberto e eu não esteja nele, ele abre como se eu tivesse clicado nele na barra de tarefas.
[vaza]
Curtidas 0
Respostas
Diegotiemann
15/05/2009
O trecho abaixo faz essa verificação ao iniciar o programa, basta você adaptar a sua necessidade:
{
MutexHandle := CreateMutex(nil, TRUE, ´Gestor RETTA :: Suínos´);
if MutexHandle <> 0 then
begin
if GetLastError = ERROR_ALREADY_EXISTS then
begin
application.MessageBox(´Gestor RETTA :: Suínos já está em execução em outra janela!´,´ Aviso´, MB_ICONQUESTION);
CloseHandle(MutexHandle);
hwind:=0;
repeat
hwind:=Windows.FindWindowEx(0,hwind,´TApplication´,´Gestor RETTA :: Suínos´);
until (hwind<>Application.Handle);
if (hwind<>0) then
begin
Windows.ShowWindow(hwind,SW_SHOWNORMAL);
Windows.SetForegroundWindow(hwind);
Windows.CloseHandle(hwind);
end;
Halt;
end
end; }GOSTEI 0
[vaza]
15/05/2009
Eu defino MutexHandle, hwind como THandle?
no caso ´Gestor RETTA :: Suínos´ seria o título do meu programa, correto?
É que esta retornando um erro. como esta no meu programa:
procedure TForm1.Button1Click(Sender: TObject);
[b:4ceb8f0e5b]var
MutexHandle, hwind: THandle;
begin
MutexHandle := CreateMutex(nil, TRUE, ´IBConsole´);
if MutexHandle <> 0 then
begin
if GetLastError = ERROR_ALREADY_EXISTS then
begin
application.MessageBox(´IBConsole já está em execução em outra janela!´,´ Aviso´, MB_ICONQUESTION);
CloseHandle(MutexHandle);
hwind:=0;
repeat
hwind:=Windows.FindWindowEx(0,hwind,´TApplication´,´IBConsole´);
until (hwind<>Application.Handle);
if (hwind<>0) then
begin
Windows.ShowWindow(hwind,SW_SHOWNORMAL);
Windows.SetForegroundWindow(hwind);
Windows.CloseHandle(hwind);
end;
Halt;
end;
end;
[/b:4ceb8f0e5b]
end;
no caso ´Gestor RETTA :: Suínos´ seria o título do meu programa, correto?
É que esta retornando um erro. como esta no meu programa:
procedure TForm1.Button1Click(Sender: TObject);
[b:4ceb8f0e5b]var
MutexHandle, hwind: THandle;
begin
MutexHandle := CreateMutex(nil, TRUE, ´IBConsole´);
if MutexHandle <> 0 then
begin
if GetLastError = ERROR_ALREADY_EXISTS then
begin
application.MessageBox(´IBConsole já está em execução em outra janela!´,´ Aviso´, MB_ICONQUESTION);
CloseHandle(MutexHandle);
hwind:=0;
repeat
hwind:=Windows.FindWindowEx(0,hwind,´TApplication´,´IBConsole´);
until (hwind<>Application.Handle);
if (hwind<>0) then
begin
Windows.ShowWindow(hwind,SW_SHOWNORMAL);
Windows.SetForegroundWindow(hwind);
Windows.CloseHandle(hwind);
end;
Halt;
end;
end;
[/b:4ceb8f0e5b]
end;
GOSTEI 0
[vaza]
15/05/2009
Eu quero ver se o programa IBConsole está aberto.
Esta aberto?
Então da o foco nele. Como se eu estivesse usando o IBConsole ou como se ele estivesse minimizado e eu cliquei no icone dele na barra de ferramentas do windows e ele abriu.
Esta aberto?
Então da o foco nele. Como se eu estivesse usando o IBConsole ou como se ele estivesse minimizado e eu cliquei no icone dele na barra de ferramentas do windows e ele abriu.
GOSTEI 0
[vaza]
15/05/2009
Consegui!
dexei apenas isso:
procedure TForm1.Button3Click(Sender: TObject);
var
MutexHandle, hwind: THandle;
begin
MutexHandle := CreateMutex(nil, TRUE, ´IBConsole´);
if MutexHandle <> 0 then
begin
hwind:=0;
repeat
hwind:=Windows.FindWindow(nil,´IBConsole´);
until (hwind<>Application.Handle);
if (hwind<>0) then
begin
Windows.ShowWindow(hwind,SW_SHOWMAXIMIZED);
Windows.SetForegroundWindow(hwind);
Halt;
end
end;
end;
Vlw ai por tudo :)
dexei apenas isso:
procedure TForm1.Button3Click(Sender: TObject);
var
MutexHandle, hwind: THandle;
begin
MutexHandle := CreateMutex(nil, TRUE, ´IBConsole´);
if MutexHandle <> 0 then
begin
hwind:=0;
repeat
hwind:=Windows.FindWindow(nil,´IBConsole´);
until (hwind<>Application.Handle);
if (hwind<>0) then
begin
Windows.ShowWindow(hwind,SW_SHOWMAXIMIZED);
Windows.SetForegroundWindow(hwind);
Halt;
end
end;
end;
Vlw ai por tudo :)
GOSTEI 0