Alattare
31-07-2014, 18:39
Запускается одна и та же программа во всех трех (с разными ключами),что не так сделано
Код:
#include <vcl.h>
#pragma hdrstop
#include <Tlhelp32.h>
#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
char* pName;
AnsiString FullPath;
int OE;
String Capt;
__fastcall TForm1::TForm1(TComponent* Owner)
:TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N1Click(TObject *Sender)
{
OE = ((TMenuItem *)Sender)->Tag;
Capt = ((TMenuItem *)Sender)->Caption;
BitBtn1->Enabled = true;
switch(OE)
{
case 0 : FullPath = "revLoader.exe","-launch hl.exe -game cstrike -steam"; break;
case 1 : FullPath = "revLoader.exe","-launch hl.exe -game czero -steam"; break;
case 2 : FullPath = "revLoader.exe","-launch hl.exe -steam"; break;
}
Timer1->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
ShellExecute(NULL,"open",FullPath.c_str(),NULL,NULL,SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------
bool IsProcessRun(char* pName)
{
HANDLE Hndl = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(Hndl == INVALID_HANDLE_VALUE) return false;
PROCESSENTRY32 ProcessEntry;
ProcessEntry.dwSize = sizeof(ProcessEntry);
bool Loop = Process32First(Hndl, &ProcessEntry);
while (Loop)
{
if (strcmp(ProcessEntry.szExeFile, pName) == 0)
{
CloseHandle(Hndl);
return true;
}
Loop = Process32Next(Hndl, &ProcessEntry);
}
return false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
pName = AnsiString(ExtractFileName(FullPath)).c_str();
if(! IsProcessRun(pName))
{
BitBtn1->Caption = Capt + " [0]";
BitBtn1->Enabled = true;
}
else
{
BitBtn1->Caption = Capt + " [1]";
BitBtn1->Enabled = false;
}
Application->ProcessMessages();
}
//---------------------------------------------------------------------------
P.S
Исходный код для C++ Builder XE6
Код:
#include <vcl.h>
#pragma hdrstop
#include <Tlhelp32.h>
#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
char* pName;
AnsiString FullPath;
int OE;
String Capt;
__fastcall TForm1::TForm1(TComponent* Owner)
:TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N1Click(TObject *Sender)
{
OE = ((TMenuItem *)Sender)->Tag;
Capt = ((TMenuItem *)Sender)->Caption;
BitBtn1->Enabled = true;
switch(OE)
{
case 0 : FullPath = "revLoader.exe","-launch hl.exe -game cstrike -steam"; break;
case 1 : FullPath = "revLoader.exe","-launch hl.exe -game czero -steam"; break;
case 2 : FullPath = "revLoader.exe","-launch hl.exe -steam"; break;
}
Timer1->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
ShellExecute(NULL,"open",FullPath.c_str(),NULL,NULL,SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------
bool IsProcessRun(char* pName)
{
HANDLE Hndl = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(Hndl == INVALID_HANDLE_VALUE) return false;
PROCESSENTRY32 ProcessEntry;
ProcessEntry.dwSize = sizeof(ProcessEntry);
bool Loop = Process32First(Hndl, &ProcessEntry);
while (Loop)
{
if (strcmp(ProcessEntry.szExeFile, pName) == 0)
{
CloseHandle(Hndl);
return true;
}
Loop = Process32Next(Hndl, &ProcessEntry);
}
return false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
pName = AnsiString(ExtractFileName(FullPath)).c_str();
if(! IsProcessRun(pName))
{
BitBtn1->Caption = Capt + " [0]";
BitBtn1->Enabled = true;
}
else
{
BitBtn1->Caption = Capt + " [1]";
BitBtn1->Enabled = false;
}
Application->ProcessMessages();
}
//---------------------------------------------------------------------------
P.S
Исходный код для C++ Builder XE6