Click here to Skip to main content
15,886,648 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to invoke a button in another app but i can't to do it .. after searched i found only one API can do this .. it is SendMessage API but i can't to ues it ...
i develop an windows app that interact with Viber app ( social application like whatsapp ) . i want to pass number in a text box and click on chat logo to write message then sending it ... any help please

here is my sample code

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace ViberMess
{
    public partial class Form1 : Form
    {

        // Get a handle to an application window.
        [DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
        public static extern IntPtr FindWindow(string lpClassName,
            string lpWindowName);

        // Activate an application window.
        [DllImport("USER32.DLL")]
        public static extern bool SetForegroundWindow(IntPtr hWnd);

        
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // Get a handle to the viber application. The window class 
            // and window name were obtained using the Spy++ tool.
            IntPtr calculatorHandle = FindWindow("Qt5QWindowIcon", "Viber +2xxxxxxxxx");

            // Verify that Viber is a running process. 
            if (calculatorHandle == IntPtr.Zero)
            {
                MessageBox.Show("Viber is not running.");
                return;
            }

            // Make Viber the foreground application and send it  
            // phone number

            SetForegroundWindow(calculatorHandle);
            //Send CTRL+d to open dialled windows
            SendKeys.SendWait("^d");
            
            //Pass phone number
            SendKeys.SendWait("+2010xxxxxxxx");
            //Here is i want to click on message logo then type text and press Enter
            //My problem how to click on message logo to type text
           
        }

        
    }
}
Posted
Updated 18-Mar-15 4:27am
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900