Click here to Skip to main content
15,665,229 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
C# Visual Studio windows form...

I'm experimenting on how to access other applications. I want to be able to click other application buttons through my program.

I can't get this code right!
It should click the number 2 in the calculator, but it clicks the "," sign.

WinSpy++ shows that the CONTROL ID of the button 2 is 00000084

Here is the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication2
    public partial class Form1 : Form

    public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);

    static extern int FindWindow(string lpClassName, string lpWindowName);

        public Form1()

        private void Form1_Load(object sender, EventArgs e)
            const int WM_COMMAND = 0x0111;

            int thisWindow = FindWindow("CalcFrame", "Calculator");

            SendMessage(thisWindow, WM_COMMAND, 00000084, 0);


Richard MacCutchan 28-Feb-15 5:35am    
Are you sure that is not supposed to be Hex 84 (0x84)?
Member 11380736 28-Feb-15 6:57am    
Is it the same syntax if it's not a windows app ?
Member 11380736 28-Feb-15 5:37am    
your a genius!!!

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