 |
Club Builder Foro de C++Builder en español
|
| Ver tema anterior :: Ver tema siguiente |
| Autor |
Mensaje |
an_dario Cdt

Registrado: 03 Nov 2005Mensajes: 5
|
Publicado: Jue 03 Nov, 2005 9:56 pm Asunto: COMO HACER PARA QUE UNA APLICACION NO C ABRA MAS D 1 VEZ?? |
|
|
HOLA. TENGO UNA PEQUEÑA DUDA Y QUISIERA POR FAVOR ME AYUDARAN A RESOLVERLA. COMO PUEDO HACER PARA QUE UNA APLICACION NO SE ABRA MAS DE UNA VEZ. LE AGRADECERIA MUCHO SI ME AYUDARAN...
ANDRES!!!  |
|
| Volver arriba |
|
 |
bosoft Master

Registrado: 23 Oct 2005Mensajes: 342
|
Publicado: Jue 03 Nov, 2005 10:46 pm Asunto: |
|
|
espero que te sirva. Esta bajado de borland
| Cita: |
//---------------------------------------------------------------------------
//-- Author: Cleber Jorge Amaral
//-- E-mail: clebercbr@yahoo.ca
//-- Web-site: http://clebercbr.8k.com
//-- Cowntry: Brazil
//-- Date: 26/07/2005
//-- IDE: Borland C++Builder 6
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
... includes ...
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try{
THandle hMap;
PHandle HandleData;
hMap = (THandle) CreateFileMapping(0, NULL, PAGE_READWRITE, 0, sizeof(THandle),"{TESTTEST-0000-0000-0000-000000000001}");
if (GetLastError() == ERROR_ALREADY_EXISTS){
hMap = (THandle) OpenFileMapping(FILE_MAP_READ, false, "{TESTTEST-0000-0000-0000-000000000001}");
if (hMap != 0){
HandleData = (PHandle) MapViewOfFile(&hMap, FILE_MAP_READ, 0, 0, sizeof(THandle));
if (IsIconic(HandleData)) ShowWindow(&HandleData, SW_RESTORE);
SetForegroundWindow(&HandleData);
MessageDlg("O aplicativo já foi inicializado!", mtInformation, TMsgDlgButtons() << mbOK, 0);
}
}else{
Application->Initialize();
... forms ...
Application->Run();
}
} catch (Exception &exception) {
Application->ShowException(&exception);
} catch (...) {
try {
throw Exception("");
} catch (Exception &exception) {
Application->ShowException(&exception);
}
}
return 0;
}
//---------------------------------------------------------------------------
|
Saludos, bosoft. |
|
| Volver arriba |
|
 |
Cesar C. Salazar Gonzalez Master


Registrado: 01 Oct 2002Mensajes: 2155Ubicación: San Cristóbal de Las Casas, Chiapas
|
Publicado: Vie 04 Nov, 2005 4:21 pm Asunto: |
|
|
Otra manera de hacerlo es creando un MUTEX, dentro del mismo archivo que te mencionan arriba, para ello debes ingresar en la parte de
Project - Options - (solapa Application) y establecer en donde dice
"Title" el titulo de tu apliacacion por ejemplo mi "MiPrograma"
y posteriormente usas el siguiente codigo..
| Código: | WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
//::CreateMutex(NULL,NULL,"MUTEX");
::CreateMutex(NULL,NULL,"Mi_Programa"); //para que no se repita
if(GetLastError()){
HWND FirstWnd;
FirstWnd = ::FindWindow("TApplication","MiPrograma"); //OJO
if(FirstWnd!=NULL)
{
// si se encuentra, enviamos un mensaje y lo traemos al frente
::ShowMessage("El Programa ya esta en ejecucción");
::SetForegroundWindow(FirstWnd);
}
}else{
// si no se encuentra, dejamos el proceso del programa
// ejecutarse
Application->ProcessMessages();
Application->Initialize();
Application->Title = "MiPrograma";
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
} |
Saludos... otra opcion es buscar dentro del Foro _________________
 |
|
| Volver arriba |
|
 |
Invitado
|
Publicado: Sab 05 Nov, 2005 12:54 am Asunto: MUCHAS GRACIAS |
|
|
muchisimas gracias!!!!!
| bosoft escribió: | espero que te sirva. Esta bajado de borland
| Cita: |
//---------------------------------------------------------------------------
//-- Author: Cleber Jorge Amaral
//-- E-mail: clebercbr@yahoo.ca
//-- Web-site: http://clebercbr.8k.com
//-- Cowntry: Brazil
//-- Date: 26/07/2005
//-- IDE: Borland C++Builder 6
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
... includes ...
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try{
THandle hMap;
PHandle HandleData;
hMap = (THandle) CreateFileMapping(0, NULL, PAGE_READWRITE, 0, sizeof(THandle),"{TESTTEST-0000-0000-0000-000000000001}");
if (GetLastError() == ERROR_ALREADY_EXISTS){
hMap = (THandle) OpenFileMapping(FILE_MAP_READ, false, "{TESTTEST-0000-0000-0000-000000000001}");
if (hMap != 0){
HandleData = (PHandle) MapViewOfFile(&hMap, FILE_MAP_READ, 0, 0, sizeof(THandle));
if (IsIconic(HandleData)) ShowWindow(&HandleData, SW_RESTORE);
SetForegroundWindow(&HandleData);
MessageDlg("O aplicativo já foi inicializado!", mtInformation, TMsgDlgButtons() << mbOK, 0);
}
}else{
Application->Initialize();
... forms ...
Application->Run();
}
} catch (Exception &exception) {
Application->ShowException(&exception);
} catch (...) {
try {
throw Exception("");
} catch (Exception &exception) {
Application->ShowException(&exception);
}
}
return 0;
}
//---------------------------------------------------------------------------
|
Saludos, bosoft. |
|
|
| Volver arriba |
|
 |
ITM Cdt

Registrado: 23 Nov 2005Mensajes: 11
|
Publicado: Vie 25 Nov, 2005 10:23 am Asunto: |
|
|
| A mi me causa un problema el metodo para no poder mostrar mas de 1 vez la aplicacion y es que por ejemplo, yo tengo varias ventanas o formas que aparecen con algunos eventos desde la forma principal, siempre las tego en StayOnTop, pero al momento de ejecutar ese codigo, basta que yo de click fuera de esas formas, y desaparecen, como si el estilo de la forma fuera el Normal, hay alguna forma de solucionar esto? |
|
| Volver arriba |
|
 |
|
|
No puedes publicar temas nuevos en este foro No puedes responder a temas en este foro No puedes editar tus mensajes en este foro No puedes borrar tus mensajes en este foro No puedes votar en las encuestas de este foro
|
© 2002–2026 Club Builder · Funciona con phpBB.
|