PDA

View Full Version : سوال: کار با متد mTapiex_OnCallerID کامپوننت tapiex ؟؟؟



shahrzad87
سه شنبه 05 مهر 1390, 23:44 عصر
سلام
مودم caller ID رو پشتیبانی می کنه و با نمونه برنامه های تلفن گویا که از اینترنت گرفتم تست کردم مشکل نداشت و شماره رو نشون می داد اما برنامه Caller ID از visual C# sample خود Tapiex رو که اجرا می کنم شماره رو نشون نمی ده و اصلا وارد متد mTapiex_OnCallerID نمیشه !!! و مقدار متغیر eventArgs.callerNumber متد خالی هست!
کد برنامه رو هم اینجا ضمیمه میکنم :|







#define Win32
using System.Diagnostics;
using AxTAPIEXLib;
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;

//################################################## ##################################
//# Program name: Caller ID DEMO #
//# #
//# Version: v1.0 #
//# #
//# Date: Nov 26th 2004 #
//# #
//# Requirements: TAPIEx control, VOICE modem or TAPI compliant telephony device #
//# #
//# Operating System: Windows 98, Windows ME, Windows NT 4, Windows 2000, Windows XP #
//# #
//# Note: Under Windows NT 4 voice modems may not supported because of the lack of a #
//# voice capable TAPI universal modem driver. # #
//# #
//# Program Purpose: To demonstrate how to add telephony functions to your application#
//# using the TAPIEx ActiveX control. #
//# #
//################################################## ##################################
namespace Project1
{
internal class Form1 : System.Windows.Forms.Form
{

[STAThread]
static void Main()
{
Application.Run(new Form1());
}
#region "Windows Form Designer generated code "
public Form1() {
if (m_vb6FormDefInstance == null)
{
if (m_InitializingDefInstance)
{
m_vb6FormDefInstance = this;
}
else
{
try
{
//For the start-up form, the first instance created is the default instance.
if (System.Reflection.Assembly.GetExecutingAssembly() .EntryPoint.DeclaringType == this.GetType())
{
m_vb6FormDefInstance = this;
}
}
catch
{
}
}
}
//This call is required by the Windows Form Designer.
InitializeComponent();
}
//Form overrides dispose to clean up the component list.
protected override void Dispose (bool Disposing)
{
if (Disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(Disposing);
}

private System.ComponentModel.IContainer components;
//Required by the Windows Form Designer
public System.Windows.Forms.ToolTip ToolTip1;
public System.Windows.Forms.Button BnClose;
public System.Windows.Forms.Button BnOpen;
public System.Windows.Forms.ComboBox CBLines;
public System.Windows.Forms.Label LbState;
public System.Windows.Forms.Label Label2;
//NOTE: The following procedure is required by the Windows Form Designer
//It can be modified using the Windows Form Designer.
//Do not modify it using the code editor.
internal System.Windows.Forms.TextBox Txtlog;
internal AxTAPIEXLib.AxTAPIExCtl mTAPIEx;
[System.Diagnostics.DebuggerStepThrough()]private void InitializeComponent ()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typ eof(Form1));
this.ToolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.BnClose = new System.Windows.Forms.Button();
this.BnOpen = new System.Windows.Forms.Button();
this.CBLines = new System.Windows.Forms.ComboBox();
this.LbState = new System.Windows.Forms.Label();
this.Label2 = new System.Windows.Forms.Label();
this.Txtlog = new System.Windows.Forms.TextBox();
this.mTAPIEx = new AxTAPIEXLib.AxTAPIExCtl();
((System.ComponentModel.ISupportInitialize)(this.m TAPIEx)).BeginInit();
this.SuspendLayout();
//
// BnClose
//
this.BnClose.BackColor = System.Drawing.SystemColors.Control;
this.BnClose.Cursor = System.Windows.Forms.Cursors.Default;
this.BnClose.Enabled = false;
this.BnClose.ForeColor = System.Drawing.SystemColors.ControlText;
this.BnClose.Location = new System.Drawing.Point(120, 40);
this.BnClose.Name = "BnClose";
this.BnClose.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.BnClose.Size = new System.Drawing.Size(63, 21);
this.BnClose.TabIndex = 5;
this.BnClose.Text = "Close";
this.BnClose.UseVisualStyleBackColor = false;
this.BnClose.Click += new System.EventHandler(this.BnClose_Click);
//
// BnOpen
//
this.BnOpen.BackColor = System.Drawing.SystemColors.Control;
this.BnOpen.Cursor = System.Windows.Forms.Cursors.Default;
this.BnOpen.ForeColor = System.Drawing.SystemColors.ControlText;
this.BnOpen.Location = new System.Drawing.Point(16, 40);
this.BnOpen.Name = "BnOpen";
this.BnOpen.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.BnOpen.Size = new System.Drawing.Size(71, 21);
this.BnOpen.TabIndex = 4;
this.BnOpen.Text = "Open";
this.BnOpen.UseVisualStyleBackColor = false;
this.BnOpen.Click += new System.EventHandler(this.BnOpen_Click);
//
// CBLines
//
this.CBLines.BackColor = System.Drawing.SystemColors.Window;
this.CBLines.Cursor = System.Windows.Forms.Cursors.Default;
this.CBLines.ForeColor = System.Drawing.SystemColors.WindowText;
this.CBLines.Location = new System.Drawing.Point(64, 8);
this.CBLines.Name = "CBLines";
this.CBLines.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.CBLines.Size = new System.Drawing.Size(209, 21);
this.CBLines.TabIndex = 0;
//
// LbState
//
this.LbState.BackColor = System.Drawing.SystemColors.Control;
this.LbState.Cursor = System.Windows.Forms.Cursors.Default;
this.LbState.ForeColor = System.Drawing.SystemColors.ControlText;
this.LbState.Location = new System.Drawing.Point(8, 64);
this.LbState.Name = "LbState";
this.LbState.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.LbState.Size = new System.Drawing.Size(273, 54);
this.LbState.TabIndex = 2;
//
// Label2
//
this.Label2.BackColor = System.Drawing.SystemColors.Control;
this.Label2.Cursor = System.Windows.Forms.Cursors.Default;
this.Label2.ForeColor = System.Drawing.SystemColors.ControlText;
this.Label2.Location = new System.Drawing.Point(8, 8);
this.Label2.Name = "Label2";
this.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.Label2.Size = new System.Drawing.Size(49, 17);
this.Label2.TabIndex = 1;
this.Label2.Text = "Device:";
//
// Txtlog
//
this.Txtlog.Location = new System.Drawing.Point(5, 121);
this.Txtlog.Multiline = true;
this.Txtlog.Name = "Txtlog";
this.Txtlog.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.Txtlog.Size = new System.Drawing.Size(328, 71);
this.Txtlog.TabIndex = 6;
this.Txtlog.TextChanged += new System.EventHandler(this.Txtlog_TextChanged);
//
// mTAPIEx
//
this.mTAPIEx.Enabled = true;
this.mTAPIEx.Location = new System.Drawing.Point(296, 16);
this.mTAPIEx.Name = "mTAPIEx";
this.mTAPIEx.OcxState = ((System.Windows.Forms.AxHost.State)(resources.Get Object("mTAPIEx.OcxState")));
this.mTAPIEx.Size = new System.Drawing.Size(30, 30);
this.mTAPIEx.TabIndex = 7;
this.mTAPIEx.OnRing += new AxTAPIEXLib._ITAPIExEvents_OnRingEventHandler(this .mTapiex_OnRing);
this.mTAPIEx.OnDebug += new AxTAPIEXLib._ITAPIExEvents_OnDebugEventHandler(thi s.mTapiex_OnDebug);
this.mTAPIEx.OnCallerID += new AxTAPIEXLib._ITAPIExEvents_OnCallerIDEventHandler( this.mTapiex_OnCallerID);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(344, 206);
this.Controls.Add(this.mTAPIEx);
this.Controls.Add(this.Txtlog);
this.Controls.Add(this.BnClose);
this.Controls.Add(this.BnOpen);
this.Controls.Add(this.CBLines);
this.Controls.Add(this.LbState);
this.Controls.Add(this.Label2);
this.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Location = new System.Drawing.Point(4, 23);
this.Name = "Form1";
this.Text = "CallerID Demo";
this.Closed += new System.EventHandler(this.Form1_Closed);
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.m TAPIEx)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();

}
#endregion
#region "Upgrade Support "
private static Form1 m_vb6FormDefInstance;
private static bool m_InitializingDefInstance;
public static Form1 DefInstance
{
get{
Form1 returnValue;
if (m_vb6FormDefInstance == null || m_vb6FormDefInstance.IsDisposed)
{
m_InitializingDefInstance = true;
m_vb6FormDefInstance = new Form1();
m_InitializingDefInstance = false;
}
returnValue = m_vb6FormDefInstance;
return returnValue;
}
set
{
m_vb6FormDefInstance = value;
}
}
#endregion
private TAPIEXLib.ITAPILine currLine;
private string phonenumber;
private void BnClose_Click (System.Object eventSender, System.EventArgs eventArgs)
{
currLine.Close();
BnOpen.Enabled = true;
BnClose.Enabled = false;
LbState.Text = "Device closed.";
}

private void BnOpen_Click (System.Object eventSender, System.EventArgs eventArgs)
{
if (CBLines.SelectedIndex >= 0)
{
currLine = mTAPIEx.Lines.Item(CBLines.SelectedIndex);
if (currLine.Open())
{
BnOpen.Enabled = false;
BnClose.Enabled = true;
LbState.Text = "Waiting for a call.";
phonenumber = "";
}
}
}

private void Form1_Load (System.Object eventSender, System.EventArgs eventArgs)
{
TAPIEXLib.ITAPILine line;

mTAPIEx.initialize();

foreach (TAPIEXLib.ITAPILine tempLoopVar_line in mTAPIEx.Lines) //enumerate the line devices
{
line = tempLoopVar_line;
//If line.Caps.CallerIDFlags And 12 Then ' check device Caller supported
CBLines.Items.Add(line.DeviceName);
//End If
}


}

private void Form1_Closed (System.Object eventSender, System.EventArgs eventArgs)
{
mTAPIEx.UnInitialize(); //UnInitialize , free all the resources
}
private void mTapiex_OnCallerID (System.Object eventSender, AxTAPIEXLib._ITAPIExEvents_OnCallerIDEvent eventArgs)
{
//InComing Caller id
LbState.Text = "Caller Name=" + eventArgs.callerName + " Phone Number=" + eventArgs.callerNumber;
phonenumber = eventArgs.callerNumber;
MessageBox.Show(LbState.Text);
}

private void mTapiex_OnDebug (System.Object eventSender, AxTAPIEXLib._ITAPIExEvents_OnDebugEvent eventArgs)
{
Txtlog.Text = Txtlog.Text + eventArgs.msg + Convert.ToChar(13) + Convert.ToChar(10);
}

private void mTapiex_OnRing (System.Object eventSender, AxTAPIEXLib._ITAPIExEvents_OnRingEvent eventArgs)
{
if (eventArgs.ringCount > 2 && phonenumber == "")
{
LbState.Text = "Can not get the caller id, check whether you open incoming CallerID services.";
}
}

private void Txtlog_TextChanged (System.Object sender, System.EventArgs e)
{

}
}
}

NaserHadi
جمعه 07 بهمن 1390, 11:19 صبح
اگه ممکنه اسم و مدل مودم تونو هم بگید تا ما هم تست کنیم