0
Reply

humble question with API

blah

blah

Feb 9 2006 5:42 AM
1.7k

hello everyone, Ive been trying to get my application to work for a long time now. its basically a practice app where if I click my button then it will "click" a button on another application. the problem is now my code compiles fine, but when I run it it doesnt finish the job. when the user clicks the button with his mouse, the program puts the specified window to the foreground and then clicks the button on that form. thats all. Ive tried all kinds of things but nothing works. here is the code I have in the form.cs file, can anyone show me what the problem is??
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace test
{
    public partial class Form1 : Form
    {
///
        public Form1()
        {
            InitializeComponent();
        }

        public class Win32
        {
            [DllImport("user32", EntryPoint = "GetNextWindow")]
            public static extern int
            GetWindow(IntPtr hwnd, int wFlag);
            public const int BM_CLICK = 0x00F5;
            [DllImport("user32.dll")]
            public static extern int FindWindow(string lpClass, string lpWindow);

            [DllImport("user32.dll")]
            public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);

        }
        private void button1_Click(object sender, EventArgs e)
        {
            int hWnd;
            hWnd = Win32API.FindWindow(Class1.Text, caption.Text);
                Win32API.SetForegroundWindow(hWnd);
                //hWnd = Win32.FindWindow(Class1.Text, caption.Text);
                Win32.SendMessage(hWnd, Win32.BM_CLICK, 0, 0);
                //System.Windows.Forms.SendKeys.Send("Enter");
           
        }
    }
}

any help would be very much appreciated since its taken so long for me to solve this. SendKeys works fine by the way, at least for the textbox but Id like to use the API since later I want to communicate with specific buttons and textboxes. thanks again