SendMessage(hWnd, Msg, wParam, lParam) 困难 [英] SendMessage(hWnd, Msg, wParam, lParam) difficulties

查看:35
本文介绍了SendMessage(hWnd, Msg, wParam, lParam) 困难的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个程序点击另一个程序上的按钮;我决定使用该功能:

I am trying to make a program click a button on another program; I decided to use the function:

SendMessage(hWndVariable, MsgVariable, wParamVariable, lParamVariable)

但是有一个问题.带有窗口句柄 hWndVariable 的窗口有 3 个按钮.我最初计划在 SendMessage 函数中使用以下参数:

but there is an issue. The window with the window handle hWndVariable has 3 buttons. I initially planned to use the following parameters in the SendMessage function:

SendMessage(hWndVariable, BN_CLICK, 0, 0);

问题:: 但是由于有 3 个按钮,程序如何知道正在单击哪个按钮?大声笑我猜我要么错过了什么,要么做错了什么.

Question:: but since there are 3 buttons, how would the program know which one is being clicked? lol I am guessing that I am either missing something or doing something completely wrong.

推荐答案

SendMessage(hWndVariable, BN_CLICK, 0, 0);

SendMessage(hWndVariable, BN_CLICK, 0, 0);

这就是你的问题.首先,您发送的是一条不存在的消息(您的意思是 BN_CLICKED).其次,您没有正确发送消息.

This is your problem right here. First, you're sending a nonexistent message (you meant BN_CLICKED). Second, you're not sending the message correctly.

之前问题的答案所述,您需要获取按钮的 ID.您可以使用 Spy++ 执行此操作.

As described in answers to your previous questions, you need to get the button's ID. You can do this using Spy++.

然后,根据 BN_CLICKED 文档,您可以像这个一样发送您的消息:

Then, per the BN_CLICKED documentation, you can send your message like this:

SendMessage(parentWindowhWnd, WM_COMMAND, (BN_CLICKED << 16) | BUTTONID, buttonhWnd);

适当填写值 - parentWindowhWnd 是包含按钮的窗口的 HWND,BUTTONID 是按钮的 ID,buttonhWnd 是按钮本身的 HWND.

Fill in the values appropriately - parentWindowhWnd is the HWND of the window containing the button, BUTTONID is the button's ID, and buttonhWnd is the HWND of the button itself.

这篇关于SendMessage(hWnd, Msg, wParam, lParam) 困难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆