Fórum componente ribbon dando dor de cabeca #416236
04/05/2012
0
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
Curtir tópico
+ 0Posts
05/05/2012
Wesley Yamazack
Um abraço e te retorno ainda hoje.
Gostei + 0
05/05/2012
Wesley Yamazack
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
05/05/2012
Bruno Leandro
Gostei + 0
07/05/2012
Eniorm
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
07/05/2012
Perivaldo Martins
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
08/05/2012
Edson Melo
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
08/05/2012
Eniorm
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
11/05/2012
Edson Melo
agradeco pela ajuda e ate breve
edson garcia de melo
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)