質問するログイン新規登録

回答編集履歴

2

見直しキャンペーン中

2023/08/12 14:44

投稿

TN8001
TN8001

スコア10193

answer CHANGED
@@ -1,7 +1,7 @@
1
1
  Windows限定です。すべて貫通するので移動ができません。
2
2
  ざっと試した限りは動いてそうですが、何か問題があるかもしれません。
3
3
 
4
- `jna-5.6.0.jar`・`jna-platform-5.6.0.jar`を、エディタにドロップするなりして使えるようにしておきます。
4
+ `jna-5.6.0.jar`・`jna-platform-5.6.0.jar`を、エディタにドロップするなりして使えるようにしておきます。
5
5
  [java-native-access/jna: Java Native Access](https://github.com/java-native-access/jna)
6
6
  ```Processing
7
7
  import processing.awt.PSurfaceAWT;

1

見直しキャンペーン中

2023/08/12 14:43

投稿

TN8001
TN8001

スコア10193

answer CHANGED
@@ -1,67 +1,63 @@
1
- Windows限定です。
2
- すべ貫通するの移動できません。
3
- ざっと試した限りは動いてそうですが、何か問題があるかもしれません。
4
-
5
- `jna-5.6.0.jar`
6
- `jna-platform-5.6.0.jar`
7
- [java-native-access/jna: Java Native Access](https://github.com/java-native-access/jna)
8
- をエディタにドロップするなりして、使えるようにしておきます。
9
-
10
- ```Processing
11
- import processing.awt.PSurfaceAWT;
12
-
13
- import java.awt.Component;
14
- import java.awt.Frame;
15
-
16
- import com.sun.jna.Native;
17
- import com.sun.jna.platform.win32.User32;
18
- import com.sun.jna.platform.win32.WinDef;
19
- import com.sun.jna.platform.win32.WinUser;
20
-
21
- void setup() {
22
- size(300, 150);
23
- frameRate(1);
24
- stroke(255);
25
- textSize(72);
26
-
27
- PSurfaceAWT awtSurface = (PSurfaceAWT)surface;
28
- PSurfaceAWT.SmoothCanvas smoothCanvas = (PSurfaceAWT.SmoothCanvas)awtSurface.getNative();
29
- Frame frame = smoothCanvas.getFrame();
30
-
31
- frame.removeNotify();
32
- frame.setSize(width, height);
33
- frame.setAlwaysOnTop(true);
34
- frame.setUndecorated(true);
35
- frame.setOpacity(0.5f);
36
- frame.addNotify();
37
-
38
- setTransparent(frame);
39
- }
40
-
41
- void draw() {
42
- background(0);
43
- if (second() % 2 == 0)
44
- text(nf(hour(), 2) + ":" + nf(minute(), 2), 50, 100);
45
- else
46
- text(nf(hour(), 2) + " " + nf(minute(), 2), 50, 100);
47
- }
48
-
49
- // [swing - Java: Making a window click-through (including text/images) - Stack Overflow](https://stackoverflow.com/questions/11217660/java-making-a-window-click-through-including-text-images)
50
- private static void setTransparent(Component w) {
51
- WinDef.HWND hwnd = getHWnd(w);
52
- int wl = User32.INSTANCE.GetWindowLong(hwnd, WinUser.GWL_EXSTYLE);
53
- wl = wl | WinUser.WS_EX_LAYERED | WinUser.WS_EX_TRANSPARENT;
54
- User32.INSTANCE.SetWindowLong(hwnd, WinUser.GWL_EXSTYLE, wl);
55
- }
56
-
57
- private static WinDef.HWND getHWnd(Component w) {
58
- WinDef.HWND hwnd = new WinDef.HWND();
59
- hwnd.setPointer(Native.getComponentPointer(w));
60
- return hwnd;
61
- }
62
- ```
63
-
64
- 参考
65
- [swing - Java: Making a window click-through (including text/images) - Stack Overflow](https://stackoverflow.com/questions/11217660/java-making-a-window-click-through-including-text-images)
66
-
1
+ Windows限定です。すべて貫通するので移動ができません。
2
+ ざっと試した限りは動いそう、何か問題があるかもしれません。
3
+
4
+ `jna-5.6.0.jar`・`jna-platform-5.6.0.jar`を、エディタにドロップするなりして、使えるようにしておきます。
5
+ [java-native-access/jna: Java Native Access](https://github.com/java-native-access/jna)
6
+ ```Processing
7
+ import processing.awt.PSurfaceAWT;
8
+
9
+ import java.awt.Component;
10
+ import java.awt.Frame;
11
+
12
+ import com.sun.jna.Native;
13
+ import com.sun.jna.platform.win32.User32;
14
+ import com.sun.jna.platform.win32.WinDef;
15
+ import com.sun.jna.platform.win32.WinUser;
16
+
17
+ void setup() {
18
+ size(300, 150);
19
+ frameRate(1);
20
+ stroke(255);
21
+ textSize(72);
22
+
23
+ PSurfaceAWT awtSurface = (PSurfaceAWT)surface;
24
+ PSurfaceAWT.SmoothCanvas smoothCanvas = (PSurfaceAWT.SmoothCanvas)awtSurface.getNative();
25
+ Frame frame = smoothCanvas.getFrame();
26
+
27
+ frame.removeNotify();
28
+ frame.setSize(width, height);
29
+ frame.setAlwaysOnTop(true);
30
+ frame.setUndecorated(true);
31
+ frame.setOpacity(0.5f);
32
+ frame.addNotify();
33
+
34
+ setTransparent(frame);
35
+ }
36
+
37
+ void draw() {
38
+ background(0);
39
+ if (second() % 2 == 0)
40
+ text(nf(hour(), 2) + ":" + nf(minute(), 2), 50, 100);
41
+ else
42
+ text(nf(hour(), 2) + " " + nf(minute(), 2), 50, 100);
43
+ }
44
+
45
+ // [swing - Java: Making a window click-through (including text/images) - Stack Overflow](https://stackoverflow.com/questions/11217660/java-making-a-window-click-through-including-text-images)
46
+ private static void setTransparent(Component w) {
47
+ WinDef.HWND hwnd = getHWnd(w);
48
+ int wl = User32.INSTANCE.GetWindowLong(hwnd, WinUser.GWL_EXSTYLE);
49
+ wl = wl | WinUser.WS_EX_LAYERED | WinUser.WS_EX_TRANSPARENT;
50
+ User32.INSTANCE.SetWindowLong(hwnd, WinUser.GWL_EXSTYLE, wl);
51
+ }
52
+
53
+ private static WinDef.HWND getHWnd(Component w) {
54
+ WinDef.HWND hwnd = new WinDef.HWND();
55
+ hwnd.setPointer(Native.getComponentPointer(w));
56
+ return hwnd;
57
+ }
58
+ ```
59
+
60
+ 参考
61
+ [swing - Java: Making a window click-through (including text/images) - Stack Overflow](https://stackoverflow.com/questions/11217660/java-making-a-window-click-through-including-text-images)
62
+
67
63
  ![アプリ画像](70cd3cd8a82781325388f852af28d903.png)