通过Windows消息队列对VB程序进行操作

本文介绍了一种使用Java Native Access (JNA) 库操作Windows DLL的方法,通过调用DLL函数获取VB应用程序窗口句柄,并向其消息队列发送消息,实现了跨语言的窗口程序交互。

运用JNA来操作DLL函数,获取VB窗口程序句柄,进而向VB程序窗口程序的消息队列发送消息,代码如下:

package com.stupidzhe;

import com.sun.jna.Native;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinUser;
import java.util.concurrent.TimeUnit;

public class JnaTest {

    public static void main(String[] args) throws InterruptedException {
        char[] windowText = new char[512];
        HWND hwnd = User32.INSTANCE.GetForegroundWindow(); // then you can call it!
        User32.INSTANCE.GetWindowText(hwnd, windowText, 512);
        System.out.println(Native.toString(windowText));
        HWND btn = User32.INSTANCE.FindWindowEx(hwnd, null, null, null);
        WinUser.MSG msg = new WinUser.MSG();
        int result;

        while (true) {
            WinDef.LRESULT res = User32.INSTANCE.SendMessage(btn, 0xF5, new WinDef.WPARAM(0), new WinDef.LPARAM(0));
            User32.INSTANCE.GetWindowText(btn, windowText, 512);
            System.out.println(Native.toString(windowText));
            TimeUnit.SECONDS.sleep(2);
        }
    }
}

转载于:https://my.oschina.net/StupidZhe/blog/3043373

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值