5,401,186 members and growing! (16,300 online)
Email Password   helpLost your password?
Languages » C# » Beginners     Intermediate License: The Code Project Open License (CPOL)

Skype Smiley Sender

By Giorgi Dalakishvili

An article on sending many smileys simultaneously with Skype
C# 2.0, C#, Windows, .NETVisual Studio, VS2005, Dev

Posted: 24 May 2007
Updated: 22 Oct 2007
Views: 20,541
Bookmarked: 13 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
19 votes for this Article.
Popularity: 4.34 Rating: 3.40 out of 5
3 votes, 15.8%
1
1 vote, 5.3%
2
2 votes, 10.5%
3
2 votes, 10.5%
4
11 votes, 57.9%
5
Screenshot - smileysender1.gif

Contents

Introduction

With this code, you can send as many as smileys you wish in Skype with only one click. There are 999 smileys in the picture below and they were all sent with just one click. Cool, isn't it?

Screenshot - smileysender2.png

How the Program Works

As you probably know, there is a Skype API which allows developers to create applications that work together with Skype. There is also a wrapper around the Skype API called Skype4COM. Apart from this, there is an ActiveX control for working with Skype contacts. It allows you to add a Skype main window and a contact list on the form. My program uses this ActiveX control to connect to Skype and send smileys.

As you probably also know, every smiley has its own code, so when you type that code, the smiley is inserted. The user chooses the smiley to send, chooses the contact and enters the desired number of smileys. After the user clicks the send button, the program builds the string to send and then sends it. The string that is built consists of the smiley code duplicated the necessary number of times. For example, if the user chooses the :) smiley and enters 5, then the constructed string looks like this: :):):):):)

I limited the number of smileys to send because if the number is too big, this program and/or Skype might hang. Multi-threading can be used to avoid this, but nothing can be done with Skype. This program can be minimized to the system tray, so it is quite convenient to use. If you can't make the program work, then try running the reg.bat file.

Using the Code

This is the function that constructs the string of smileys to be sent:

private string duplicate(string smileycode, int smileynumber)
{
    StringCollection codes = new StringCollection();
    StringBuilder duplicatedcode = new StringBuilder(
        smileycode.Length * smileynumber, smileycode.Length*smileynumber);
    StringBuilder smiley = new StringBuilder(smileycode);

    while (smileynumber > 0)
    {
        if (smileynumber % 2 == 1)
        {
            codes.Add(smiley.ToString());
        }

    smileynumber = smileynumber / 2;
    smiley.Append(smiley);
    }

    for (int i = 0; i < codes.Count; i++)
    {
        duplicatedcode.Append(codes[i]);
    }

    return duplicatedcode.ToString();
}

In this function, smileycode is the code for one smiley and smileynumber is the number of times this smiley is to be sent. After the string has been constructed, sending it to the recipient is very easy:

private void send()
{
    string codes = duplicate(sm[this.comboBox1.SelectedIndex], 
        int.Parse(this.textBox1.Text));
    SKYPE4COMLib.Chat ch = axSkypeContactList1.OpenChat(codes);
    this.button1.Enabled = false;
    Thread.Sleep(1000);
    this.button1.Enabled = true;
}

Minimizing to the system tray is easy, too. You will need notifyicon and two event handles. The first one is the resize event of the form:

//if the form is minimized hide it

private void Form1_Resize(object sender, EventArgs e)
{
    if (this.WindowState==FormWindowState.Minimized)
    {
        this.Hide();
    }
}

The second one is the click event of notifyicon:

// if the form is minimized restore it else minimize it.

private void notifyIcon1_Click(object sender, EventArgs e)
{
    if (this.WindowState==FormWindowState.Minimized)
    {
        this.Show();
        this.WindowState = FormWindowState.Normal;
        this.Focus();
        return;
    }

    if (this.WindowState==FormWindowState.Normal)
    {
        this.WindowState = FormWindowState.Minimized;
    }
}

Points of Interest

  • The function that builds the string is very fast, as it uses the StringBuilder class and the StringCollection class.
  • I have discovered that when you send more than 300 smileys to someone, only the last 300 are animated.

Useful Links

Here are some links that you might find interesting:

History

  • 24 May, 2007 - Initial release
  • 5 June, 2007 - Fixed the bug that allowed entry of nonnumeric values for the number of smileys
  • 22 October, 2007 - Article content updated

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Giorgi Dalakishvili


Mvp

Occupation: Software Developer
Location: Georgia Georgia

Other popular C# articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 8 of 8 (Total in Forum: 8) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralCan't run the code that was postedmemberjhanks10:23 12 Jun '07  
GeneralRe: Can't run the code that was postedmemberGiorgi Dalakishvili10:32 12 Jun '07  
GeneralRe: Can't run the code that was postedmemberjhanks10:40 12 Jun '07  
GeneralRe: Can't run the code that was postedmemberGiorgi Dalakishvili10:46 12 Jun '07  
GeneralWhat the?memberGerard Nicol21:04 24 May '07  
GeneralRe: What the?memberGiorgi Dalakishvili5:22 25 May '07  
GeneralRe: What the?memberFatMooseHenry4:43 6 Aug '07  
GeneralRe: What the?memberlogan133712:51 22 Oct '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 22 Oct 2007
Editor: Genevieve Sovereign
Copyright 2007 by Giorgi Dalakishvili
Everything else Copyright © CodeProject, 1999-2008
Web20 | Advertise on the Code Project