Code polish for accessing User32
This commit is contained in:
parent
409d6d0931
commit
713837cf4c
@ -17,6 +17,7 @@ package dorkbox.util.jna.windows;
|
|||||||
|
|
||||||
import static com.sun.jna.platform.win32.WinDef.HBITMAP;
|
import static com.sun.jna.platform.win32.WinDef.HBITMAP;
|
||||||
import static com.sun.jna.platform.win32.WinDef.HDC;
|
import static com.sun.jna.platform.win32.WinDef.HDC;
|
||||||
|
import static dorkbox.util.jna.windows.User32.User32;
|
||||||
|
|
||||||
import java.awt.AlphaComposite;
|
import java.awt.AlphaComposite;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
@ -34,7 +35,7 @@ public class HBITMAPWrap extends HBITMAP {
|
|||||||
HBITMAP createBitmap(BufferedImage image) {
|
HBITMAP createBitmap(BufferedImage image) {
|
||||||
int w = image.getWidth(null);
|
int w = image.getWidth(null);
|
||||||
int h = image.getHeight(null);
|
int h = image.getHeight(null);
|
||||||
HDC screenDC = User32.IMPL.GetDC(null);
|
HDC screenDC = User32.GetDC(null);
|
||||||
HDC memDC = GDI32.CreateCompatibleDC(screenDC);
|
HDC memDC = GDI32.CreateCompatibleDC(screenDC);
|
||||||
HBITMAP hBitmap = null;
|
HBITMAP hBitmap = null;
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ public class HBITMAPWrap extends HBITMAP {
|
|||||||
pbits.write(0, bits, 0, bits.length);
|
pbits.write(0, bits, 0, bits.length);
|
||||||
return hBitmap;
|
return hBitmap;
|
||||||
} finally {
|
} finally {
|
||||||
User32.IMPL.ReleaseDC(null, screenDC);
|
User32.ReleaseDC(null, screenDC);
|
||||||
GDI32.DeleteDC(memDC);
|
GDI32.DeleteDC(memDC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ package dorkbox.util.jna.windows;
|
|||||||
|
|
||||||
import static com.sun.jna.platform.win32.WinDef.HBITMAP;
|
import static com.sun.jna.platform.win32.WinDef.HBITMAP;
|
||||||
import static com.sun.jna.platform.win32.WinDef.HICON;
|
import static com.sun.jna.platform.win32.WinDef.HICON;
|
||||||
|
import static dorkbox.util.jna.windows.User32.User32;
|
||||||
|
|
||||||
import com.sun.jna.Pointer;
|
import com.sun.jna.Pointer;
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ public class HICONWrap extends HICON {
|
|||||||
info.MaskBitmap = bm;
|
info.MaskBitmap = bm;
|
||||||
info.ColorBitmap = bm;
|
info.ColorBitmap = bm;
|
||||||
|
|
||||||
HICON hicon = User32.IMPL.CreateIconIndirect(info);
|
HICON hicon = User32.CreateIconIndirect(info);
|
||||||
if (hicon == null) {
|
if (hicon == null) {
|
||||||
throw new GetLastErrorException();
|
throw new GetLastErrorException();
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ import dorkbox.util.jna.windows.structs.ICONINFO;
|
|||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
public
|
public
|
||||||
interface User32 {
|
interface User32 {
|
||||||
User32 IMPL = OS.is64bit() ? new User32_64() : new User32_32();
|
User32 User32 = OS.is64bit() ? new User32_64() : new User32_32();
|
||||||
|
|
||||||
int GWL_WNDPROC = -4;
|
int GWL_WNDPROC = -4;
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ import static com.sun.jna.platform.win32.WinDef.LPARAM;
|
|||||||
import static com.sun.jna.platform.win32.WinDef.LRESULT;
|
import static com.sun.jna.platform.win32.WinDef.LRESULT;
|
||||||
import static com.sun.jna.platform.win32.WinDef.WPARAM;
|
import static com.sun.jna.platform.win32.WinDef.WPARAM;
|
||||||
import static com.sun.jna.platform.win32.WinUser.WM_QUIT;
|
import static com.sun.jna.platform.win32.WinUser.WM_QUIT;
|
||||||
|
import static dorkbox.util.jna.windows.User32.User32;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -39,7 +40,7 @@ class WindowsEventDispatch implements Runnable {
|
|||||||
|
|
||||||
private static final String NAME = "WindowsEventDispatch";
|
private static final String NAME = "WindowsEventDispatch";
|
||||||
|
|
||||||
public static final int WM_TASKBARCREATED = User32.IMPL.RegisterWindowMessage(new WString("TaskbarCreated"));
|
public static final int WM_TASKBARCREATED = User32.RegisterWindowMessage(new WString("TaskbarCreated"));
|
||||||
public static final int WM_COMMAND = 0x0111;
|
public static final int WM_COMMAND = 0x0111;
|
||||||
public static final int WM_SHELLNOTIFY = WinUser.WM_USER + 1;
|
public static final int WM_SHELLNOTIFY = WinUser.WM_USER + 1;
|
||||||
public static final int WM_MEASUREITEM = 44;
|
public static final int WM_MEASUREITEM = 44;
|
||||||
@ -110,7 +111,7 @@ class WindowsEventDispatch implements Runnable {
|
|||||||
// always from inside lock!
|
// always from inside lock!
|
||||||
private void
|
private void
|
||||||
stop_() {
|
stop_() {
|
||||||
User32.IMPL.SendMessage(hWnd, WM_QUIT, new WPARAM(0), new LPARAM(0));
|
User32.SendMessage(hWnd, WM_QUIT, new WPARAM(0), new LPARAM(0));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// wait for the dispatch thread to quit (but only if we are not on the dispatch thread)
|
// wait for the dispatch thread to quit (but only if we are not on the dispatch thread)
|
||||||
@ -175,30 +176,30 @@ class WindowsEventDispatch implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return User32.IMPL.DefWindowProc(hWnd, msg, wParam, lParam);
|
return User32.DefWindowProc(hWnd, msg, wParam, lParam);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
hWnd = User32.IMPL.CreateWindowEx(0, "STATIC", NAME, 0, 0, 0, 0, 0, null, null, null,
|
hWnd = User32.CreateWindowEx(0, "STATIC", NAME, 0, 0, 0, 0, 0, null, null, null,
|
||||||
null);
|
null);
|
||||||
if (hWnd == null) {
|
if (hWnd == null) {
|
||||||
throw new GetLastErrorException();
|
throw new GetLastErrorException();
|
||||||
}
|
}
|
||||||
|
|
||||||
User32.IMPL.SetWindowLong(hWnd, User32.GWL_WNDPROC, WndProc);
|
User32.SetWindowLong(hWnd, User32.GWL_WNDPROC, WndProc);
|
||||||
|
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
lock.notifyAll();
|
lock.notifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
MSG msg = new MSG();
|
MSG msg = new MSG();
|
||||||
while (User32.IMPL.GetMessage(msg, null, 0, 0)) {
|
while (User32.GetMessage(msg, null, 0, 0)) {
|
||||||
User32.IMPL.TranslateMessage(msg);
|
User32.TranslateMessage(msg);
|
||||||
User32.IMPL.DispatchMessage(msg);
|
User32.DispatchMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hWnd != null) {
|
if (hWnd != null) {
|
||||||
if (!User32.IMPL.DestroyWindow(hWnd)) {
|
if (!User32.DestroyWindow(hWnd)) {
|
||||||
throw new GetLastErrorException();
|
throw new GetLastErrorException();
|
||||||
}
|
}
|
||||||
hWnd = null;
|
hWnd = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user