Search in sources :

Example 6 with POINT

use of com.sun.jna.platform.win32.WinDef.POINT in project jna by java-native-access.

the class User32Test method testSetCursorPos.

@Test
public void testSetCursorPos() {
    POINT cursorPos = new POINT();
    boolean result = User32.INSTANCE.GetCursorPos(cursorPos);
    assertTrue("GetCursorPos should return true", result);
    assertTrue("X coordinate in POINT should be >= 0", cursorPos.x >= 0);
    boolean scpResult = User32.INSTANCE.SetCursorPos(cursorPos.x - 20, cursorPos.y);
    assertTrue("SetCursorPos should return true", scpResult);
    POINT cursorPos2 = new POINT();
    boolean result2 = User32.INSTANCE.GetCursorPos(cursorPos2);
    assertTrue("GetCursorPos should return true", result2);
    assertTrue("X coordinate in POINT should be original cursor position - 20", cursorPos2.x == cursorPos.x - 20);
}
Also used : POINT(com.sun.jna.platform.win32.WinDef.POINT) Test(org.junit.Test)

Example 7 with POINT

use of com.sun.jna.platform.win32.WinDef.POINT in project jna by java-native-access.

the class User32Test method testMonitorFromPoint.

@Test
public final void testMonitorFromPoint() {
    int dwFlags = WinUser.MONITOR_DEFAULTTOPRIMARY;
    POINT pt = new POINT(0, 0);
    assertNotNull(User32.INSTANCE.MonitorFromPoint(pt, dwFlags));
}
Also used : POINT(com.sun.jna.platform.win32.WinDef.POINT) Test(org.junit.Test)

Example 8 with POINT

use of com.sun.jna.platform.win32.WinDef.POINT in project jna by java-native-access.

the class Kernel32VolumeManagementFunctionsTest method testEnumVolumeMountMoints.

private void testEnumVolumeMountMoints(String volumeGUID) {
    char[] lpszVolumeMountPoint = new char[WinDef.MAX_PATH + 1];
    HANDLE hFindVolumeMountPoint = Kernel32.INSTANCE.FindFirstVolumeMountPoint(volumeGUID, lpszVolumeMountPoint, lpszVolumeMountPoint.length);
    if (WinNT.INVALID_HANDLE_VALUE.equals(hFindVolumeMountPoint)) {
        int hr = Kernel32.INSTANCE.GetLastError();
        if (// e.g., network or hidden volumes
        (hr == WinError.ERROR_ACCESS_DENIED) || // e.g., DVD drive
        (hr == WinError.ERROR_NOT_READY) || // No folders found
        (hr == WinError.ERROR_NO_MORE_FILES) || (hr == WinError.ERROR_PATH_NOT_FOUND)) {
            //                System.out.append('\t').append('[').append(volumeGUID).append(']').append(" - skipped: reason=").println(hr);
            return;
        }
        fail("Cannot (error=" + hr + ") open mount point search handle for " + volumeGUID);
    }
    try {
        do {
            String name = Native.toString(lpszVolumeMountPoint);
            assertTrue("Empty mount point for " + volumeGUID, name.length() > 0);
        //                System.out.append('\t').append("testEnumVolumeMountMoints").append('[').append(volumeGUID).append(']').append(" - ").println(name);
        } while (Kernel32.INSTANCE.FindNextVolumeMountPoint(hFindVolumeMountPoint, lpszVolumeMountPoint, lpszVolumeMountPoint.length));
        int hr = Kernel32.INSTANCE.GetLastError();
        assertEquals("Mount points enum termination reason for " + volumeGUID, WinError.ERROR_NO_MORE_FILES, hr);
    } finally {
        assertCallSucceeded("FindVolumeMountPointClose(" + volumeGUID + ")", Kernel32.INSTANCE.FindVolumeMountPointClose(hFindVolumeMountPoint));
    }
}
Also used : HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE)

Example 9 with POINT

use of com.sun.jna.platform.win32.WinDef.POINT in project jna by java-native-access.

the class AlphaMaskDemo method updateW32.

private void updateW32(boolean a, boolean i) {
    User32 user = User32.INSTANCE;
    GDI32 gdi = GDI32.INSTANCE;
    HWND hWnd = null;
    if (!alphaWindow.isDisplayable()) {
        alphaWindow.pack();
        hWnd = getHwnd(alphaWindow);
        int flags = user.GetWindowLong(hWnd, WinUser.GWL_EXSTYLE);
        flags |= WinUser.WS_EX_LAYERED;
        user.SetWindowLong(hWnd, WinUser.GWL_EXSTYLE, flags);
        Window parent = alphaWindow.getOwner();
        Point where = parent.getLocationOnScreen();
        where.translate(parent.getWidth(), 0);
        alphaWindow.setLocation(where);
    } else {
        hWnd = getHwnd(alphaWindow);
    }
    if (i) {
        int w = image.getWidth(null);
        int h = image.getHeight(null);
        HDC screenDC = user.GetDC(null);
        HDC memDC = gdi.CreateCompatibleDC(screenDC);
        HBITMAP hBitmap = null;
        HANDLE oldBitmap = null;
        try {
            BufferedImage buf = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
            Graphics g = buf.getGraphics();
            g.drawImage(image, 0, 0, w, h, null);
            BITMAPINFO bmi = new BITMAPINFO();
            bmi.bmiHeader.biWidth = w;
            bmi.bmiHeader.biHeight = h;
            bmi.bmiHeader.biPlanes = 1;
            bmi.bmiHeader.biBitCount = 32;
            bmi.bmiHeader.biCompression = WinGDI.BI_RGB;
            bmi.bmiHeader.biSizeImage = w * h * 4;
            PointerByReference ppbits = new PointerByReference();
            hBitmap = gdi.CreateDIBSection(memDC, bmi, WinGDI.DIB_RGB_COLORS, ppbits, null, 0);
            oldBitmap = gdi.SelectObject(memDC, hBitmap);
            Pointer pbits = ppbits.getValue();
            Raster raster = buf.getData();
            int[] pixel = new int[4];
            int[] bits = new int[w * h];
            for (int y = 0; y < h; y++) {
                for (int x = 0; x < w; x++) {
                    raster.getPixel(x, h - y - 1, pixel);
                    int alpha = (pixel[3] & 0xFF) << 24;
                    int red = (pixel[2] & 0xFF);
                    int green = (pixel[1] & 0xFF) << 8;
                    int blue = (pixel[0] & 0xFF) << 16;
                    bits[x + y * w] = alpha | red | green | blue;
                }
            }
            pbits.write(0, bits, 0, bits.length);
            SIZE size = new SIZE();
            size.cx = w;
            size.cy = h;
            POINT loc = new POINT();
            loc.x = alphaWindow.getX();
            loc.y = alphaWindow.getY();
            POINT srcLoc = new POINT();
            BLENDFUNCTION blend = new BLENDFUNCTION();
            blend.SourceConstantAlpha = (byte) (alpha * 255);
            blend.AlphaFormat = WinUser.AC_SRC_ALPHA;
            user.UpdateLayeredWindow(hWnd, screenDC, loc, size, memDC, srcLoc, 0, blend, WinUser.ULW_ALPHA);
        } finally {
            user.ReleaseDC(null, screenDC);
            if (hBitmap != null) {
                gdi.SelectObject(memDC, oldBitmap);
                gdi.DeleteObject(hBitmap);
            }
            gdi.DeleteDC(memDC);
        }
    } else if (a) {
        BLENDFUNCTION blend = new BLENDFUNCTION();
        blend.SourceConstantAlpha = (byte) (alpha * 255);
        blend.AlphaFormat = WinUser.AC_SRC_ALPHA;
        user.UpdateLayeredWindow(hWnd, null, null, null, null, null, 0, blend, WinUser.ULW_ALPHA);
    }
    if (!alphaWindow.isVisible()) {
        alphaWindow.setVisible(true);
    }
}
Also used : Window(java.awt.Window) JWindow(javax.swing.JWindow) GDI32(com.sun.jna.platform.win32.GDI32) BLENDFUNCTION(com.sun.jna.platform.win32.WinUser.BLENDFUNCTION) HDC(com.sun.jna.platform.win32.WinDef.HDC) HWND(com.sun.jna.platform.win32.WinDef.HWND) Raster(java.awt.image.Raster) SIZE(com.sun.jna.platform.win32.WinUser.SIZE) Pointer(com.sun.jna.Pointer) Point(java.awt.Point) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) Graphics(java.awt.Graphics) BITMAPINFO(com.sun.jna.platform.win32.WinGDI.BITMAPINFO) PointerByReference(com.sun.jna.ptr.PointerByReference) User32(com.sun.jna.platform.win32.User32) HBITMAP(com.sun.jna.platform.win32.WinDef.HBITMAP) POINT(com.sun.jna.platform.win32.WinDef.POINT) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE)

Example 10 with POINT

use of com.sun.jna.platform.win32.WinDef.POINT in project jna by java-native-access.

the class ComEventCallbacks_Test method testComEventCallback.

@Test
public void testComEventCallback() throws InterruptedException {
    VARIANT.ByReference pVarResult = new VARIANT.ByReference();
    IntByReference puArgErr = new IntByReference();
    EXCEPINFO.ByReference pExcepInfo = new EXCEPINFO.ByReference();
    HRESULT hr;
    DISPPARAMS.ByReference pDispParams;
    pDispParams = new DISPPARAMS.ByReference();
    pDispParams.setArgs(new VARIANT[] { new VARIANT(true) });
    pDispParams.setRgdispidNamedArgs(new DISPID[] { OaIdl.DISPID_PROPERTYPUT });
    // Visible-Prioperty
    hr = ieDispatch.Invoke(dispIdVisible.getValue(), niid, lcid, propertyPutFlags, pDispParams, null, null, null);
    COMUtils.checkRC(hr);
    // query for ConnectionPointContainer
    Unknown unk = new Unknown(ieApp.getValue());
    PointerByReference ppCpc = new PointerByReference();
    hr = unk.QueryInterface(new REFIID(IID_IConnectionPointContainer), ppCpc);
    COMUtils.checkRC(hr);
    ConnectionPointContainer cpc = new ConnectionPointContainer(ppCpc.getValue());
    // find connection point for DWebBrowserEvents2
    REFIID riid = new REFIID(IID_DWebBrowserEvents2);
    PointerByReference ppCp = new PointerByReference();
    hr = cpc.FindConnectionPoint(riid, ppCp);
    COMUtils.checkRC(hr);
    final ConnectionPoint cp = new ConnectionPoint(ppCp.getValue());
    IID cp_iid = new IID();
    hr = cp.GetConnectionInterface(cp_iid);
    COMUtils.checkRC(hr);
    final DWebBrowserEvents2_Listener listener = new DWebBrowserEvents2_Listener();
    final DWORDByReference pdwCookie = new DWORDByReference();
    HRESULT hr1 = cp.Advise(listener, pdwCookie);
    COMUtils.checkRC(hr1);
    // Advise make several callbacks into the object passed in - at this
    // point QueryInterface must have be called multiple times
    Assert.assertTrue(listener.QueryInterface_called);
    // Call Navigate with URL https://github.com/java-native-access/jna
    String navigateURL = "https://github.com/java-native-access/jna";
    String blockedURL = "http://www.google.de";
    VARIANT[] arguments = new VARIANT[] { new VARIANT(navigateURL) };
    pDispParams = new DISPPARAMS.ByReference();
    pDispParams.setArgs(arguments);
    hr = ieDispatch.Invoke(dispIdNavigate.getValue(), niid, lcid, methodFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
    COMUtils.checkRC(hr, pExcepInfo, puArgErr);
    for (int i = 0; i < 10; i++) {
        if (listener.navigateComplete2Called) {
            break;
        }
        Thread.sleep(1000);
    }
    // At this point the call to Navigate before should be complete
    Assert.assertTrue(listener.navigateComplete2Called);
    // Navidate complete should have brought us to github
    Assert.assertEquals(navigateURL, listener.navigateComplete2String);
    listener.navigateComplete2Called = false;
    listener.navigateComplete2String = null;
    listener.blockNavigation = true;
    arguments = new VARIANT[] { new VARIANT(blockedURL) };
    pDispParams = new DISPPARAMS.ByReference();
    pDispParams.setArgs(arguments);
    hr = ieDispatch.Invoke(dispIdNavigate.getValue(), niid, lcid, methodFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
    COMUtils.checkRC(hr, pExcepInfo, puArgErr);
    // wait 10 seconds to ensure navigation won't happen
    for (int i = 0; i < 10; i++) {
        if (listener.navigateComplete2Called) {
            break;
        }
        Thread.sleep(1000);
    }
    // Naviation will be blocked - so NavigateComplete can't be called
    Assert.assertFalse("NavigateComplete Handler was called although it should be blocked", listener.navigateComplete2Called);
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) IID(com.sun.jna.platform.win32.Guid.IID) REFIID(com.sun.jna.platform.win32.Guid.REFIID) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) EXCEPINFO(com.sun.jna.platform.win32.OaIdl.EXCEPINFO) REFIID(com.sun.jna.platform.win32.Guid.REFIID) WString(com.sun.jna.WString) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) DISPIDByReference(com.sun.jna.platform.win32.OaIdl.DISPIDByReference) VARIANT_BOOLByReference(com.sun.jna.platform.win32.OaIdl.VARIANT_BOOLByReference) UINTByReference(com.sun.jna.platform.win32.WinDef.UINTByReference) PointerByReference(com.sun.jna.ptr.PointerByReference) IntByReference(com.sun.jna.ptr.IntByReference) VARIANT(com.sun.jna.platform.win32.Variant.VARIANT) PointerByReference(com.sun.jna.ptr.PointerByReference) DISPPARAMS(com.sun.jna.platform.win32.OleAuto.DISPPARAMS) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 REFIID (com.sun.jna.platform.win32.Guid.REFIID)5 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)5 PointerByReference (com.sun.jna.ptr.PointerByReference)5 POINT (com.sun.jna.platform.win32.WinDef.POINT)4 IID (com.sun.jna.platform.win32.Guid.IID)3 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)3 ConnectionPoint (com.sun.jna.platform.win32.COM.ConnectionPoint)2 DWORDByReference (com.sun.jna.platform.win32.WinDef.DWORDByReference)2 IntByReference (com.sun.jna.ptr.IntByReference)2 Memory (com.sun.jna.Memory)1 Pointer (com.sun.jna.Pointer)1 WString (com.sun.jna.WString)1 COMException (com.sun.jna.platform.win32.COM.COMException)1 ConnectionPointContainer (com.sun.jna.platform.win32.COM.ConnectionPointContainer)1 Dispatch (com.sun.jna.platform.win32.COM.Dispatch)1 IDispatch (com.sun.jna.platform.win32.COM.IDispatch)1 IDispatchCallback (com.sun.jna.platform.win32.COM.IDispatchCallback)1 ComInterface (com.sun.jna.platform.win32.COM.util.annotation.ComInterface)1 GDI32 (com.sun.jna.platform.win32.GDI32)1