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);
}
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));
}
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));
}
}
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);
}
}
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);
}
Aggregations