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

📄 user32.java

📁 用于Java 组件和通过Windows COM 对象或Windows DLL 来公开的组件之间的互操作
💻 JAVA
字号:
//******************************************************************
// Released under the DevelopMentor OpenSource Software License.
// Please consult the LICENSE file in the project root directory,
// or at http://www.develop.com for details before using this
// software.
//******************************************************************

package com.develop.jawin.win32;

import com.develop.jawin.*;
import com.develop.jawin.marshal.*;
import com.develop.io.*;
import com.develop.util.*;
import java.io.*;
import java.util.*;

public class User32 implements MarshalConstants {

    public static void MessageBoxW(String msg, String title)
            throws COMException, IOException
    {
        FuncPtr fp = new FuncPtr("USER32.DLL", "MessageBoxW");
	fp.invoke(0, msg, title, 0, ReturnFlags.FAIL_ON_FALSE);
    }

    public static int LoadIconW(int handle, int iconConstant)
            throws COMException, IOException
    {
        FuncPtr fp = new FuncPtr("USER32.DLL", "LoadIconW");
        return SharedStubs.invokeII_I(handle, iconConstant, fp.getPeer(), CHECK_NULL);
    }

    public static int LoadCursorW(int hinst, int cursor)
            throws COMException, IOException
    {
        FuncPtr fp = new FuncPtr("USER32.DLL", "LoadCursorW");
        return SharedStubs.invokeII_I(hinst, cursor, fp.getPeer(), CHECK_NULL);
    }

    static final String mstringRegisterClassW = "R" + WNDCLASS.token +":I:";
    static final int msRegisterClassW = 4;
    public static short RegisterClassW(WNDCLASS cls)
            throws COMException, IOException
    {
        FuncPtr fp = new FuncPtr("USER32.DLL", "RegisterClassW");
        NakedByteStream nbs = new NakedByteStream();
        LittleEndianOutputStream baos = new LittleEndianOutputStream(nbs);
        ArrayList alObjs = new ArrayList();
        cls.marshal(baos, alObjs);
        byte[] res = GenericStub.win32Invoke(fp.getPeer(), 
                            mstringRegisterClassW, 
                            msRegisterClassW, 
                            baos.size(), 
                            nbs.getInternalBuffer(), 
                            alObjs.toArray());
        return StructConverter.bytesIntoShort(res, 0);
    }

    public static int DefWindowProcW(int hwnd, int msg, int wParam, int lParam)
            throws COMException, IOException
    {
        FuncPtr fp = new FuncPtr("USER32.DLL", "DefWindowProcW");
        return SharedStubs.invokeIIII_I(hwnd, msg, wParam, lParam, fp.getPeer(), CHECK_NONE);
    }

    static final int mstackCreateWindowExW = 48;
    public static int CreateWindowExW (int dwExStyle,
                                        String lpClassName,
                                        String lpWindowName,
                                        int dwStyle,
                                        int X,
                                        int Y,
                                        int nWidth,
                                        int nHeight,
                                        int hWndParent ,
                                        int hMenu,
                                        int hInstance,
                                        int lpParam)
            throws COMException, IOException
    {
        FuncPtr fp = new FuncPtr("USER32.DLL", "CreateWindowExW");
        NakedByteStream nbs = new NakedByteStream();
        LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
        //top-level args
        leos.writeInt(dwExStyle);
        leos.writeStringUnicode(lpClassName);
        leos.writeStringUnicode(lpWindowName);
        leos.writeInt(dwStyle);
        leos.writeInt(X);
        leos.writeInt(Y);
        leos.writeInt(nWidth);
        leos.writeInt(nHeight);
        leos.writeInt(hWndParent);
        leos.writeInt(hMenu);
        leos.writeInt(hInstance);
        leos.writeInt(lpParam);
        byte[] res = GenericStub.win32Invoke(fp.getPeer(), 
			    "IGGIIIIIIIII:T1:", //mtokenCreateWindowExW, 
                            mstackCreateWindowExW, 
                            leos.size(), 
                            nbs.getInternalBuffer(), 
                            null);
        return StructConverter.bytesIntoInt(res, 0);
    }

    public static boolean ShowWindow(int hwnd, int nCmdShow)
            throws COMException, IOException
    {
        FuncPtr fp = new FuncPtr("USER32.DLL", "ShowWindow");
        return (0 != SharedStubs.invokeII_I(hwnd, nCmdShow, fp.getPeer(), CHECK_NONE));
    }

    public static void UpdateWindow(int hWnd)
            throws COMException, IOException
    {
        FuncPtr fp = new FuncPtr("USER32.DLL", "UpdateWindow");
        SharedStubs.invokeI_I(hWnd, fp.getPeer(), CHECK_NULL);
    }

    public static boolean GetMessageW(MSG msg, int hWnd , int wMsgFilterMin, int wMsgFilterMax)
        throws COMException, IOException
    {
        FuncPtr fp = new FuncPtr("USER32.DLL", "GetMessageW");
        NakedByteStream nbs = new NakedByteStream();
        LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
        leos.writeInt(hWnd);
        leos.writeInt(wMsgFilterMin);
        leos.writeInt(wMsgFilterMax);

        byte[] res = GenericStub.win32Invoke(fp.getPeer(), 
                            "M" + MSG.marshal + "III:I:N|" + MSG.marshal + "B" + MSG.marshal + "|", 
                            16, 
                            leos.size(), 
                            nbs.getInternalBuffer(), 
                            null);

        ByteArrayInputStream bais = new ByteArrayInputStream(res);
        LittleEndianInputStream leis = new LittleEndianInputStream(bais);
        boolean result = (leis.readInt() != 0);
        msg.marshalOut(leis, null);
        return result;
    }

    public static boolean TranslateMessage(MSG msg)
        throws COMException, IOException
    {
        FuncPtr fp = new FuncPtr("USER32.DLL", "TranslateMessage");
        NakedByteStream nbs = new NakedByteStream();
        LittleEndianOutputStream leis = new LittleEndianOutputStream(nbs);
        msg.marshal(leis, null);
        return SharedStubs.invokeP_I(nbs.getInternalBuffer(), fp.getPeer(), 0) != 0;
    }

    public static boolean DispatchMessageW(MSG msg)
        throws COMException, IOException
    {
        FuncPtr fp = new FuncPtr("USER32.DLL", "DispatchMessageW");
        NakedByteStream nbs = new NakedByteStream();
        LittleEndianOutputStream leis = new LittleEndianOutputStream(nbs);
        msg.marshal(leis, null);
        return SharedStubs.invokeP_I(nbs.getInternalBuffer(), fp.getPeer(), 0) != 0;
    }

    public static void PostQuitMessage(int nExitCode)
            throws COMException, IOException
    {
        FuncPtr fp = new FuncPtr("USER32.DLL", "PostQuitMessage");
        SharedStubs.invokeI_I(nExitCode, fp.getPeer(), CHECK_NONE);
    }

    static final String mstringBeginPaint = "IM" + PAINTSTRUCT.marshal + ":T1:lN|" + PAINTSTRUCT.marshal + "B" + PAINTSTRUCT.marshal + "|";
    static final int msBeginPaint = 8;
    public static int BeginPaint(int hwnd, PAINTSTRUCT ps) 
            throws COMException, IOException
    {
        FuncPtr fp = new FuncPtr("USER32.DLL", "BeginPaint");
        NakedByteStream nbs = new NakedByteStream();
        LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
        //top-level args
        leos.writeInt(hwnd);
        leos.writeInt(0);
        byte[] res = GenericStub.win32Invoke(fp.getPeer(), 
                            mstringBeginPaint, 
                            msBeginPaint, 
                            leos.size(), 
                            nbs.getInternalBuffer(), 
                            null);
        ByteArrayInputStream bais = new ByteArrayInputStream(res);
        LittleEndianInputStream leis = new LittleEndianInputStream(bais);
        int result = (leis.readInt());
        ps.marshalOut(leis, null);
        return result;
    }

    static final String mstringGetClientRect = "IR" + RECT.token +":T1:ln" + RECT.marshal;
    static final int msGetClientRect = 8;
    public static void GetClientRect(int hwnd, RECT r)
        throws COMException, IOException
    {
        FuncPtr fp = new FuncPtr("USER32.DLL", "GetClientRect");
        NakedByteStream nbs = new NakedByteStream();
        LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
        //top level args
        leos.writeInt(hwnd);
        leos.writeInt(0);
        //nested args
        r.marshal(leos, null);
        byte[] res = GenericStub.win32Invoke(fp.getPeer(), 
                            mstringGetClientRect, 
                            msGetClientRect, 
                            leos.size(), 
                            nbs.getInternalBuffer(), 
                            null);
        ByteArrayInputStream bais = new ByteArrayInputStream(res);
        LittleEndianInputStream leis = new LittleEndianInputStream(bais);
                leis.readInt(); //ignore return value
        r.marshalOut(leis, null);
    }

    static final String mstringDrawTextW = "IGIR" + RECT.token +"I:T1:";
    static final int msDrawTextW = 20;
    public static int DrawTextW(int hwnd, String lpString, int nCount, RECT lpRect, int nFormat)
        throws COMException, IOException
    {
        FuncPtr fp = new FuncPtr("USER32.DLL", "DrawTextW");
        NakedByteStream nbs = new NakedByteStream();
        LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
        leos.writeInt(hwnd);
        leos.writeStringUnicode(lpString);
        leos.writeInt(nCount);
        lpRect.marshal(leos, null);
        leos.writeInt(nFormat);

        byte[] res = GenericStub.win32Invoke(fp.getPeer(), 
                            mstringDrawTextW, 
                            msDrawTextW, 
                            leos.size(), 
                            nbs.getInternalBuffer(), 
                            null);
        return StructConverter.bytesIntoInt(res, 0);
    }
    
    static final String mstringEndPaint = "IR" + PAINTSTRUCT.token + "::";
    static final int msEndPaint = 8;
    public static void EndPaint(int hwnd, PAINTSTRUCT ps)
        throws COMException, IOException
    {
        FuncPtr fp = new FuncPtr("USER32.DLL", "EndPaint");
        NakedByteStream nbs = new NakedByteStream();
        LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
        leos.writeInt(hwnd);
        ps.marshal(leos, null);
        GenericStub.win32Invoke(fp.getPeer(), 
                            mstringEndPaint, 
                            msEndPaint, 
                            leos.size(), 
                            nbs.getInternalBuffer(), 
                            null);
    }
}

⌨️ 快捷键说明

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