Java 类com.sun.jna.platform.win32.WinUser.MSG 实例源码

项目:NanoUI    文件:TaskBar.java   
private void createHotKeys() {
    Thread keys = new Thread(() -> {
        keysThreadID = Kernel32.INSTANCE.GetCurrentThreadId();
        User32.INSTANCE.RegisterHotKey(new HWND(Pointer.NULL), 1, MOD_WIN | MOD_NOREPEAT, VK_E);
        MSG msg = new MSG();
        while (User32.INSTANCE.GetMessage(msg, new HWND(Pointer.NULL), 0, 0) != 0 && running) {
            if (msg.message == WM_HOTKEY) {
                try {
                    switch (msg.wParam.intValue()) {
                    case 1:
                        new ProcessBuilder("explorer.exe", ",").start();
                        break;
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        User32.INSTANCE.UnregisterHotKey(Pointer.NULL, 1);
    });
    keys.start();
}
项目:Clipcon-Client    文件:ClipboardController.java   
public static void clipboardMonitor() {

    WString windowClass = new WString("MyWindowClass");
    HMODULE hInst = Kernel32.INSTANCE.GetModuleHandle("");
    WNDCLASSEX wClass = new WNDCLASSEX();
    wClass.hInstance = hInst;
    WindowProc wProc = new WindowProc();
    wClass.lpfnWndProc = wProc;
    wClass.lpszClassName = windowClass;

    // register window class
    User32.INSTANCE.RegisterClassEx(wClass);
    getLastError();

    // create new window
    HWND hWnd = User32.INSTANCE.CreateWindowEx(User32.WS_EX_TOPMOST, windowClass, "My hidden helper window, used only to catch the windows events", 0, 0, 0, 0, 0, null, null, hInst, null);
    getLastError();

    // set clipboard viewer
    HWND nextViewer = User32X.INSTANCE.SetClipboardViewer(hWnd);
    wProc.setNextViewer(nextViewer);

    // pump messages
    MSG msg = new MSG();
    while (User32.INSTANCE.GetMessage(msg, hWnd, 0, 0) != 0) {
        User32.INSTANCE.TranslateMessage(msg);
        User32.INSTANCE.DispatchMessage(msg);
    }

    // wait for input
    try {
        System.in.read();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // destroy window
    User32.INSTANCE.UnregisterClass(windowClass, hInst);
    User32.INSTANCE.DestroyWindow(hWnd);
    System.exit(0);
}
项目:spark-svn-mirror    文件:UserIdlePlugin.java   
public void initKeyHook() {

        thread = new Thread(new Runnable() {

        @Override
        public void run() {
            final User32 lib = User32.INSTANCE;
            HMODULE hMod = Kernel32.INSTANCE.GetModuleHandle(null);
            keyboardHook = new LowLevelKeyboardProc() {
            public LRESULT callback(int nCode, WPARAM wParam,
                KBDLLHOOKSTRUCT info) {
                if (nCode >= 0) {
                switch (wParam.intValue()) {
                // case WinUser.WM_KEYUP:
                case WinUser.WM_KEYDOWN:
                    // case WinUser.WM_SYSKEYUP:
                case WinUser.WM_SYSKEYDOWN:
                    // do active
                    userActive();
                }
                }
                return lib.CallNextHookEx(hhk, nCode, wParam,
                    info.getPointer());
            }
            };
            hhk = lib.SetWindowsHookEx(WinUser.WH_KEYBOARD_LL,
                keyboardHook, hMod, 0);

            // This bit never returns from GetMessage
            int result;
            MSG msg = new MSG();
            while ((result = lib.GetMessage(msg, null, 0, 0)) != 0) {
            if (result == -1) {
                System.err.println("error in get message");
                break;
            } else {
                System.err.println("got message");
                lib.TranslateMessage(msg);
                lib.DispatchMessage(msg);
            }
            }
            lib.UnhookWindowsHookEx(hhk);
        }
        });
        thread.start();
    }
项目:yajsw    文件:WindowsXPMouse.java   
public synchronized void registerMouseUpListner(Runnable action,
        Executor executor)
{
    if (thrd != null)
        return;
    this.action = action;
    thrd = new Thread(new Runnable()
    {

        public void run()
        {
            try
            {
                if (!isHooked)
                {
                    hhk = USER32INST.SetWindowsHookEx(14,
                            (HOOKPROC) mouseHook,
                            KERNEL32INST.GetModuleHandle(null), 0);
                    isHooked = true;
                    MSG msg = new MSG();
                    while ((USER32INST.GetMessage(msg, null, 0, 0)) != 0)
                    {
                        System.out.println("got message");
                        USER32INST.TranslateMessage(msg);
                        USER32INST.DispatchMessage(msg);
                        System.out.print(isHooked);
                        if (!isHooked)
                            break;
                    }
                }
                else
                    System.out.println("The Hook is already installed.");
            }
            catch (Exception e)
            {
                System.err.println(e.getMessage());
                System.err.println("Caught exception in MouseHook!");
            }
            // System.out.println("terminated ");
            USER32INST.UnhookWindowsHookEx(hhk);
            hhk = null;
        }

    }, "Named thread");
    threadFinish = false;
    thrd.start();

}
项目:Nird2    文件:WindowsShutdownManagerImpl.java   
int GetMessage(MSG msg, HWND hwnd, int filterMin, int filterMax);
项目:Nird2    文件:WindowsShutdownManagerImpl.java   
boolean TranslateMessage(MSG msg);
项目:Nird2    文件:WindowsShutdownManagerImpl.java   
LRESULT DispatchMessage(MSG msg);
项目:Nird2    文件:WindowsShutdownManagerImpl.java   
int GetMessage(MSG msg, HWND hwnd, int filterMin, int filterMax);
项目:Nird2    文件:WindowsShutdownManagerImpl.java   
boolean TranslateMessage(MSG msg);
项目:Nird2    文件:WindowsShutdownManagerImpl.java   
LRESULT DispatchMessage(MSG msg);
项目:briar    文件:WindowsShutdownManagerImpl.java   
int GetMessage(MSG msg, HWND hwnd, int filterMin, int filterMax);
项目:briar    文件:WindowsShutdownManagerImpl.java   
boolean TranslateMessage(MSG msg);
项目:briar    文件:WindowsShutdownManagerImpl.java   
LRESULT DispatchMessage(MSG msg);