Ver Mensaje Individual
  #8  
Antiguo 24-09-2014
pr0sper0 pr0sper0 is offline
Miembro
NULL
 
Registrado: sep 2014
Ubicación: Villa Clara-Cuba
Posts: 12
Reputación: 0
pr0sper0 Va por buen camino
Question Marcador para conexión a Internet por modem

Hola necesito su ayuda con este código, lo que necesito esta comentado en el mismo y el proyecto lo pueden descargar en

terawiki.clubdelphi.com/Delphi/Proyectos/?download=Dialer.rar

Código Delphi [-]
unit Dialer;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, XPMan, ExtCtrls, ComCtrls, Buttons, StdCtrls, jpeg, shellapi;

type
  TFPrincipal = class(TForm)
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    PageControl2: TPageControl;
    TabSheet3: TTabSheet;
    Label6: TLabel;
    Label8: TLabel;
    LabelSpeed: TLabel;
    Label10: TLabel;
    LabelOnline: TLabel;
    GroupBox4: TGroupBox;
    ConnList: TListBox;
    doHangup: TButton;
    doDial: TButton;
    GroupBox5: TGroupBox;
    Label14: TLabel;
    Label15: TLabel;
    ETiempoConexion: TPanel;
    ETiempoConsumido: TPanel;
    GroupBox11: TGroupBox;
    ETiempoContratado: TPanel;
    ConnLog: TMemo;
    TabSheet6: TTabSheet;
    Label3: TLabel;
    PageControl1: TPageControl;
    TabSheet2: TTabSheet;
    Label1: TLabel;
    SpeedButton2: TSpeedButton;
    GroupBox2: TGroupBox;
    edtUser: TEdit;
    GroupBox3: TGroupBox;
    edtPhone: TEdit;
    BitBtn1: TBitBtn;
    GroupBox6: TGroupBox;
    edtPass: TEdit;
    TabSheet5: TTabSheet;
    BitBtn2: TBitBtn;
    GroupBox1: TGroupBox;
    Edit4: TEdit;
    UpDown1: TUpDown;
    TabSheet7: TTabSheet;
    Label2: TLabel;
    GroupBox7: TGroupBox;
    Edit5: TEdit;
    GroupBox8: TGroupBox;
    Edit6: TEdit;
    BitBtn3: TBitBtn;
    TabSheet1: TTabSheet;
    Button2: TButton;
    GroupBox10: TGroupBox;
    Panel3: TPanel;
    TabSheet8: TTabSheet;
    Label12: TLabel;
    Panel6: TPanel;
    Label9: TLabel;
    DateTimePicker1: TDateTimePicker;
    Panel7: TPanel;
    Label11: TLabel;
    DateTimePicker2: TDateTimePicker;
    BitBtn4: TBitBtn;
    GroupBox9: TGroupBox;
    SpeedButton1: TSpeedButton;
    Edit7: TEdit;
    Button1: TButton;
    TabSheet4: TTabSheet;
    Label7: TLabel;
    Panel4: TPanel;
    Label4: TLabel;
    Label5: TLabel;
    Image4: TImage;
    Edit8: TEdit;
    Button3: TButton;
    XPManifest1: TXPManifest;
    TUnSegundo: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure doDialClick(Sender: TObject);
    procedure doHangupClick(Sender: TObject);
    procedure TUnSegundoTimer(Sender: TObject);
    procedure Image2Click(Sender: TObject);
  private
  InicioConexion, TiempoConsumidoAlIniciarAplicacion : TDateTime;
  TiempoConexion, TiempoConsumido,TiempoContratado : TDateTime;
  procedure ActualizaDatos;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FPrincipal: TFPrincipal;

implementation

{$R *.dfm}
uses IniFiles;
const
  RAS_MaxEntryName = 256;
  RASBASE = 600;
  ERROR_BUFFER_TOO_SMALL = RASBASE + 3;
  ERROR_INVALID_SIZE = RASBASE + 32;

type
  PRasEntryName = ^TRasEntryName;
  TRasEntryName = record
    dwSize: Longint;
    szEntryName: array [0..RAS_MaxEntryName] of Char;
  end;

function RasEnumEntriesA(reserved: PChar; lpszPhonebook: PChar;
          lpRasEntryName: PRasEntryName; var lpcb: DWORD;
          var lpcEntries: DWORD): DWORD; stdcall; external 'RASAPI32.DLL';
procedure GetRasEntries(List: TStrings);
var
  RasEntryNames: array of TRasEntryName;
  Err, Size, Entries: DWORD;
  i: Integer;
begin
  List.Clear;
  SetLength(RasEntryNames, 1);
  Size := SizeOf(TRasEntryName);
  RasEntryNames[0].dwSize := Size;
  Err := RasEnumEntriesA(nil, nil, @RasEntryNames[0], Size, Entries);
  if (Err = ERROR_BUFFER_TOO_SMALL) and (Entries > 0) then begin
    Assert(Size = SizeOf(TRasEntryName) * Entries);
    SetLength(RasEntryNames, Entries);
    Err := RasEnumEntriesA(nil, nil, @RasEntryNames[0], Size, Entries);
    if Err = 0 then
      for i := 0 to Length(RasEntryNames) do
        List.Add(RasEntryNames[i].szEntryName);
  end else
    List.Add(RasEntryNames[0].szEntryName);
end;
procedure TFPrincipal.ActualizaDatos;
begin
  // Calculo el tiempo de conexion
  TiempoConexion := Now - InicioConexion;
  TiempoConsumido := TiempoConsumidoAlIniciarAplicacion + TiempoConexion;

  // Actualizo el formulario
  ETiempoContratado.Caption:= TimeToStr(TiempoContratado);
  ETiempoConsumido.Caption:= TimeToStr(TiempoConsumido);
  ETiempoConexion.Caption:= TimeToStr(TiempoConexion);

  // Si el tiempo contratado se ha consumido cierro la aplciacion
  if (TiempoContratado < TiempoConsumido) then
     Close;
end;

procedure TFPrincipal.FormCreate(Sender: TObject);
begin
GetRasEntries(ConnList.Items);
end;

procedure TFPrincipal.doDialClick(Sender: TObject);
var
Ini : TIniFile;
cmd, par, fil, dir: PChar;
begin
cmd := 'open';
fil := 'rasdial.exe';
par := PChar(edtUser.Text + ' ' + edtPass.Text + ' ' + edtPhone.Text);
dir := 'C:';
// llamar a rasdial.exe con Shellexecute
//Necesito que lo q pasa en la ventana de cmd me lo muestre en ConnLog:TMemo como lo hago
//Necesito incorporar el ConnList a la cadena de PChar(edtUser.Text + ' ' + edtPass.Text + ' ' + edtPhone.Text)
//para que puedan utilizar la conexción que deseen.
//Necesito me expliquen como trabajar con los usuarios y contraseñas en la parte administrativa,
//como se guardan, como desde esta parte se puede implementar para que el usuario pueda cambiar la contraseña
//y como lograr que cuando den marcar y el modem no este conectado o la linea ocupada el tiempo
//no empieze a descontar
{SW_SHOWMINNOACTIVE ou SW_HIDE ou SW_SHOWNORMAL};
ShellExecute(Self.Handle, cmd, fil, par, dir, SW_SHOWNORMAL);
 // Hora de inicio de la conexion
  InicioConexion := Now;
  // Lee datos guardados
  Ini := TIniFile.Create('C:\Windows\System32\BRCL06.dll');
  try
     TiempoContratado := StrToTime(Ini.ReadString('Datos', 'TiempoContratado', '00:03:00')); //Este tiempo necesito asignarlo a traves de la pestaña Tiempo de conexiçon de la administración no se hacerlo.
     TiempoConsumidoAlIniciarAplicacion := StrToTime(Ini.ReadString('Datos', 'TiempoConsumido', '00:00:00'));
  finally
     Ini.Free;
  end;

  ActualizaDatos;

  // Inicio el Timer
  TUnSegundo.Enabled := True;
  doDial.Enabled:=false;
  doHangup.Enabled:=true;
end;
procedure TFPrincipal.doHangupClick(Sender: TObject);
var
cmd, par, fil, dir: PChar;
begin
// Desconectar la conexión a Internet
cmd := 'open';
fil := 'rasdial.exe';
par := PChar( ' /DISCONNECT');
//como agrego la conexion que este usandose en el ConnList
dir := 'C:';
ShellExecute(Self.Handle, cmd, fil, par, dir, SW_SHOWMINNOACTIVE);
TUnSegundo.Enabled:=false;
doDial.Enabled:=true;
doHangup.Enabled:=false;
end;

procedure TFPrincipal.TUnSegundoTimer(Sender: TObject);
var
  Ini : TIniFile;
begin
  ActualizaDatos;

  // Actualizo el tiempo consumido
  Ini := TIniFile.Create('C:\Windows\System32\BRCL06.dll');
  try
     Ini.WriteString('Datos', 'TiempoConsumido', TimeToStr(TiempoConsumido));
  finally
  Ini.Free;

  end;
end;

procedure TFPrincipal.Image2Click(Sender: TObject);
var
cmd, par, fil, dir: PChar;
begin
MessageDlg( 'Su conexción terminará.', mtInformation, [ mbOK ],0);
// Desconectar la conexión a Internet
cmd := 'open';
fil := 'rasdial.exe';
par := PChar( ' /DISCONNECT');
//como agrego la conexion que este usandose en el ConnList
dir := 'C:';
ShellExecute(Self.Handle, cmd, fil, par, dir, SW_SHOWMINNOACTIVE);
TUnSegundo.Enabled:=false;
Close;
end;
end.
Responder Con Cita