using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using SKYPE4COMLib; using System.Collections; namespace Skype { /// <summary> /// 20120804 塗聚文 /// 締友計算機信息技術有限公司 /// Geovin Du geovindu@163.com /// </summary> public partial class Form1 : Form { string strskypeuser = string.Empty; string strskypeid = string.Empty; SKYPE4COMLib.Skype oSkype = new SKYPE4COMLib.Skype(); /// <summary> /// /// </summary> public Form1() { InitializeComponent(); } /// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { //不能發送文件在WEB上可以用 //string file = @"E:\金蝶KIS系列产品简介.xls"; //oSkype.Client.OpenFileTransferDialog(strskypeid, file);//打開發送文件 oSkype.SendMessage(strskypeid, strskypeuser + ":" + textBox1.Text); } /// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Form1_Load(object sender, EventArgs e) { if (oSkype.Client.IsRunning == false)//判断客户端是否运行 { //是否能免費提供登錄調用的API?不管是DESKTOP或是WEB oSkype.Client.Start(true, true);//運行 MessageBox.Show("請登錄SKPYE再重新操作", "請注意"); return; } else { this.listBox1.DataSource = skyuselist(); this.listBox1.DisplayMember = "userDisplayName"; this.listBox1.ValueMember = "userLoginName"; } ////初始化物件,預設會抓本機的Skype帳號資訊 //SKYPE4COMLib.Skype oSkype = new SKYPE4COMLib.Skype(); //UserCollection tFriends = oSkype.Friends; ////取出所有的朋友資訊 //foreach (User tUser in oSkype.Friends) //{ // if (tUser.FullName.Trim() != "") // { // ListItem newItem = new ListItem(tUser.Handle, tUser.FullName); // listBox1.Items.Add(newItem); // this.listBox1.DisplayMember = "Name"; // this.listBox1.ValueMember = "ID"; // //listBox1.Items.Add(tUser.Handle);//賬號 //tUser.FullName //昵稱 // //listBox1.Items.AddRange(tUser.FullName); // } //} } /// <summary> /// /// </summary> /// <returns></returns> private DataTable skyuselist() { DataTable d = new DataTable(); //初始化物件,預設會抓本機的Skype帳號資訊 //SKYPE4COMLib.Skype oSkype = new SKYPE4COMLib.Skype(); UserCollection tFriends = oSkype.Friends; d.Columns.Add("userLoginName", typeof(string)); d.Columns.Add("userDisplayName", typeof(string)); //取出所有的朋友資訊 foreach (User tUser in oSkype.Friends) { if (tUser.FullName.Trim() != "") { //ListItem newItem = new ListItem(tUser.Handle, tUser.FullName); //listBox1.Items.Add(newItem); //this.listBox1.DisplayMember = "Name"; //this.listBox1.ValueMember = "ID"; //listBox1.Items.Add(tUser.Handle);//賬號 //tUser.FullName //昵稱 //listBox1.Items.AddRange(tUser.FullName); d.Rows.Add(tUser.Handle, tUser.FullName); } else { d.Rows.Add(tUser.Handle, tUser.Handle); } } d.Rows.Add("geovindu", "geovindu"); return d; } /// <summary> /// 選擇SKYPE用戶 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void listBox1_Click(object sender, EventArgs e) { strskypeuser= this.listBox1.Text; strskypeid = this.listBox1.SelectedValue.ToString(); MessageBox.Show(strskypeuser+","+strskypeid); }