Repository navigation
Expand file tree
/
Copy pathForm1.vb
More file actions
287 lines (214 loc) · 9.49 KB
/
Copy pathForm1.vb
File metadata and controls
287 lines (214 loc) · 9.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
Imports System.IO
Imports System.Net.WebRequestMethods
Imports System.Runtime.InteropServices
Imports System.Collections.Concurrent
Public Class Form1
' WorkerW Slideshow
'🎬 Ken Burns effect (zoom + pan durante fade)
'🌫 true Gaussian blur
'🧠 pipeline rendering ottimizzata GPU-style
'🖥 multi-monitor
' lord.marte@gmail.com
' 12-04-2026
' ===== Win32 =====
<DllImport("user32.dll")>
Private Shared Function FindWindow(lpClassName As String, lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll")>
Private Shared Function SendMessageTimeout(hWnd As IntPtr, msg As Integer, wParam As IntPtr, lParam As IntPtr,
flags As Integer, timeout As Integer,
ByRef lpdwResult As IntPtr) As IntPtr
End Function
<DllImport("user32.dll")>
Private Shared Function EnumWindows(lpEnumFunc As EnumWindowsProc, lParam As IntPtr) As Boolean
End Function
<DllImport("user32.dll")>
Private Shared Function FindWindowEx(parentHandle As IntPtr, childAfter As IntPtr,
className As String, windowTitle As String) As IntPtr
End Function
<DllImport("user32.dll")>
Private Shared Function SetParent(hWndChild As IntPtr, hWndNewParent As IntPtr) As IntPtr
End Function
Private Delegate Function EnumWindowsProc(hWnd As IntPtr, lParam As IntPtr) As Boolean
Private workerw As IntPtr = IntPtr.Zero
' ===== Slideshow =====
Private monitorForms As New List(Of MonitorForm)
Private immagini As List(Of String)
Private intervallo As Integer = 5000
Private index As Integer = 0
Private WithEvents timer As New Timer()
Private imgCurrent As Image = Nothing
Private pic1 As New PictureBox()
Private cacheFolder As String = Path.Combine(Path.GetTempPath(), "WorkerWCache")
Private urlSourceFile As String = ""
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.DoubleBuffered = True
Me.ShowInTaskbar = False
Me.WindowState = FormWindowState.Minimized
Me.Visible = False
' ===== WorkerW =====
Dim progman = FindWindow("Progman", Nothing)
Dim result As IntPtr = IntPtr.Zero
SendMessageTimeout(progman, &H52C, IntPtr.Zero, IntPtr.Zero, 2, 1000, result)
EnumWindows(Function(tophandle, topparamhandle)
Dim shellViewWin = FindWindowEx(tophandle, IntPtr.Zero, "SHELLDLL_DefView", Nothing)
If shellViewWin <> IntPtr.Zero Then
workerw = FindWindowEx(IntPtr.Zero, tophandle, "WorkerW", Nothing)
End If
Return True
End Function, IntPtr.Zero)
' ===== Carica immagini =====
Dim path = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)
Dim immagini = Directory.GetFiles(path, "*.*", SearchOption.TopDirectoryOnly).
Where(Function(f) f.EndsWith(".jpg") Or f.EndsWith(".png") Or f.EndsWith(".jpeg")).ToList()
Dim rnd As New Random()
immagini = immagini.OrderBy(Function(x) rnd.Next()).ToList()
' ===== Cache =====
If Not Directory.Exists(cacheFolder) Then
Directory.CreateDirectory(cacheFolder)
End If
' ===== CREA UNA FORM PER OGNI MONITOR =====
For Each screen In System.Windows.Forms.Screen.AllScreens
Dim f As New MonitorForm(immagini, intervallo)
f.Bounds = screen.Bounds
f.Show()
SetParent(f.Handle, workerw)
f.Start()
AddHandler f.ExitRequested, AddressOf ExitApp
monitorForms.Add(f)
Next
' SysTray
InitTray()
End Sub
Private Sub ChooseFolder(sender As Object, e As EventArgs)
' Scegli la cartella immagini
Using fbd As New FolderBrowserDialog()
If fbd.ShowDialog() = DialogResult.OK Then
Dim files = Directory.GetFiles(fbd.SelectedPath, "*.*", SearchOption.TopDirectoryOnly).
Where(Function(f) f.EndsWith(".jpg") Or f.EndsWith(".png") Or f.EndsWith(".jpeg")).ToList()
If files.Count = 0 Then
MessageBox.Show("Nessuna immagine trovata!")
Return
End If
Dim rnd As New Random()
immagini = files.OrderBy(Function(x) rnd.Next()).ToList()
' aggiorna tutte le form
For Each f In monitorForms
f.UpdateImages(immagini)
Next
End If
End Using
End Sub
' Cache
Private Async Function DownloadImageAsync(url As String) As Task(Of String)
Dim fileName = Path.GetFileName(New Uri(url).LocalPath)
Dim localPath = Path.Combine(cacheFolder, fileName)
If System.IO.File.Exists(localPath) Then Return localPath
Using client As New Net.Http.HttpClient()
Dim data = Await client.GetByteArrayAsync(url)
System.IO.File.WriteAllBytes(localPath, data)
End Using
Return localPath
End Function
Private Async Sub ChooseFile(sender As Object, e As EventArgs)
' Carica il file delle immagini online
Using ofd As New OpenFileDialog
ofd.Filter = "Files Testo|*.txt"
ofd.FileName = ""
ofd.Title = "Immagini HTTP/HTTPS..."
If ofd.ShowDialog(Me) = DialogResult.OK Then
Dim lines = System.IO.File.ReadAllLines(ofd.FileName).ToList()
Dim urls = lines.
Where(Function(l) Uri.IsWellFormedUriString(l, UriKind.Absolute)).
ToList()
If urls.Count = 0 Then Return
Dim tempImages As New ConcurrentBag(Of String)
Dim tasks As New List(Of Task)
For Each url In urls
Dim t = Task.Run(Async Function()
Try
Dim localPath = Await DownloadImageAsync(url)
tempImages.Add(localPath)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Function)
tasks.Add(t)
Next
Await Task.WhenAll(tasks)
' minimo 3 immagini
Do While tempImages.Count < 3
Await Task.Delay(100)
Loop
immagini = tempImages.ToList()
Dim rnd As New Random()
immagini = immagini.OrderBy(Function(x) rnd.Next()).ToList()
For Each f In monitorForms
f.UpdateImages(immagini)
Next
tray.ShowBalloonTip(1000, "Slideshow", "Caricamento completato", ToolTipIcon.Info)
End If
End Using
End Sub
Private Async Sub ReloadUrls(sender As Object, e As EventArgs)
' Ricarica il file
If String.IsNullOrEmpty(urlSourceFile) OrElse Not System.IO.File.Exists(urlSourceFile) Then
MessageBox.Show("Nessun file selezionato!")
Return
End If
Dim lines = System.IO.File.ReadAllLines(urlSourceFile).ToList()
Dim urls = lines.
Where(Function(l) Uri.IsWellFormedUriString(l, UriKind.Absolute)).
ToList()
If urls.Count = 0 Then
MessageBox.Show("Nessun URL valido trovato!")
Return
End If
' 🔥 RESET lista immagini (IMPORTANTE)
immagini.Clear()
For Each url In urls
Try
Dim localPath = Await DownloadImageAsync(url)
immagini.Add(localPath)
Catch ex As Exception
Console.WriteLine($"Errore: {url} -> {ex.Message}")
End Try
Next
' shuffle
Dim rnd As New Random()
immagini = immagini.OrderBy(Function(x) rnd.Next()).ToList()
' update monitor forms
For Each f In monitorForms
f.UpdateImages(immagini)
Next
tray.ShowBalloonTip(1000, "Slideshow", "Lista URL ricaricata", ToolTipIcon.Info)
End Sub
' SysTray
Private tray As New NotifyIcon()
Private traymenu As New ContextMenuStrip()
Private Sub InitTray()
tray.Icon = Me.Icon
tray.Text = "WorkerW Slideshow"
tray.Visible = True
traymenu.Items.Add("Scegli cartella", Nothing, AddressOf ChooseFolder)
traymenu.Items.Add("Scegli file Testo", Nothing, AddressOf ChooseFile)
traymenu.Items.Add("Ricarica lista URLS", Nothing, AddressOf ReloadUrls)
traymenu.Items.Add("Intervallo (secondi)", Nothing, AddressOf ChangeInterval)
traymenu.Items.Add(New ToolStripSeparator())
traymenu.Items.Add("Esci", Nothing, AddressOf ExitApp)
tray.ContextMenuStrip = traymenu
End Sub
Private Sub ChangeInterval(sender As Object, e As EventArgs)
Dim input = InputBox("Secondi tra le immagini:", "Intervallo", (intervallo / 1000).ToString())
If Integer.TryParse(input, Nothing) Then
intervallo = CInt(input) * 1000
For Each f In monitorForms
f.UpdateInterval(intervallo)
Next
End If
End Sub
Private Sub ExitApp()
tray.Visible = False
Application.Exit()
End Sub
End Class