componente ribbon dando dor de cabeca
retirado do help DTDelphi versao 2.7
159 - Verificando se há uma cópia em execução
program Project1;
uses Forms,windows,dialogs, Unit1 in Unit1.pas;
{$R *.RES}
var
Hwnd: Thandle;
begin
Hwnd := FindWindow (TLloydSoft, LloydSoft);
if Hwnd = 0 then
begin
Application.Initialize;
Application.CreateForm(TLloydsoft, Lloydsoft);
Application.Run;
end
else
begin
MessageDlg (Este programa já esta aberto,mtinformation,[mbok], 0);
SetForegroundWindow (Hwnd);
end;
end.
{obs: para o exemplo acima funcionar a propriedade Caption do Formulário deve ser LloydSoft
esta rotina funcionava com delphi 7 mas com o uso do componete ribbon no delphi 2010, parou
favor ajudem-me a solucionar esta cauas de problemas
159 - Verificando se há uma cópia em execução
program Project1;
uses Forms,windows,dialogs, Unit1 in Unit1.pas;
{$R *.RES}
var
Hwnd: Thandle;
begin
Hwnd := FindWindow (TLloydSoft, LloydSoft);
if Hwnd = 0 then
begin
Application.Initialize;
Application.CreateForm(TLloydsoft, Lloydsoft);
Application.Run;
end
else
begin
MessageDlg (Este programa já esta aberto,mtinformation,[mbok], 0);
SetForegroundWindow (Hwnd);
end;
end.
{obs: para o exemplo acima funcionar a propriedade Caption do Formulário deve ser LloydSoft
esta rotina funcionava com delphi 7 mas com o uso do componete ribbon no delphi 2010, parou
favor ajudem-me a solucionar esta cauas de problemas
Edson Melo
Curtidas 0
Respostas
Wesley Yamazack
04/05/2012
Olá Edson, acabei de ver seu tópico aqui no forum, estou dando uma olhada para poder tentar te ajudar, não garanto resultado, rs.. Mas vou tentar fazer aqui agora.
Um abraço e te retorno ainda hoje.
Um abraço e te retorno ainda hoje.
GOSTEI 0
Wesley Yamazack
04/05/2012
Olá Edson, acabei aqui o código, foi mais rápido do que imaginava...
Listagem 1: No projeto fiz assim.
Listagem 2:
Bom comigo funcionou certinho aqui, até gostei da ideia! rs
Obs: Se não funcionar, me manda o fonte do teu projeto, coloca num disco virtual para poder testar.
Um abraço e bom código!
Listagem 1: No projeto fiz assim.
program prj_Ribbon_Aberto;
uses
Forms,
windows,
dialogs,
uFrmLloydSoft in uFrmLloydSoft.pas ;
{$R *.res}
var
Hwnd: Thandle;
begin
Hwnd := FindWindow (TLloydSoft, LloydSoft);
if Hwnd = 0 then
begin
Application.Initialize;
Application.CreateForm(TLloydsoft, Lloydsoft);
Application.Run;
end
else
begin
MessageDlg (Este programa já esta aberto,mtinformation,[mbok], 0);
SetForegroundWindow (Hwnd);
end;
end.
Listagem 2:
Nome do Formulário com o Ribbon: LloydSoft Nome da Unit com do Ribbon: uFrmLloydSoft
Bom comigo funcionou certinho aqui, até gostei da ideia! rs
Obs: Se não funcionar, me manda o fonte do teu projeto, coloca num disco virtual para poder testar.
Um abraço e bom código!
GOSTEI 0
Bruno Leandro
04/05/2012
caso não funcione de uma pesquisada sobre mutex
GOSTEI 0
Eniorm
04/05/2012
eu tenho em casa uma unit bem antiga, usei ela desde o D6 eu acho, usei muito no D7, por fim, vi que ela continuava a funcionar, nas versões seguintes... já testei no XE e funcionou.
Você não precisa implementar nada, basta adicionar a unit no projeto e pronto.
Porém está em casa no hd, hoje a noite ou amanhã eu posto o código dela aqui.
Você não precisa implementar nada, basta adicionar a unit no projeto e pronto.
Porém está em casa no hd, hoje a noite ou amanhã eu posto o código dela aqui.
GOSTEI 0
Perivaldo Martins
04/05/2012
Dá uma olhada em Mutex.
Boa sorte e bons códigos!
uses
windows
var
mAppMutexHnd: cardinal;
const
APPLICATION_MUTEX_ID = AplicativoMutex;
begin
Application.Initialize;
// Cria o mutex para verificação
mAppMutexHnd := CreateMutex(nil, BOOL(1), APPLICATION_MUTEX_ID);
// Checa se a aplicação já está rodando
if (mAppMutexHnd = 0) or (GetLastError <> 0) then
begin
MessageBox(0, Programa já em execução., Aviso, MB_ICONHAND);
Application.Terminate;
end;
try
Application.Run;
finally
// Fecha a instância criada
CloseHandle(mAppMutexHnd);
end;
Application.Terminate;
Boa sorte e bons códigos!
GOSTEI 0
Edson Melo
04/05/2012
agradeço a todos , não tenho internet em casa , por isso vou testar as ideias e depois volto a postar,
so para completar estas linhas que citei acima funcionam muito bem no delphi 7, no delphi 2010 que e o que uso tambem funciona, mas o problema e com o componente ribbon, sabe aquele menu bonito que colocaram no word 2007, pois é coloquei no meu sistema, e qual a minha surpresa, a opção paroiu de funcionar, ou seja, sew eu abrir mais de uma vez o sistema , não sou avisado, e iso esta me dando dor de cabeça nos meus clientes. para eu tirar o componente ribbon e voltar o meu sistema ao menu antigo , naõp acho uma boa, por causa disto e que estou pedindo esta ajuda.
vou testar e depois posto resposta , mas antecipadamente agradeço pelo ajuda
ateniosamente
edson garcia de melo
obs : Seria possivel me enviarem em cd o delphi xe2, pois aqui no interior do para a internet e uma carroça quase parando e para mim fazer o download demoraria um 15 dias mais ou menos,
so para completar estas linhas que citei acima funcionam muito bem no delphi 7, no delphi 2010 que e o que uso tambem funciona, mas o problema e com o componente ribbon, sabe aquele menu bonito que colocaram no word 2007, pois é coloquei no meu sistema, e qual a minha surpresa, a opção paroiu de funcionar, ou seja, sew eu abrir mais de uma vez o sistema , não sou avisado, e iso esta me dando dor de cabeça nos meus clientes. para eu tirar o componente ribbon e voltar o meu sistema ao menu antigo , naõp acho uma boa, por causa disto e que estou pedindo esta ajuda.
vou testar e depois posto resposta , mas antecipadamente agradeço pelo ajuda
ateniosamente
edson garcia de melo
obs : Seria possivel me enviarem em cd o delphi xe2, pois aqui no interior do para a internet e uma carroça quase parando e para mim fazer o download demoraria um 15 dias mais ou menos,
GOSTEI 0
Eniorm
04/05/2012
como eu havia prometido, a unit que basta ser adicionada ao projeto, e mais nada.
Podem fazer download aqui: http://www.enio.pro.br/delphi/uDHSOneInstanceApp.pas
ou copiar o código abaixo e colar numa nova unit do Delphi, depois salvar.
(* Just include this unit in your project *)
(* ONE Instance APP
Author : Clément Doss
Date : 6 - DEZ - 2000
VErsion : 0.0 - First relaease
*)
(* If you have any suggestions or bug reports please do
email it to suporte@dhs.com.br *)
(* How it works *)
(* I am just trying to keep it simply stupid. I just wanted to add a unit
to my project that will ensure that one and only one instance will be
running.
I never liked to change the Project Source to add stuff there... ThatŽs why
I wrote this unit.
Just Add this unit to your project and only one application (with the same
title) will be allowed to run.
*)
(* A few more details....
I am using the Application.Title property as an application identifier.
If you are using two application with the same Application.Title, then the
second one will not open....
I used the Title because it seems to be adequate to the following rules:
1) No code will be added. Just add the unit!
2) Two applications with the same title seems unlikely to happen.
3) ... Just not figured this one yet...
I am using MUTEXes to check the existance of a second instance of the same
application.
Both CreateMutex and WaitForSingleObjects are available for Win9x and Windows NT.
I have tested it with Windows 2000 pro, and delphi 5 E. But it should work with
earlier versions of delphi.
Enjoy...
*)
unit uDHSOneInstanceApp;
interface
implementation
uses Windows, // THandle defined here
SysUtils, // strPCopy defined here
Forms; // Application defined here
type
TdhsOneInstanceApp = Class(TObject)
private
FMutex : THandle;
FAppTitle : Array[0..$100] of char;
procedure CheckForAnotherInstance;
public
{ Public declarations }
constructor Create;
end;
(* ////////// \\\\\\\\\\ *)
var
OneInstanceApp : TdhsOneInstanceApp;
{ TdhsOnceInstance }
constructor TdhsOneInstanceApp.Create;
begin
strPCopy(FappTitle,Application.Title);
CheckForAnotherInstance;
end;
procedure TdhsOneInstanceApp.CheckForAnotherInstance;
var
hRunningApp : THandle;
begin
// .. This mutex will be freed when the applcation closes!
FMutex := CreateMutex (nil, FALSE, FAppTitle );
if WaitForSingleObject (FMutex, 0) = wait_TimeOut then begin
// Found another instance
SetWindowText(Application.Handle,); // We must not found this one again ;)
// Retrieving handle of the first instance;
hRunningApp := FindWindow(nil,FAppTitle);
if hRunningApp<>0 then begin
if IsIconic(hRunningApp) then
// First instance is minimized.. Restore it
ShowWindow(hRunningApp,SW_RESTORE);
BringWindowToTop(hRunningApp);
SetForegroundWindow(hRunningApp);
end;
// Finish this second instance ...
Application.ShowMainForm := False; // Well... donŽt show the main windows
Application.Terminate;
Halt(2);
end;
end;
initialization
OneInstanceApp := TdhsOneInstanceApp.Create;
finalization
OneInstanceApp.Free;
end.
Podem fazer download aqui: http://www.enio.pro.br/delphi/uDHSOneInstanceApp.pas
ou copiar o código abaixo e colar numa nova unit do Delphi, depois salvar.
(* Just include this unit in your project *)
(* ONE Instance APP
Author : Clément Doss
Date : 6 - DEZ - 2000
VErsion : 0.0 - First relaease
*)
(* If you have any suggestions or bug reports please do
email it to suporte@dhs.com.br *)
(* How it works *)
(* I am just trying to keep it simply stupid. I just wanted to add a unit
to my project that will ensure that one and only one instance will be
running.
I never liked to change the Project Source to add stuff there... ThatŽs why
I wrote this unit.
Just Add this unit to your project and only one application (with the same
title) will be allowed to run.
*)
(* A few more details....
I am using the Application.Title property as an application identifier.
If you are using two application with the same Application.Title, then the
second one will not open....
I used the Title because it seems to be adequate to the following rules:
1) No code will be added. Just add the unit!
2) Two applications with the same title seems unlikely to happen.
3) ... Just not figured this one yet...
I am using MUTEXes to check the existance of a second instance of the same
application.
Both CreateMutex and WaitForSingleObjects are available for Win9x and Windows NT.
I have tested it with Windows 2000 pro, and delphi 5 E. But it should work with
earlier versions of delphi.
Enjoy...
*)
unit uDHSOneInstanceApp;
interface
implementation
uses Windows, // THandle defined here
SysUtils, // strPCopy defined here
Forms; // Application defined here
type
TdhsOneInstanceApp = Class(TObject)
private
FMutex : THandle;
FAppTitle : Array[0..$100] of char;
procedure CheckForAnotherInstance;
public
{ Public declarations }
constructor Create;
end;
(* ////////// \\\\\\\\\\ *)
var
OneInstanceApp : TdhsOneInstanceApp;
{ TdhsOnceInstance }
constructor TdhsOneInstanceApp.Create;
begin
strPCopy(FappTitle,Application.Title);
CheckForAnotherInstance;
end;
procedure TdhsOneInstanceApp.CheckForAnotherInstance;
var
hRunningApp : THandle;
begin
// .. This mutex will be freed when the applcation closes!
FMutex := CreateMutex (nil, FALSE, FAppTitle );
if WaitForSingleObject (FMutex, 0) = wait_TimeOut then begin
// Found another instance
SetWindowText(Application.Handle,); // We must not found this one again ;)
// Retrieving handle of the first instance;
hRunningApp := FindWindow(nil,FAppTitle);
if hRunningApp<>0 then begin
if IsIconic(hRunningApp) then
// First instance is minimized.. Restore it
ShowWindow(hRunningApp,SW_RESTORE);
BringWindowToTop(hRunningApp);
SetForegroundWindow(hRunningApp);
end;
// Finish this second instance ...
Application.ShowMainForm := False; // Well... donŽt show the main windows
Application.Terminate;
Halt(2);
end;
end;
initialization
OneInstanceApp := TdhsOneInstanceApp.Create;
finalization
OneInstanceApp.Free;
end.
GOSTEI 0
Edson Melo
04/05/2012
ola pessoal meu oroblema foi resolvido com o mutex
agradeco pela ajuda e ate breve
edson garcia de melo
agradeco pela ajuda e ate breve
edson garcia de melo
GOSTEI 0