some windows code

This commit is contained in:
DaniTheSkunk 2022-09-28 02:17:33 +02:00
parent ec7cc40d02
commit d9ff38e221
4 changed files with 66 additions and 3 deletions

View File

@ -11,6 +11,8 @@
<element id="extracted-dir" path="$PROJECT_DIR$/lib/lwjgl/lwjgl-stb-natives-windows.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/lwjgl/lwjgl-stb.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/lwjgl/lwjgl.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/jna/jna-5.12.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/jna/jna-platform-5.12.1.jar" path-in-jar="/" />
</root>
</artifact>
</component>

View File

@ -17,9 +17,12 @@ public class Test {
}
windows.get(0).setBorder(true);
windows.get(0).setBorderRounded(false);
windows.get(0).move(new Vec2i(1280, 720), new Vec2i(2560, 1440));
windows.get(0).move(new Recti(1280, 720, 2560, 1440));
windows.get(0).debugPrintStyles();
windows.get(0).debugPrintStylesEx();
Window.onKey();
Window.onNewWindow();
Window.messageLoop();
/*
var engine = new Engine();
var window = engine.openWindow(new Vec2i(1280, 720), "Skunkworks");

View File

@ -46,6 +46,9 @@ public interface User32Extra extends User32 {
long WS_EX_OVERLAPPEDWINDOW = (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE);
long WS_EX_PALETTEWINDOW = (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST);
int WH_SHELL = 10;
int HSHELL_WINDOWCREATED = 1;
// https://docs.microsoft.com/en-us/windows/desktop/inputdev/virtual-key-codes
int VK_LBUTTON = 0x01;
int VK_RBUTTON = 0x02;

View File

@ -1,8 +1,10 @@
package com.danitheskunk.skunkworks.windows;
import com.danitheskunk.skunkworks.Recti;
import com.danitheskunk.skunkworks.Util;
import com.danitheskunk.skunkworks.Vec2i;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.*;
import com.sun.jna.ptr.IntByReference;
@ -188,11 +190,19 @@ public class Window {
var user32 = User32Extra.INSTANCE;
var dwm = Dwm.INSTANCE;
var out = new IntByReference();
//dwm.DwmGetWindowAttribute(hwnd, Dwm.DWMWA_CLOAKED, out.getPointer(), new WinDef.DWORD(WinDef.DWORD.SIZE));
dwm.DwmGetWindowAttribute(hwnd, Dwm.DWMWA_CLOAKED, out.getPointer(), new WinDef.DWORD(WinDef.DWORD.SIZE));
var val = out.getValue();
return val != 0;
}
public boolean isClass(String str) {
return str.equals(getClassName());
}
public boolean isExecutableName(String str) {
return str.equals(getExecutableName());
}
public boolean isInAltTabList() {
var user32 = User32Extra.INSTANCE;
var walk = user32.GetAncestor(hwnd, WinUser.GA_ROOTOWNER);
@ -210,9 +220,11 @@ public class Window {
return (getStyle() & User32Extra.WS_EX_TOOLWINDOW) != 0;
}
public void move(Vec2i pos, Vec2i size) {
public void move(Recti rectangle) {
var user32 = User32Extra.INSTANCE;
var dwm = Dwm.INSTANCE;
var pos = rectangle.getPos();
var size = rectangle.getSize();
var rect_with_shadow = new WinDef.RECT();
var rect_without_shadow = new WinDef.RECT();
@ -261,4 +273,47 @@ public class Window {
return windows;
}
public static void messageLoop() {
var user32 = User32Extra.INSTANCE;
var msg = new WinUser.MSG();
while(user32.GetMessage(msg, null, 0, 0) != 0) {
System.out.println("msg pump");
user32.TranslateMessage(msg);
user32.DispatchMessage(msg);
}
}
public static void onKey() {
var user32 = User32Extra.INSTANCE;
var kernel32 = Kernel32.INSTANCE;
var res = user32.SetWindowsHookEx(User32Extra.WH_KEYBOARD_LL, new WinUser.HOOKPROC() {
public WinDef.LRESULT callback(int nCode, WinDef.WPARAM wparam, WinDef.LPARAM lparam) {
System.out.println("got some message a");
return new WinDef.LRESULT(0);
}
}, null, 0);
if(res == null) {
throw new RuntimeException("Couldn't setwindowhookex: " + Native.getLastError());
}
}
public static void onNewWindow() {
var user32 = User32Extra.INSTANCE;
var kernel32 = Kernel32.INSTANCE;
var hmod = kernel32.GetModuleHandle("kernel32.dll");
//todo: try RegisterShellHookWindow instead
var res = user32.SetWindowsHookEx(User32Extra.WH_SHELL, new WinUser.HOOKPROC() {
public WinDef.LRESULT callback(int nCode, WinDef.WPARAM wparam, WinDef.LPARAM lparam) {
System.out.println("got some message b");
if(nCode == User32Extra.HSHELL_WINDOWCREATED) {
System.out.println("window created");
}
return new WinDef.LRESULT(0);
}
}, hmod, 0);
if(res == null) {
throw new RuntimeException("Couldn't setwindowhookex: " + Native.getLastError());
}
}
}