⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 user32.java

📁 一个开源的组件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    	SendMessage.setParameter(pos++, wParam.getValue());
    	SendMessage.setParameter(pos++, lParam.getValue());
    	SendMessage.invoke();
        pos = SendMessage.getRetValAsInt();
        SendMessage.dispose();
    	return new LRESULT(pos);
    }
    
    /*
     if the ImageIcon is not readable by PixelGrabber you need to make use of external libs to generate a valid ImageIcon
     I.e. *.ico images cannot be grabbed. Use i.e. aclibico to generate a valid ImageIcon:
     try {
        if(Class.forName("com.ctreber.aclib.image.ico.ICOFile") != null) {
            final ICOFile lICOFile = new ICOFile(path);
            final Iterator lDescIt = lICOFile.getDescriptors().iterator();
            while (lDescIt.hasNext()) {
                final BitmapDescriptor lDescriptor = (BitmapDescriptor) lDescIt.next();
                final Image img = lDescriptor.getImageRGB();
                if (img != null) { 
                    return new ImageIcon(img);
                }
            }
        }
    } catch(Exception e) {
        e.printStackTrace();
    }   
     **/ 
    public static int[] grabImage(ImageIcon icon) throws InterruptedException {
      
        int w = icon.getIconWidth();
        int h = icon.getIconHeight();
        int[] pixels = new int[w * h];
         
        // Collect pixel data in array
        PixelGrabber pg = new PixelGrabber(icon.getImage(), 0, 0, w, h, pixels, 0, w);
        pg.grabPixels();
        if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
            return null;
        }
        return pixels;
    }
    
    public static LONG CreateIcon(LONG hInstance, int cPlanes, int cBitsPixel, ImageIcon icon) throws InterruptedException, NativeException, IllegalAccessException {
        if(icon == null)
            return new LONG(0);
        int[] pixels = grabImage(icon);
        if(pixels == null)
            return new LONG(0);
        return CreateIcon(hInstance, icon.getIconWidth(), icon.getIconHeight(), cPlanes, cBitsPixel, pixels, pixels);
    }
    
        /*
        HINSTANCE hInstance,
        int nWidth,
        int nHeight,
        BYTE cPlanes,
        BYTE cBitsPixel,
        public static final int BYTE *lpbANDbits,
        public static final int BYTE *lpbXORbits
     */
    public static LONG CreateIcon(LONG hInstance, int nWidth, int nHeight, int cPlanes,
                                    int cBitsPixel, int[] lpbANDbits, int[] lpbXORbits)
                                         throws NativeException, IllegalAccessException {

        JNative createIcon = new JNative(DLL_NAME, "CreateIcon");
        Pointer p = new Pointer(MemoryBlockFactory.createMemoryBlock(lpbXORbits.length*4));
        for(int i = 0; i<lpbXORbits.length; i++) {
            p.setIntAt(i*4,lpbXORbits[i]);
        }
    	createIcon.setRetVal(Type.INT);

        int i = 0;
    	createIcon.setParameter(i++, hInstance.getValue());
    	createIcon.setParameter(i++, nWidth);
        createIcon.setParameter(i++, nHeight);
        createIcon.setParameter(i++, cPlanes);
        createIcon.setParameter(i++, cBitsPixel);
        createIcon.setParameter(i++, p);
        createIcon.setParameter(i++, p);

    	createIcon.invoke();
        i = createIcon.getRetValAsInt();
        createIcon.dispose();

    	return new LONG(i);
    }
    /*
    LONG GetWindowLong( 
        HWND hWnd,
        int nIndex
    );
     */
    
    public static LONG GetWindowLong(HWND hWnd,
                                    int nIndex) throws NativeException, IllegalAccessException {
        
        JNative GetWindowLong = new JNative(DLL_NAME, "GetWindowLongA");
    	GetWindowLong.setRetVal(Type.INT);
    	int pos = 0;
    	GetWindowLong.setParameter(pos++, hWnd.getValue());
    	GetWindowLong.setParameter(pos++, nIndex);
    	GetWindowLong.invoke();
        pos = GetWindowLong.getRetValAsInt();
        GetWindowLong.dispose();
    	return new LONG(pos);
    }
	
	/*
	BOOL WINAPI AttachThreadInput(
		DWORD idAttach,
		DWORD idAttachTo,
		BOOL fAttach
	);
	 */
    public static boolean AttachThreadInput(int idAttach,
											int idAttachTo,
											boolean fAttach)
												throws NativeException, IllegalAccessException {
        JNative AttachThreadInput = new JNative(DLL_NAME, "AttachThreadInput");
    	AttachThreadInput.setRetVal(Type.INT);
    	int pos = 0;
    	AttachThreadInput.setParameter(pos++, idAttach);
		AttachThreadInput.setParameter(pos++, idAttachTo);
		AttachThreadInput.setParameter(pos++, fAttach ? "1" : "0");
    	AttachThreadInput.invoke();
        pos = AttachThreadInput.getRetValAsInt();
        
        AttachThreadInput.dispose();
    	if(pos == 0)
            return false;
        return true;
	}
	/*
	 *HWND GetForegroundWindow(VOID);
	 */
	public static HWND GetForegroundWindow() throws NativeException, IllegalAccessException {
        JNative GetForegroundWindow = new JNative(DLL_NAME, "GetForegroundWindow");
    	GetForegroundWindow.setRetVal(Type.INT);

    	GetForegroundWindow.invoke();
		int ret = GetForegroundWindow.getRetValAsInt();
		GetForegroundWindow.dispose();
        return new HWND(ret);
    }
	
	/*
	 *HWND SetActiveWindow(      
		HWND hWnd
	);
	 */
	public static HWND SetActiveWindow(HWND hWnd) throws NativeException, IllegalAccessException {
        JNative SetActiveWindow = new JNative(DLL_NAME, "SetActiveWindow");
    	SetActiveWindow.setRetVal(Type.INT);
    	int pos = 0;
    	SetActiveWindow.setParameter(pos++, hWnd.getValue());
    	SetActiveWindow.invoke();
        pos = SetActiveWindow.getRetValAsInt();
        
        SetActiveWindow.dispose();
		return new HWND(pos);
     }
	
    /*
     BOOL SetForegroundWindow(      
           HWND hWnd
        );
     */
     public static boolean SetForegroundWindow(HWND hWnd) throws NativeException, IllegalAccessException {
        JNative SetForegroundWindow = new JNative(DLL_NAME, "SetForegroundWindow");
    	SetForegroundWindow.setRetVal(Type.INT);
    	int pos = 0;
    	SetForegroundWindow.setParameter(pos++, hWnd.getValue());
    	SetForegroundWindow.invoke();
        pos = SetForegroundWindow.getRetValAsInt();
        
        SetForegroundWindow.dispose();
    	if(pos == 0)
            return false;
        return true;
     }
	 
	 public static boolean SetForegroundWindowEx(HWND hWnd) throws NativeException, IllegalAccessException {
        int lThreadWindow = GetWindowThreadProcessId(hWnd);
		int lThreadForeWin = GetWindowThreadProcessId(GetForegroundWindow());
		if(lThreadWindow == lThreadForeWin) {			
			return SetForegroundWindow(hWnd);
		} else {
			AttachThreadInput(lThreadForeWin, lThreadWindow, true);
			boolean b = SetForegroundWindow(hWnd);
			AttachThreadInput(lThreadForeWin, lThreadWindow, false);
			return b;
		}
     }
     
     /*
    BOOL DestroyIcon(   
        HICON hIcon
    );
      */
      
     public static boolean DestroyIcon(LONG hIcon) throws NativeException, IllegalAccessException {
        JNative DestroyIcon = new JNative(DLL_NAME, "DestroyIcon");
        DestroyIcon.setRetVal(Type.INT);
        int pos = 0;
        DestroyIcon.setParameter(pos++, hIcon.getValue());
        DestroyIcon.invoke();
        pos = DestroyIcon.getRetValAsInt();

        DestroyIcon.dispose();
        if(pos == 0)
            return false;
        return true;
    }
	 
	 /*
	 UINT RegisterWindowMessage(      
		LPCTSTR lpString
	);
	  **/
    public static int RegisterWindowMessage(String lpString) throws NativeException, IllegalAccessException {
        JNative RegisterWindowMessage = new JNative(DLL_NAME, "RegisterWindowMessageA");
        RegisterWindowMessage.setRetVal(Type.INT);
        int pos = 0;
        RegisterWindowMessage.setParameter(pos++, lpString);
        RegisterWindowMessage.invoke();
        pos = RegisterWindowMessage.getRetValAsInt();

        RegisterWindowMessage.dispose();
        
        return pos;
    }
	
	/*
	 *BOOL SetWindowPos(      
		HWND hWnd,
		HWND hWndInsertAfter,
		int X,
		int Y,
		int cx,
		int cy,
		UINT uFlags
	);
	 **/
	public static boolean SetWindowPos(HWND hWnd,
										HWND hWndInsertAfter,
										int X,
										int Y,
										int cx,
										int cy,
										int uFlags)
												throws NativeException, IllegalAccessException {
        JNative SetWindowPos = new JNative(DLL_NAME, "SetWindowPos");
    	SetWindowPos.setRetVal(Type.INT);
    	int pos = 0;
    	SetWindowPos.setParameter(pos++, hWnd.getValue());
		SetWindowPos.setParameter(pos++, hWndInsertAfter.getValue());
		SetWindowPos.setParameter(pos++, X);
		SetWindowPos.setParameter(pos++, Y);
		SetWindowPos.setParameter(pos++, cx);
		SetWindowPos.setParameter(pos++, cy);
		SetWindowPos.setParameter(pos++, uFlags);
    	SetWindowPos.invoke();
        pos = SetWindowPos.getRetValAsInt();
        
        SetWindowPos.dispose();
    	if(pos == 0)
            return false;
        return true;
	}
	
	public static boolean setOnTop(HWND hWnd) {
		try {
			return User32.SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
		} catch(Exception ee) {
			ee.printStackTrace();
		}
		return false;
	}
	
	/*
	 BOOL RegisterHotKey(      
		HWND hWnd,
		int id,
		UINT fsModifiers,
		UINT vk
	);
	 */
	public static boolean RegisterHotKey(HWND hWnd,
										int id,
										int fsModifiers,
										int vk)
												throws NativeException, IllegalAccessException {
        JNative RegisterHotKey = new JNative(DLL_NAME, "RegisterHotKey");
    	RegisterHotKey.setRetVal(Type.INT);
    	int pos = 0;
    	RegisterHotKey.setParameter(pos++, hWnd.getValue());
		RegisterHotKey.setParameter(pos++, id);
		RegisterHotKey.setParameter(pos++, fsModifiers);
		RegisterHotKey.setParameter(pos++, vk);

    	RegisterHotKey.invoke();
        pos = RegisterHotKey.getRetValAsInt();
        
        RegisterHotKey.dispose();
    	if(pos == 0)
            return false;
        return true;
	}	

	/*
	BOOL UnregisterHotKey(      
		HWND hWnd,
		int id
	);
	*/
	public static boolean UnregisterHotKey(String lpString) throws NativeException, IllegalAccessException {
        JNative UnregisterHotKey = new JNative(DLL_NAME, "UnregisterHotKey");
        UnregisterHotKey.setRetVal(Type.INT);
        int pos = 0;
        UnregisterHotKey.setParameter(pos++, lpString);
        UnregisterHotKey.invoke();
        pos = UnregisterHotKey.getRetValAsInt();

        UnregisterHotKey.dispose();
        if(pos == 0)
            return false;
        return true;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -