{"id":90,"date":"2007-02-22T18:52:47","date_gmt":"2007-02-22T23:52:47","guid":{"rendered":"http:\/\/www.lastdragon.net\/?p=90"},"modified":"2007-02-22T18:52:47","modified_gmt":"2007-02-22T23:52:47","slug":"llamadas-a-las-apis-de-otros-programas-en-c","status":"publish","type":"post","link":"https:\/\/www.lastdragon.net\/?p=90","title":{"rendered":"Llamadas a las APIS de otros programas en C#"},"content":{"rendered":"<p>Este programa es para llamar la atenci\u00f3n, com\u00fanmente 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\u00f3n <\/p>\n<p>Para automatizar esto, he escrito este programa en C#, que de una forma f\u00e1cil permite lo mismo.<\/p>\n<p>Aprovecho para mostrar como llamar servicio de aplicaciones de terceros, en este caso APIs del Messenger, El c\u00f3digo fuente es el siguiente:<\/p>\n<p>\/\/ Parcial 1<\/p>\n<p>using System;<br \/>\nusing System.Collections.Generic;<br \/>\nusing System.Drawing;<br \/>\nusing System.Windows.Forms;<\/p>\n<p>namespace msgpi<br \/>\n{<\/p>\n<p>\tpublic partial class MainForm<br \/>\n\t{<br \/>\n\t\tMessengerAPI.Messenger MSG = new MessengerAPI.Messenger();<\/p>\n<p>\t\t[STAThread]<br \/>\n\t\tpublic static void Main(string[] args)<br \/>\n\t\t{<br \/>\n\t\t\tApplication.EnableVisualStyles();<br \/>\n\t\t\tApplication.SetCompatibleTextRenderingDefault(false);<br \/>\n\t\t\tApplication.Run(new MainForm());<br \/>\n\t\t}<\/p>\n<p>\t\tpublic MainForm()<br \/>\n\t\t{<\/p>\n<p>\t\t}<\/p>\n<p>\t\tvoid Button1Click(object sender, System.EventArgs e)<br \/>\n\t\t{<br \/>\n\t\t\tint veces = System.Convert.ToInt32 (cantidad.Text);<br \/>\n\t\t\tint contador = 0;<\/p>\n<p>\t\t\tif (veces == 0) MessageBox.Show  (&#8220;Revise la cantidad de ventanas a enviar mayor a 0 pero menor a 6&#8243;,&#8221;Mensaje de ERROR:&#8221;,MessageBoxButtons.OK, MessageBoxIcon.Information);<\/p>\n<p>\t\t\tif (veces > 0 &#038;&#038; veces < = 6)\n\t\t\t\t\n\t\t\twhile (contador != veces)\n\t\t\t{\n\t\t\t\tcontador ++;\n\t\t\t\tMSG.MyStatus = MessengerAPI.MISTATUS.MISTATUS_INVISIBLE;\n\t\t\t\tMSG.MyStatus = MessengerAPI.MISTATUS.MISTATUS_ONLINE;\n\t\t\t\t\n\t\t\t}\t\n\t\t}\n\t\t\n\t\tvoid Button1MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)\n\t\t{\n\t\t\tthis.ttip.SetToolTip(this.button1, \"Mensaje a enviar: \" + MSG.MyFriendlyName.ToString());\t\t\t\n\t\t\t\n\t\t}\n\t\t\n\t\tvoid CantidadTextChanged(object sender, System.EventArgs e)\n\t\t{\n\t\t\ttry\n\t\t\t{\n\t\t\tint veces = System.Convert.ToInt32 (cantidad.Text);\n\t\t\tif (veces == 0 || veces > 6) MessageBox.Show  (&#8220;Revise la cantidad de ventanas a enviar mayor a 0 pero menor a 6&#8243;,&#8221;Mensaje de ERROR:&#8221;,MessageBoxButtons.OK, MessageBoxIcon.Information);<br \/>\n\t\t\t}<br \/>\n\t\t\tcatch<br \/>\n\t\t\t{<br \/>\n\t\t\t\tcantidad.Text = &#8220;0&#8221;;<br \/>\n\t\t\t}<br \/>\n\t\t}<br \/>\n\t}<br \/>\n}<\/p>\n<p>\/\/ Parcional 2<\/p>\n<p>namespace msgpi<br \/>\n{<br \/>\n\tpartial class MainForm : System.Windows.Forms.Form<br \/>\n\t{<\/p>\n<p>\t\tprivate System.ComponentModel.IContainer components = null;<\/p>\n<p>\t\tprotected override void Dispose(bool disposing)<br \/>\n\t\t{<br \/>\n\t\t\tif (disposing) {<br \/>\n\t\t\t\tif (components != null) {<br \/>\n\t\t\t\t\tcomponents.Dispose();<br \/>\n\t\t\t\t}<br \/>\n\t\t\t}<br \/>\n\t\t\tbase.Dispose(disposing);<br \/>\n\t\t}<\/p>\n<p>\t\tprivate void InitializeComponent()<br \/>\n\t\t{<br \/>\n\t\t\tthis.components = new System.ComponentModel.Container();<br \/>\n\t\t\tSystem.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));<br \/>\n\t\t\tthis.button1 = new System.Windows.Forms.Button();<br \/>\n\t\t\tthis.label1 = new System.Windows.Forms.Label();<br \/>\n\t\t\tthis.cantidad = new System.Windows.Forms.TextBox();<br \/>\n\t\t\tthis.ttip = new System.Windows.Forms.ToolTip(this.components);<br \/>\n\t\t\tthis.label2 = new System.Windows.Forms.Label();<br \/>\n\t\t\tthis.label3 = new System.Windows.Forms.Label();<br \/>\n\t\t\tthis.SuspendLayout();<br \/>\n\t\t\t\/\/<br \/>\n\t\t\t\/\/ button1<br \/>\n\t\t\t\/\/<br \/>\n\t\t\tthis.button1.Location = new System.Drawing.Point(72, 119);<br \/>\n\t\t\tthis.button1.Name = &#8220;button1&#8221;;<br \/>\n\t\t\tthis.button1.Size = new System.Drawing.Size(106, 29);<br \/>\n\t\t\tthis.button1.TabIndex = 0;<br \/>\n\t\t\tthis.button1.Tag = &#8220;&#8221;;<br \/>\n\t\t\tthis.button1.Text = &#8220;Enviar Ventanas&#8221;;<br \/>\n\t\t\tthis.button1.UseVisualStyleBackColor = true;<br \/>\n\t\t\tthis.button1.Click += new System.EventHandler(this.Button1Click);<br \/>\n\t\t\tthis.button1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Button1MouseMove);<br \/>\n\t\t\t\/\/<br \/>\n\t\t\t\/\/ label1<br \/>\n\t\t\t\/\/<br \/>\n\t\t\tthis.label1.AutoSize = true;<br \/>\n\t\t\tthis.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;<br \/>\n\t\t\tthis.label1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;<br \/>\n\t\t\tthis.label1.Font = new System.Drawing.Font(&#8220;Arial&#8221;, 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));<br \/>\n\t\t\tthis.label1.Location = new System.Drawing.Point(38, 69);<br \/>\n\t\t\tthis.label1.Name = &#8220;label1&#8221;;<br \/>\n\t\t\tthis.label1.Size = new System.Drawing.Size(166, 20);<br \/>\n\t\t\tthis.label1.TabIndex = 1;<br \/>\n\t\t\tthis.label1.Text = &#8220;Cantidad de Ventanas&#8221;;<br \/>\n\t\t\t\/\/<br \/>\n\t\t\t\/\/ cantidad<br \/>\n\t\t\t\/\/<br \/>\n\t\t\tthis.cantidad.Location = new System.Drawing.Point(109, 92);<br \/>\n\t\t\tthis.cantidad.Name = &#8220;cantidad&#8221;;<br \/>\n\t\t\tthis.cantidad.Size = new System.Drawing.Size(27, 21);<br \/>\n\t\t\tthis.cantidad.TabIndex = 2;<br \/>\n\t\t\tthis.cantidad.Text = &#8220;0&#8221;;<br \/>\n\t\t\tthis.cantidad.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;<br \/>\n\t\t\tthis.cantidad.TextChanged += new System.EventHandler(this.CantidadTextChanged);<br \/>\n\t\t\t\/\/<br \/>\n\t\t\t\/\/ label2<br \/>\n\t\t\t\/\/<br \/>\n\t\t\tthis.label2.AutoSize = true;<br \/>\n\t\t\tthis.label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;<br \/>\n\t\t\tthis.label2.Location = new System.Drawing.Point(26, 9);<br \/>\n\t\t\tthis.label2.Name = &#8220;label2&#8221;;<br \/>\n\t\t\tthis.label2.Size = new System.Drawing.Size(211, 28);<br \/>\n\t\t\tthis.label2.TabIndex = 3;<br \/>\n\t\t\tthis.label2.Text = &#8220;Programa para llamar la atenci\u00f3n,\\r\\nusando ventanas de ingreso al Messenger\\r\\n&#8221;;<br \/>\n\t\t\t\/\/<br \/>\n\t\t\t\/\/ label3<br \/>\n\t\t\t\/\/<br \/>\n\t\t\tthis.label3.AutoSize = true;<br \/>\n\t\t\tthis.label3.Location = new System.Drawing.Point(12, 165);<br \/>\n\t\t\tthis.label3.Name = &#8220;label3&#8221;;<br \/>\n\t\t\tthis.label3.Size = new System.Drawing.Size(138, 39);<br \/>\n\t\t\tthis.label3.TabIndex = 4;<br \/>\n\t\t\tthis.label3.Text = &#8220;Programado por:\\r\\nLast Dragon. en\\r\\nhttps:\/\/www.lastdragon.net&#8221;;<br \/>\n\t\t\t\/\/<br \/>\n\t\t\t\/\/ MainForm<br \/>\n\t\t\t\/\/<br \/>\n\t\t\tthis.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);<br \/>\n\t\t\tthis.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;<br \/>\n\t\t\tthis.ClientSize = new System.Drawing.Size(249, 212);<br \/>\n\t\t\tthis.Controls.Add(this.label3);<br \/>\n\t\t\tthis.Controls.Add(this.label2);<br \/>\n\t\t\tthis.Controls.Add(this.cantidad);<br \/>\n\t\t\tthis.Controls.Add(this.label1);<br \/>\n\t\t\tthis.Controls.Add(this.button1);<br \/>\n\t\t\tthis.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;<br \/>\n\t\t\tthis.Icon = ((System.Drawing.Icon)(resources.GetObject(&#8220;$this.Icon&#8221;)));<br \/>\n\t\t\tthis.MaximizeBox = false;<br \/>\n\t\t\tthis.Name = &#8220;MainForm&#8221;;<br \/>\n\t\t\tthis.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;<br \/>\n\t\t\tthis.Tag = &#8220;&#8221;;<br \/>\n\t\t\tthis.Text = &#8220;Ventanas Messenger&#8221;;<br \/>\n\t\t\tthis.ResumeLayout(false);<br \/>\n\t\t\tthis.PerformLayout();<br \/>\n\t\t}<br \/>\n\t\tprivate System.Windows.Forms.Label label3;<br \/>\n\t\tprivate System.Windows.Forms.Label label2;<br \/>\n\t\tprivate System.Windows.Forms.ToolTip ttip;<br \/>\n\t\tprivate System.Windows.Forms.TextBox cantidad;<br \/>\n\t\tprivate System.Windows.Forms.Label label1;<br \/>\n\t\tprivate System.Windows.Forms.Button button1;<br \/>\n\t}<br \/>\n}<\/p>\n<p>El coraz\u00f3n de este programa esta en solo 3 l\u00edneas, el resto del c\u00f3digo es la programaci\u00f3n visual de interfase con el usuario ventanas, eventos, etc, etc.<\/p>\n<p>1 Se referencia a la DLL del API<\/p>\n<p>Se crea el objeto MSG<\/p>\n<p>MessengerAPI.Messenger MSG = new MessengerAPI.Messenger();<\/p>\n<p>Ya con el MSG, podemos modificar el comportamiento del Messenger, en el codigo hay otras 2 lineas que estan dentro de un bucle<\/p>\n<p>MSG.MyStatus = MessengerAPI.MISTATUS.MISTATUS_INVISIBLE;<br \/>\nMSG.MyStatus = MessengerAPI.MISTATUS.MISTATUS_ONLINE;<\/p>\n<p>Estas l\u00edneas son las que hacen el efecto de invisible y online, el bucle determina el numero de veces.<\/p>\n<p>La apariencia del programa ejecutandose es la siguiente.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.lastdragon.net\/\/misarchivos\/msgventanas\/msgvejem.jpg\" alt=\"Ejemplo del programa MSGVentanas\" \/><\/p>\n<p>El siguiente archivo auto extra\u00edble contiene una versi\u00f3n precompilada del programa descrito, adem\u00e1s del c\u00f3digo fuente, requiere Framework .NET 2.0 para ejecutarse correctamente.<\/p>\n<p><a href=\"https:\/\/www.lastdragon.net\/\/misarchivos\/msgventanas\/msgventana.exe\">Descargar<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Este programa es para llamar la atenci\u00f3n, com\u00fanmente 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\u00f3n Para automatizar esto, he escrito este programa en C#, que de una forma f\u00e1cil permite lo mismo. Aprovecho para mostrar&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-90","post","type-post","status-publish","format-standard","hentry","category-programacion"],"_links":{"self":[{"href":"https:\/\/www.lastdragon.net\/index.php?rest_route=\/wp\/v2\/posts\/90","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lastdragon.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lastdragon.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lastdragon.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lastdragon.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=90"}],"version-history":[{"count":0,"href":"https:\/\/www.lastdragon.net\/index.php?rest_route=\/wp\/v2\/posts\/90\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.lastdragon.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=90"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lastdragon.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=90"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lastdragon.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=90"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}