拨号问题?(50分)

  • 主题发起人 主题发起人 zfnet
  • 开始时间 开始时间
Z

zfnet

Unregistered / Unconfirmed
GUEST, unregistred user!
我在delphi中拨号代码如下:
var
strDialName : string;
begin

strDialName := '163';//拨号连接的名称设为163
winexec( PChar('rundll32.exe rnaui.dll,RnaDial ' + strDialName),SW_SHOWNORMAL);
end;

执行后不能自动拨号,只能调出拨号窗口,然后再点击连接进行连接,
不知怎样实现连接后自动连接拨号??而不再出现拨号窗口??
 
我的不知跑到哪里去了,查询一下拨号就有了。
 
没试过你自己试试
--------------------------------------------
电话号码设置是正确的,关键是RasDial的参数要设置正确,
请看下面的例子:
function MyDial(FEntryName: String;
FPhoneNumber: String;
FCallbackNumber: String;
FUserName: String;
FPassword: String;
FDomain: String;
FHRasConn: THRasConn): Longint;
var
DialParams: TRasDialParams;
lpfPassword: LongBool;
begin
if FHRasConn > 0 then
HangUp;
FillChar(DialParams, SizeOf(TRasDialParams), #0);
with DialParamsdo
begin
dwSize:=Sizeof(TRasDialParams);
StrPCopy(szEntryName, FEntryName);
end;

if FEntryName <> '' then
begin
Result := RasGetEntryDialParams(nil, DialParams, lpfPassWord);
if Result <> 0 then
Exit;
end
else
with DialParamsdo
begin
dwSize := SizeOf(TRASDialParams);
szEntryName := '';
UniqueString(FPhoneNumber);
StrLCopy(szPhoneNumber, PChar(FPhoneNumber), RAS_MaxPhoneNumber);
UniqueString(FCallBackNumber);
UniqueString(FCallBackNumber);
StrLCopy(szCallbackNumber, PChar((FCallBackNumber)),
RAS_MaxCallbackNumber);
UniqueString(FUserName);
StrLCopy(szUserName,PChar((FUserName)) , UNLEN);
UniqueString(fPassWord);
StrLCopy(szPassword, PChar((fPassWord)), PWLEN);
UniqueString(FDomain);
StrLCopy(szDomain, Pchar(FDomain), DNLEN);
end;

FHRasConn := 0;
Result := RasDial(nil, nil, DialParams, 0, nil, FHRasConn);
end;
 
下面是一个拨号的单元代码,你自己看把
unit Dialer;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, DialDlg;
type
TComPort = (dpCOM1,dpCOM2,dpCOM3,dpCOM4);
TMethod = (dmTone,dmPulse);
TDialer = class(TComponent)
private
{ Private declarations }
FComPort : TComPort;
FNumberToDial : string;
FConfirm : boolean;
FMethod : TMethod;
FInitStr : string;
Buf : array[1..32] of Char;
protected
{ Protected declarations }
CId : Integer;
Stat : TComStat;
HInv : HWnd;
DialerDlg : TDialerDlg;
procedure WndProc(var Msg : TMessage);
public
{ Public declarations }
constructor Create(AOwner : TComponent);
override;
destructor Destroy;
override;
procedure Execute;
published
{ Published declarations }
property ComPort : TComPort read FComPort
write FComPort;
property Confirm : boolean read FConfirm
write FConfirm;
property InitStr : string read FInitStr
write FInitStr;
property Method : TMethod read FMethod
write FMethod;
property NumberToDial : string read FNumberToDial
write FNumberToDial;
end;

procedure Register;
implementation
procedure Register;
begin
RegisterComponents('System', [TDialer]);
end;

constructor TDialer.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
HInv:=AllocateHWnd(WndProc);
end;

destructor TDialer.Destroy;
begin
DeallocateHWnd(HInv);
inherited Destroy;
end;

procedure TDialer.WndProc(var Msg : TMessage);
var
Status : Integer;
s : string;
begin
with Msgdo
if (Msg=WM_COMMNOTIFY) and (lParamLo=CN_RECEIVE) then
begin
Status:=ReadComm(CId,@Buf,128);
GetCommError(CId,Stat);
s:=UpperCase(StrPas(@Buf));
if Pos('DIALTONE',s)<>0 then
DialerDlg.Label1.Caption:='没有信号......'
else
if Pos('BUSY',s)<>0 then
DialerDlg.Label1.Caption:='线路忙......';
Result:=0;
end
else
Result:=DefWindowProc(HInv, Msg, wParam, lParam);
end;

procedure TDialer.Execute;
var
s : string;
Status : Integer;
begin
{Open Com Port}
StrPCopy(@Buf,'COM ');
Buf[4]:=Chr(49+Ord(FComPort));
CId:=OpenComm(@Buf,512,512);
if CId<0 then
begin
MessageDlg('不能打开'+StrPas(@Buf),mtError,
[mbOk], 0);
Exit;
end;
{Send modem initialization string, if any}
if FInitStr<>'' then
begin
s:=FInitStr+^M^J;
StrPCopy(@Buf,s);
Status:=WriteComm(CId,@Buf,StrLen(@Buf));
if Status<0 then
begin
MessageDlg(' The modem 初始化错误',mtError,
[mbOk],0);
CloseComm(CId);
Exit;
end;
end;
if FConfirm then
begin
if MessageDlg('About to dial the number '+FNumberToDial+'. Are you sure?',
mtConfirmation, [mbYes,mbNo], 0)<>mrYes then
begin
CloseComm(CId);
Exit;
end;
end;
{Create a string to send to modem}
s:=Concat('ATDT',FNumberToDial,^M^J);
if FMethod=dmPulse then
s[4]:='P';
{Send phone number to modem}
StrPCopy(@Buf,s);
Status:=WriteComm(CId,@Buf,StrLen(@Buf));
{Enable WM_COMMNOTIFY message}
EnableCommNotification(CId,HInv,128,128);
if Status>=0 then
begin
DialerDlg:=TDialerDlg.Create(Application);
DialerDlg.Caption:=Concat('Dialing ',FNumberToDial);
DialerDlg.ShowModal;
DialerDlg.Free;
WriteComm(CId,'ATH'^M^J,5);
end
else
MessageDlg('拨号不能进行!',mtError,
[mbOk], 0);
{Close communication port}
if CId>0 then
CloseComm(CId);
end;

end.
 
是个控件代码,把它改一下,应该可以了吧
 
后退
顶部