📄 user32.java
字号:
package org.xvolks.jnative.util;
import java.awt.image.ImageObserver;
import java.awt.image.PixelGrabber;
import javax.swing.ImageIcon;
import org.xvolks.jnative.JNative;
import org.xvolks.jnative.Type;
import org.xvolks.jnative.exceptions.NativeException;
import org.xvolks.jnative.misc.MSG;
import org.xvolks.jnative.misc.WNDCLASS;
import org.xvolks.jnative.misc.basicStructures.DC;
import org.xvolks.jnative.misc.basicStructures.HWND;
import org.xvolks.jnative.misc.basicStructures.ICONINFO;
import org.xvolks.jnative.misc.basicStructures.LONG;
import org.xvolks.jnative.misc.basicStructures.LPARAM;
import org.xvolks.jnative.misc.basicStructures.LRESULT;
import org.xvolks.jnative.misc.basicStructures.UINT;
import org.xvolks.jnative.misc.basicStructures.WPARAM;
import org.xvolks.jnative.pointers.Pointer;
import org.xvolks.jnative.pointers.memory.MemoryBlockFactory;
/**
* User32 this is the class wrapper to User32.dll.<br>
* When a developper needs a function of this DLL (s)he should add it here.
*
* $Id: User32.java,v 1.25 2007/04/27 18:42:03 thubby Exp $;
*
* This software is released under the LGPL.
* @author Created by Marc DENTY - (c) 2006 JNative project
*/
public class User32 {
public static final String DLL_NAME = "User32.dll";
private static JNative nEnumWindows;
private static JNative nGetWindowText;
private static Pointer nBufferGWT;
private static JNative getProcessHandle;
public static final int SWP_NOMOVE = 2;
public static final int SWP_NOSIZE = 1;
public static final int SWP_HIDEWINDOW = 0x80;
public static final int SWP_SHOWWINDOW = 0x40;
public static final HWND HWND_TOP = new HWND(0);
public static final HWND HWND_TOPMOST = new HWND(-1);
public static final HWND HWND_NOTOPMOST = new HWND(-2);
public static final int IDI_APPLICATION = 32512;
public static final int IDI_ASTERISK = 32516;
public static final int IDI_ERROR = 32513;
public static final int IDI_EXCLAMATION = 32515;
public static final int IDI_HAND = IDI_ERROR;
public static final int IDI_INFORMATION = IDI_ASTERISK;
public static final int IDI_QUESTION = 32514;
public static final int IDI_WARNING = IDI_EXCLAMATION;
public static final int IDI_WINLOGO = 32517; // IDI_APPLICATION on WinXP
public static final int IDI_SHIELD = 32518; // Vista only
public static final int WM_HOTKEY = 0x312;
public static final int GWL_WNDPROC = (-4);
public static final int MOD_ALT = 0x1;
public static final int MOD_CONTROL = 0x2;
public static final int MOD_SHIFT = 0x4;
public static final int MOD_WIN = 0x8;
/*
*HWND GetDesktopWindow(VOID);
*/
public static HWND GetDesktopWindow()
throws NativeException, IllegalAccessException {
JNative GetDesktopWindow = new JNative(DLL_NAME, "GetDesktopWindow");
try {
GetDesktopWindow.setRetVal(Type.INT);
GetDesktopWindow.invoke();
return new HWND(GetDesktopWindow.getRetValAsInt());
} finally {
if(GetDesktopWindow != null)
GetDesktopWindow.dispose();
}
}
/*
*BOOL GetIconInfo(
HICON hIcon,
PICONINFO piconinfo
);
*/
public static boolean GetIconInfo(LONG hIcon, ICONINFO piconinfo)
throws NativeException, IllegalAccessException {
JNative GetIconInfo = new JNative(DLL_NAME, "GetIconInfo");
try {
GetIconInfo.setRetVal(Type.INT);
GetIconInfo.setParameter(0, hIcon.getValue());
GetIconInfo.setParameter(1, piconinfo.getPointer());
GetIconInfo.invoke();
return (GetIconInfo.getRetValAsInt() != 0);
} finally {
if(GetIconInfo != null)
GetIconInfo.dispose();
}
}
/*
int ReleaseDC(
HWND hWnd, // handle to window
HDC hDC // handle to DC
);
*/
public static int ReleaseDC(HWND hwnd, DC hdc)
throws NativeException, IllegalAccessException {
JNative ReleaseDC = new JNative(DLL_NAME, "ReleaseDC");
try {
ReleaseDC.setRetVal(Type.INT);
ReleaseDC.setParameter(0, hwnd.getValue());
ReleaseDC.setParameter(0, hdc.getValue());
ReleaseDC.invoke();
return ReleaseDC.getRetValAsInt();
} finally {
if(ReleaseDC != null)
ReleaseDC.dispose();
}
}
/*
HDC GetDC(
HWND hWnd // handle to window
);
**/
public static DC GetDC(HWND hwnd)
throws NativeException, IllegalAccessException {
JNative GetDC = new JNative(DLL_NAME, "GetDC");
try {
GetDC.setRetVal(Type.INT);
GetDC.setParameter(0, hwnd.getValue());
GetDC.invoke();
return new DC(GetDC.getRetValAsInt());
} finally {
if(GetDC != null)
GetDC.dispose();
}
}
public static int GetWindowThreadProcessId(final HWND hwnd) {
if(hwnd == null)
return -1;
Pointer nBufferGWT = null;
try {
if(getProcessHandle == null) {
getProcessHandle = new JNative("User32.dll","GetWindowThreadProcessId");
getProcessHandle.setRetVal(Type.INT);
}
nBufferGWT = new Pointer(MemoryBlockFactory.createMemoryBlock(4));
getProcessHandle.setParameter(0, hwnd.getValue());
getProcessHandle.setParameter(1, nBufferGWT);
getProcessHandle.invoke();
return nBufferGWT.getAsInt(0);
} catch(Exception e) {
e.printStackTrace();
} finally {
try {
if(nBufferGWT != null)
nBufferGWT.dispose();
nBufferGWT = null;
} catch(Exception e) {
e.printStackTrace();
}
}
return -1;
}
/**
* HWND FindWindow(
*
* LPCTSTR lpClassName, LPCTSTR lpWindowName );
*/
public static HWND FindWindow(String className, String windowName)
throws NativeException, IllegalAccessException {
JNative _FindWindow = new JNative(DLL_NAME, "FindWindowA");
try {
_FindWindow.setRetVal(Type.INT);
_FindWindow.setParameter(0, Type.STRING, className);
_FindWindow.setParameter(1, Type.STRING, windowName);
_FindWindow.invoke();
int valRet = Integer.parseInt(_FindWindow.getRetVal());
return new HWND(valRet);
} finally {
if(_FindWindow != null)
_FindWindow.dispose();
}
}
/*
WNDPROC lpPrevWndFunc,
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
*/
public static LRESULT CallWindowProc(LONG lpPrevWndFunc, HWND hwnd, UINT msg, WPARAM wparam,
LPARAM lparam)
throws NativeException, IllegalAccessException {
JNative dwp = new JNative(DLL_NAME, "CallWindowProcA");
try {
dwp.setRetVal(Type.INT);
int i = 0;
dwp.setParameter(i++, lpPrevWndFunc.getValue());
dwp.setParameter(i++, hwnd.getValue());
dwp.setParameter(i++, msg.getValue());
dwp.setParameter(i++, wparam.getValue());
dwp.setParameter(i++, lparam.getValue());
dwp.invoke();
return new LRESULT(dwp.getRetValAsInt());
} finally {
if(dwp != null)
dwp.dispose();
}
}
public static LRESULT DefWindowProc(HWND hwnd, UINT msg, WPARAM wparam,
LPARAM lparam) throws NativeException, IllegalAccessException {
JNative dwp = new JNative(DLL_NAME, "DefWindowProcA");
dwp.setRetVal(Type.INT);
dwp.setParameter(0, Type.INT, hwnd.getValueAsString());
dwp.setParameter(1, Type.INT, msg.getValueAsString());
dwp.setParameter(2, Type.INT, wparam.getValueAsString());
dwp.setParameter(3, Type.INT, lparam.getValueAsString());
dwp.invoke();
return new LRESULT(dwp.getRetValAsInt());
}
public static void UpdateWindow(HWND hwnd) throws NativeException,
IllegalAccessException {
JNative dm = new JNative(DLL_NAME, "UpdateWindow");
dm.setParameter(0, Type.INT, hwnd.getValueAsString());
dm.invoke();
dm.dispose();
}
public static void DispatchMessage(MSG msg) throws NativeException,
IllegalAccessException {
JNative dm = new JNative(DLL_NAME, "DispatchMessageA");
// dm.setRetVal(Type.INT);
dm.setParameter(0, msg.getValue());
dm.invoke();
dm.dispose();
}
public static void TranslateMessage(MSG msg) throws NativeException,
IllegalAccessException {
JNative dm = new JNative(DLL_NAME, "TranslateMessage");
// dm.setRetVal(Type.INT);
dm.setParameter(0, msg.getValue());
dm.invoke();
dm.dispose();
}
public static int PeekMessage(MSG msg, HWND hwnd, int minMSG, int maxMSG, int removeMsg)
throws NativeException, IllegalAccessException {
JNative gm = new JNative(DLL_NAME, "PeekMessageA");
gm.setRetVal(Type.INT);
gm.setParameter(0, msg.getValue());
gm.setParameter(1, Type.INT, hwnd.getValueAsString());
gm.setParameter(2, Type.INT, "" + minMSG);
gm.setParameter(3, Type.INT, "" + maxMSG);
gm.setParameter(4, Type.INT, "" + removeMsg);
gm.invoke();
int ret = gm.getRetValAsInt();
gm.dispose();
return ret;
}
public static int GetMessage(MSG msg, HWND hwnd, int minMSG, int maxMSG)
throws NativeException, IllegalAccessException {
JNative gm = new JNative(DLL_NAME, "GetMessageA");
gm.setRetVal(Type.INT);
gm.setParameter(0, msg.getValue());
gm.setParameter(1, Type.INT, hwnd.getValueAsString());
gm.setParameter(2, Type.INT, "" + minMSG);
gm.setParameter(3, Type.INT, "" + maxMSG);
gm.invoke();
int ret = gm.getRetValAsInt();
gm.dispose();
return ret;
}
public static boolean ShowWindow(HWND hwnd, int nCmdShow)
throws NativeException, IllegalAccessException {
JNative w = null;
try {
w = new JNative(DLL_NAME, "ShowWindow");
w.setRetVal(Type.INT);
w.setParameter(0, Type.INT, hwnd.getValueAsString());
w.setParameter(1, Type.INT, "" + nCmdShow);
w.invoke();
return Integer.parseInt(w.getRetVal()) != 0;
} finally {
if (w != null)
w.dispose();
}
}
/**
* HWND CreateWindowEx( DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR
* lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND
* hWndParent, -3 for HWND_MESSAGE (Message only windows) HMENU hMenu,
* HINSTANCE hInstance, LPVOID lpParam );
*/
public static final int CreateWindowEx(int dwExStyle, String lpClassName,
String lpWindowName, int dwStyle, int x, int y, int nWidth,
int nHeight, int hWndParent, int hMenu, int hInstance, int lParam)
throws NativeException, IllegalAccessException {
JNative n = null;
try {
n = new JNative(DLL_NAME, "CreateWindowExA");
n.setRetVal(Type.INT);
int i = 0;
n.setParameter(i++, Type.INT, "" + dwExStyle);
n.setParameter(i++, Type.STRING, lpClassName);
if(lpWindowName == null) {
n.setParameter(i++, 0);
} else {
n.setParameter(i++, lpWindowName);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -