Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1108441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:05:00+00:00 2026-05-17T02:05:00+00:00

I am new to WINAPI and have figured out how to send a message

  • 0

I am new to WINAPI and have figured out how to send a message to another program. The program I am using however I would like to be able to have it click on a specific button. From what I have learned by viewing Spy++ windows handles change for the programs every time they are reloaded and so do the handles for their controls. The control ID stays the same. After two days of trying to figure it out I am here.

under SendMesssageA if I specify the current handle as viewable by Spy++ and use that and run the code it works fine and clicks the button on my external application. I am attempting to use GetDlgItem as I have read that I can get the handle for the control (child window) using it. I am doing something wrong however since no matter what I do it returns 0 or ‘null’.

How can I get GetDlgItem to return the child control handle so that I may use it to sendmessage to click that control in the external application?

Thanks for your help an input ahead of time.

    [DllImport("User32.dll")]
    static extern bool SetForegroundWindow(IntPtr hWnd);
    Process[] myProcess = Process.GetProcessesByName("program name here");

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    static extern int SendMessageA(IntPtr hwnd, int wMsg, int wParam, uint lParam);

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern IntPtr GetDlgItem(int hwnd, int childID);

    public const int WM_LBUTTONDOWN = 0x0201;
    public const int WM_LBUTTONUP = 0x0202;


    public void SendClick()
    {
        IntPtr hwnd = myProcess[0].MainWindowHandle;
        SetForegroundWindow(hwnd);

        int intCID = 1389;
        IntPtr ptrTest = GetDlgItem(hwnd, intCID);
        SendKeys.SendWait(" ");
        Thread.Sleep(1000);
        SendKeys.SendWait("various text to be sent here");
        Thread.Sleep(1000);
        SendKeys.SendWait("{ENTER}");
        Thread.Sleep(1000);

        SendMessageA(ptrTest, WM_LBUTTONDOWN, WM_LBUTTONDOWN, 0);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:05:01+00:00Added an answer on May 17, 2026 at 2:05 am

    I think you have to use the Win32 API to find the “receiving” application window, and then find a child window of that handle.
    This is something I found googling Win32 API FindWindow

    http://www.c-sharpcorner.com/UploadFile/shrijeetnair/win32api12062005005528AM/win32api.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pure Winapi application that needs a few new features. One of
New to javascript/jquery and having a hard time with using this or $(this) to
New to silverlight. Traditionally if I were to design a wizard-like process where a
The new extensions in .Net 3.5 allow functionality to be split out from interfaces.
I have a new web app that is packaged as a WAR as part
I have found this example on StackOverflow: var people = new List<Person> { new
I would like to update my SQL lite database with the native update-method of
New class is a subclass of the original object It needs to be php4
New to xml. Looking for XPath to search a xml file with python ElementTree
New to both Ruby and Rails but I'm book educated by now (which apparently

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.