ITeye博客

JNA 闪烁 JFrame

genius · 2010-12-16 16:48 · JAVA · 编程语言 · Markdown

下面是代码,附件是二个jar文件

 

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewJFrame.java
 *
 * Created on 2010-12-16, 6:55:38
 */

package jna;

import com.sun.jna.Native;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinUser.FLASHWINFO;
import com.sun.jna.win32.StdCallLibrary;

/**
 *
 * @author Administrator
 */
public class NewJFrame extends javax.swing.JFrame {

    /** Creates new form NewJFrame */
    public NewJFrame() {

        initComponents();
                this.setTitle("AAAss");
                 User32 user32 = (User32) Native.loadLibrary ("user32",User32.class);
        char[] windowText = new char[512];

        HWND wnd = user32.INSTANCE.FindWindow(null, "AAAss");
        user32.INSTANCE.GetWindowText(wnd, windowText, 512);
        System.out.println(Native.toString(windowText));
        FLASHWINFO flashInfo=new FLASHWINFO();
        flashInfo.hWnd=wnd;
        flashInfo.dwFlags = 0x00000003;
        flashInfo.uCount = 1000000;
        flashInfo.dwTimeout = 0;
        flashInfo.cbSize =20;

       System.out.println( user32.INSTANCE.FlashWindowEx(flashInfo));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NewJFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}
interface User32s extends StdCallLibrary {
    User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class);

    boolean FlashWindowEx(FLASHWINFO flashWInfo);
}

评论(1)

  1. #1 楼 · laiwq · 2011-04-28 18:18

    谢谢,提供很好的一个JNA实例

评论功能维护中,当前仅展示历史评论。