Llamadas a las APIS de otros programas en C#
By: Date: febrero 22, 2007 Categories: Programación

Este programa es para llamar la atención, comúnmente los usuarios en el MSG cambian su estado de invisible a online para que a sus contactos le aparezca una cascada de ventanas de inicio de sesión

Para automatizar esto, he escrito este programa en C#, que de una forma fácil permite lo mismo.

Aprovecho para mostrar como llamar servicio de aplicaciones de terceros, en este caso APIs del Messenger, El código fuente es el siguiente:

// Parcial 1

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace msgpi
{

public partial class MainForm
{
MessengerAPI.Messenger MSG = new MessengerAPI.Messenger();

[STAThread]
public static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}

public MainForm()
{

}

void Button1Click(object sender, System.EventArgs e)
{
int veces = System.Convert.ToInt32 (cantidad.Text);
int contador = 0;

if (veces == 0) MessageBox.Show (“Revise la cantidad de ventanas a enviar mayor a 0 pero menor a 6″,”Mensaje de ERROR:”,MessageBoxButtons.OK, MessageBoxIcon.Information);

if (veces > 0 && veces < = 6) while (contador != veces) { contador ++; MSG.MyStatus = MessengerAPI.MISTATUS.MISTATUS_INVISIBLE; MSG.MyStatus = MessengerAPI.MISTATUS.MISTATUS_ONLINE; } } void Button1MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { this.ttip.SetToolTip(this.button1, "Mensaje a enviar: " + MSG.MyFriendlyName.ToString()); } void CantidadTextChanged(object sender, System.EventArgs e) { try { int veces = System.Convert.ToInt32 (cantidad.Text); if (veces == 0 || veces > 6) MessageBox.Show (“Revise la cantidad de ventanas a enviar mayor a 0 pero menor a 6″,”Mensaje de ERROR:”,MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch
{
cantidad.Text = “0”;
}
}
}
}

// Parcional 2

namespace msgpi
{
partial class MainForm : System.Windows.Forms.Form
{

private System.ComponentModel.IContainer components = null;

protected override void Dispose(bool disposing)
{
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}

private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.cantidad = new System.Windows.Forms.TextBox();
this.ttip = new System.Windows.Forms.ToolTip(this.components);
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(72, 119);
this.button1.Name = “button1”;
this.button1.Size = new System.Drawing.Size(106, 29);
this.button1.TabIndex = 0;
this.button1.Tag = “”;
this.button1.Text = “Enviar Ventanas”;
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.Button1Click);
this.button1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Button1MouseMove);
//
// label1
//
this.label1.AutoSize = true;
this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.label1.Font = new System.Drawing.Font(“Arial”, 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.Location = new System.Drawing.Point(38, 69);
this.label1.Name = “label1”;
this.label1.Size = new System.Drawing.Size(166, 20);
this.label1.TabIndex = 1;
this.label1.Text = “Cantidad de Ventanas”;
//
// cantidad
//
this.cantidad.Location = new System.Drawing.Point(109, 92);
this.cantidad.Name = “cantidad”;
this.cantidad.Size = new System.Drawing.Size(27, 21);
this.cantidad.TabIndex = 2;
this.cantidad.Text = “0”;
this.cantidad.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.cantidad.TextChanged += new System.EventHandler(this.CantidadTextChanged);
//
// label2
//
this.label2.AutoSize = true;
this.label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label2.Location = new System.Drawing.Point(26, 9);
this.label2.Name = “label2”;
this.label2.Size = new System.Drawing.Size(211, 28);
this.label2.TabIndex = 3;
this.label2.Text = “Programa para llamar la atención,\r\nusando ventanas de ingreso al Messenger\r\n”;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 165);
this.label3.Name = “label3”;
this.label3.Size = new System.Drawing.Size(138, 39);
this.label3.TabIndex = 4;
this.label3.Text = “Programado por:\r\nLast Dragon. en\r\nhttps://www.lastdragon.net”;
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(249, 212);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.cantidad);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject(“$this.Icon”)));
this.MaximizeBox = false;
this.Name = “MainForm”;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Tag = “”;
this.Text = “Ventanas Messenger”;
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ToolTip ttip;
private System.Windows.Forms.TextBox cantidad;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
}
}

El corazón de este programa esta en solo 3 líneas, el resto del código es la programación visual de interfase con el usuario ventanas, eventos, etc, etc.

1 Se referencia a la DLL del API

Se crea el objeto MSG

MessengerAPI.Messenger MSG = new MessengerAPI.Messenger();

Ya con el MSG, podemos modificar el comportamiento del Messenger, en el codigo hay otras 2 lineas que estan dentro de un bucle

MSG.MyStatus = MessengerAPI.MISTATUS.MISTATUS_INVISIBLE;
MSG.MyStatus = MessengerAPI.MISTATUS.MISTATUS_ONLINE;

Estas líneas son las que hacen el efecto de invisible y online, el bucle determina el numero de veces.

La apariencia del programa ejecutandose es la siguiente.

Ejemplo del programa MSGVentanas

El siguiente archivo auto extraíble contiene una versión precompilada del programa descrito, además del código fuente, requiere Framework .NET 2.0 para ejecutarse correctamente.

Descargar

6 thoughts on “Llamadas a las APIS de otros programas en C#

  1. Unknown browser

    Hola, que padre programa me encanto jejejeje!!! Tu si que sabes programar, felicidades!!! esta interesante las aplicaciones que haces muy bien!!!

  2. Mozilla Firefox 3.0.1 Windows XP

    Hola que tal estoy usando esta misma api pero tengo problemas para cambiar mi nickname me dise

    “Property or indexer ‘MessengerAPI.IMessenger3.MyFriendlyName’ cannot be assigned to — it is read only”

    si me puedes hechar la mano te lo agradeceria muchho… bye

    gera_pappas@hotmail.com

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *