Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I want this code to press a button in the calculator app, but it doesn't work.
I've downloaded WinSpy++ to get one of the calculator buttons handle id (006303C8) = the number 8.

What am I doing wrong ?



C#
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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {

        [DllImport("user32.dll")]
        public static extern IntPtr FindWindow(String sClassName, String sAppName);

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

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            // Find and save calculator as thisWindow
            IntPtr thisWindow = FindWindow(null, "Calculator");


            //Press button "8" on calulator app
            SendMessage((int)thisWindow, 006303C8, 0, IntPtr.Zero);




        }
    }
}&lt;/pre&gt;</pre>
Posted
Comments
Sergey Alexandrovich Kryukov 26-Feb-15 15:42pm    
Wasting time on controlling some existing calculator is one of the pretty popular but apparent technological abuse. If you have nothing better to do or lean, I would advise to ask other people. There are too many unsolved problems which are badly needed by people...
—SA
Member 11380736 26-Feb-15 16:01pm    
Controlling the calculator is only for testing. I want to learn how to use WinSpy++ to get button id and then press what ever button I want
Sergey Alexandrovich Kryukov 26-Feb-15 16:39pm    
Well, if you hard-code some messages, it's hard to expect quick success...
—SA

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