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

📄 user32.java

📁 一个开源的组件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			}
			n.setParameter(i++, Type.INT, "" + dwStyle);
			n.setParameter(i++, Type.INT, "" + x);
			n.setParameter(i++, Type.INT, "" + y);
			n.setParameter(i++, Type.INT, "" + nWidth);
			n.setParameter(i++, Type.INT, "" + nHeight);
			n.setParameter(i++, Type.INT, "" + hWndParent);
			n.setParameter(i++, Type.INT, "" + hMenu);
			n
					.setParameter(i++, Type.INT, ""
							+ (hInstance == 0 ? JNative.getCurrentModule()
									: hInstance));
			n.setParameter(i++, Type.INT, "" + lParam);
			n.invoke();
			return Integer.parseInt(n.getRetVal());
		} finally {
			if (n != null) {
				n.dispose();
			}
		}
	}

	public static final int CreateWindowEx(int dwExStyle, LONG 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++, lpClassName.getValue());
			if(lpWindowName == null) {
				n.setParameter(i++, 0);
			} else {
				n.setParameter(i++, lpWindowName);
			}
			n.setParameter(i++, Type.INT, "" + dwStyle);
			n.setParameter(i++, Type.INT, "" + x);
			n.setParameter(i++, Type.INT, "" + y);
			n.setParameter(i++, Type.INT, "" + nWidth);
			n.setParameter(i++, Type.INT, "" + nHeight);
			n.setParameter(i++, Type.INT, "" + hWndParent);
			n.setParameter(i++, Type.INT, "" + hMenu);
			n
					.setParameter(i++, Type.INT, ""
							+ (hInstance == 0 ? JNative.getCurrentModule()
									: hInstance));
			n.setParameter(i++, Type.INT, "" + lParam);
			n.invoke();
			return Integer.parseInt(n.getRetVal());
		} finally {
			if (n != null) {
				n.dispose();
			}
		}
	}

	public static final int MessageBox(int parentHandle, String message,
			String caption, int buttons) throws NativeException,
			IllegalAccessException {
		JNative n = null;
		try {
			n = new JNative(DLL_NAME, "MessageBoxA");
			n.setRetVal(Type.INT);
			int i = 0;
			n.setParameter(i++, Type.INT, "" + parentHandle);
			n.setParameter(i++, Type.STRING, message);
			n.setParameter(i++, Type.STRING, caption);
			n.setParameter(i++, Type.INT, "" + buttons);
			n.invoke();
			return Integer.parseInt(n.getRetVal());
		} finally {
			if (n != null)
				n.dispose();
		}
	}

	/**
	 * <pre>
	 *  EnumWindows Function
	 * 
	 * 	 The EnumWindows function enumerates all top-level windows on the screen by passing the handle to each window, in turn, to an application-defined callback function. EnumWindows continues until the last top-level window is enumerated or the callback function returns FALSE.
	 * 
	 * 	 Syntax
	 * 
	 * 	 BOOL EnumWindows(
	 * 
	 * 	 WNDENUMPROC lpEnumFunc,
	 * 	 LPARAM lParam
	 * 	 );
	 * 
	 * 	 Parameters
	 * 
	 * 	 lpEnumFunc
	 * 	 [in] Pointer to an application-defined callback function. For more information, see EnumWindowsProc.
	 * 	 lParam
	 * 	 [in] Specifies an application-defined value to be passed to the callback function.
	 * 
	 * 	 Return Value
	 * 
	 * 	 If the function succeeds, the return value is nonzero.
	 * 
	 * 	 If the function fails, the return value is zero. To get extended error information, call GetLastError.
	 * 
	 * 	 If EnumWindowsProc returns zero, the return value is also zero. In this case, the callback function should call SetLastError to obtain a meaningful error code to be returned to the caller of EnumWindows.
	 * 
	 * 
	 * 	 Remarks
	 * 
	 * 	 The EnumWindows function does not enumerate child windows, with the exception of a few top-level windows owned by the system that have the WS_CHILD style.
	 * 
	 * 	 This function is more reliable than calling the GetWindow function in a loop. An application that calls GetWindow to perform this task risks being caught in an infinite loop or referencing a handle to a window that has been destroyed.
	 * 
	 * </pre>
	 * 
	 * lpEnumFunc must be the address returned by JNative.createCallback()
	 */

	public static boolean EnumWindows(Callback lpEnumFunc, int lParam)
			throws NativeException, IllegalAccessException {
		if (nEnumWindows == null) {
			nEnumWindows = new JNative(DLL_NAME, "EnumWindows", false);
			nEnumWindows.setRetVal(Type.INT);
		}
		nEnumWindows.setParameter(0, lpEnumFunc.getCallbackAddress());
		nEnumWindows.setParameter(1, lParam);
		nEnumWindows.invoke();
		return !"0".equals(nEnumWindows.getRetVal());
	}

	public static String GetWindowText(HWND hwnd) throws NativeException,
			IllegalAccessException {
		if (nGetWindowText == null) {
			nGetWindowText = new JNative(DLL_NAME, "GetWindowTextA");
			nGetWindowText.setRetVal(Type.INT);
			nBufferGWT = new Pointer(MemoryBlockFactory.createMemoryBlock(512));
			nGetWindowText.setParameter(1, nBufferGWT);
			nGetWindowText.setParameter(2, nBufferGWT.getSize());
		}
		nGetWindowText.setParameter(0, hwnd.getValue());
		nGetWindowText.invoke();
		if ("0".equals(nGetWindowText.getRetVal())) {
			return "";
		} else {
			return nBufferGWT.getAsString();
		}
	}

	/**
	 * LONG SetWindowLong(      
	 *  HWND hWnd,
	 *  int nIndex,
	 *  LONG dwNewLong
	 * );
	 * @throws NativeException 
	 * @throws IllegalAccessException 
	 */
	public static int SetWindowLong(HWND hwnd, int nIndex, LONG dwNewLong) throws NativeException, IllegalAccessException {
		JNative _setWindowLong = new JNative(DLL_NAME, "SetWindowLongA");
		_setWindowLong.setRetVal(Type.INT);
		
		_setWindowLong.setParameter(0, hwnd.getValue());
		_setWindowLong.setParameter(1, nIndex);
		_setWindowLong.setParameter(2, dwNewLong.getValue());
		_setWindowLong.invoke();
		int ret = _setWindowLong.getRetValAsInt();
        _setWindowLong.dispose();
		return ret;
	}

	
	/**
	 * <pre>
	 * RegisterClass Function

The RegisterClass function registers a window class for subsequent use in calls to the CreateWindow or CreateWindowEx function.

The RegisterClass function has been superseded by the RegisterClassEx function. You can still use RegisterClass, however, if you do not need to set the class small icon.

Syntax

    ATOM RegisterClass(      

        public static final int WNDCLASS *lpWndClass
    );

Parameters

    lpWndClass
        [in] Pointer to a WNDCLASS structure. You must fill the structure with the appropriate class attributes before passing it to the function. 

Return Value

    If the function succeeds, the return value is a class atom that uniquely identifies the class being registered. This atom can only be used by the CreateWindow, CreateWindowEx, GetClassInfo, GetClassInfoEx, FindWindow, FindWindowEx, and UnregisterClass functions and the IActiveIMMap::FilterClientWindows method.

    If the function fails, the return value is zero. To get extended error information, call GetLastError. 
	 * </pre>
	 * @return
	 * @throws IllegalAccessException 
	 * @throws NativeException 
	 */
	public static LONG RegisterClass(WNDCLASS lpWndClass) throws NativeException, IllegalAccessException {
		JNative registerClass = new JNative(DLL_NAME, "RegisterClassA");
		registerClass.setRetVal(Type.INT);
		
		registerClass.setParameter(0, lpWndClass.createPointer());
		registerClass.invoke();
        int i = registerClass.getRetValAsInt();
        registerClass.dispose();
		return new LONG(i);
	}
	
	/**
	 * <pre>
    HICON LoadIcon(      

            HINSTANCE hInstance,
            LPCTSTR lpIconName
        );

    Parameters

        hInstance
            [in] Handle to an instance of the module whose executable file contains the icon to be loaded. This parameter must be NULL when a standard icon is being loaded. 
        lpIconName
            [in] 

            Pointer to a null-terminated string that contains the name of the icon resource to be loaded. Alternatively, this parameter can contain the resource identifier in the low-order word and zero in the high-order word. Use the MAKEINTRESOURCE macro to create this value.

            To use one of the predefined icons, set the hInstance parameter to NULL and the lpIconName parameter to one of the following values.

            IDI_APPLICATION
                Default application icon.
            IDI_ASTERISK
                Same as IDI_INFORMATION.
            IDI_ERROR
                Hand-shaped icon.
            IDI_EXCLAMATION
                Same as IDI_WARNING.
            IDI_HAND
                Same as IDI_ERROR. 
            IDI_INFORMATION
                Asterisk icon.
            IDI_QUESTION
                Question mark icon.
            IDI_WARNING
                Exclamation point icon.
            IDI_WINLOGO
                Windows logo icon. Windows XP: Default application icon.
            IDI_SHIELD
                Security Shield icon. 

    Return Value

        If the function succeeds, the return value is a handle to the newly loaded icon.

        If the function fails, the return value is NULL. To get extended error information, call GetLastError.
        
        </pre>
	 * @throws IllegalAccessException 
	 * @throws NativeException 
    */

	public static LONG LoadIcon(LONG hInstance, String lpIconName) throws NativeException, IllegalAccessException {
    	JNative loadIcon = new JNative(DLL_NAME, "LoadIconA");
    	loadIcon.setRetVal(Type.INT);
    	
    	loadIcon.setParameter(0, hInstance.getValue());
    	loadIcon.setParameter(1, lpIconName);
    	loadIcon.invoke();
        int ret = loadIcon.getRetValAsInt();
    	loadIcon.dispose();
    	return new LONG(ret);
    }

    public static LONG LoadIcon(LONG hInstance, int ressource) throws NativeException, IllegalAccessException {
    	JNative loadIcon = new JNative(DLL_NAME, "LoadIconA");
    	loadIcon.setRetVal(Type.INT);
    	
    	loadIcon.setParameter(0, hInstance.getValue());
    	loadIcon.setParameter(1, ressource);
    	loadIcon.invoke();
        int ret = loadIcon.getRetValAsInt();
        loadIcon.dispose();
    	
    	return new LONG(ret);
    }
/**
 * <pre>
 * SendMessage Function

The SendMessage function sends the specified message to a window or windows. It calls the window procedure for the specified window and does not return until the window procedure has processed the message.

To send a message and return immediately, use the SendMessageCallback or SendNotifyMessage function. To post a message to a thread's message queue and return immediately, use the PostMessage or PostThreadMessage function.

Syntax

    LRESULT SendMessage(      

        HWND hWnd,
        UINT Msg,
        WPARAM wParam,
        LPARAM lParam
    );

Parameters

    hWnd
        [in] Handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.
    Msg
        [in] Specifies the message to be sent.
    wParam
        [in] Specifies additional message-specific information.
    lParam
        [in] Specifies additional message-specific information.

Return Value

    The return value specifies the result of the message processing; it depends on the message sent.
    </pre>
 * @throws IllegalAccessException 
 * @throws NativeException 
 */
    public static LRESULT SendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) throws NativeException, IllegalAccessException {
    	JNative SendMessage = new JNative(DLL_NAME, "SendMessageA");
    	SendMessage.setRetVal(Type.INT);
    	int pos = 0;
    	SendMessage.setParameter(pos++, hWnd.getValue());
    	SendMessage.setParameter(pos++, Msg.getValue());

⌨️ 快捷键说明

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