From 06f5eb914de73c93d8de8538e2d236266328cc2d Mon Sep 17 00:00:00 2001 From: "luca.mustacchio@outlook.it" Date: Sat, 31 Jan 2026 14:10:08 +0100 Subject: [PATCH] Aggiungere i file di progetto. --- WinFormsApp2.sln | 25 +++ WinFormsApp2/ApplicationEvents.vb | 29 +++ WinFormsApp2/Form1.Designer.vb | 74 +++++++ WinFormsApp2/Form1.resx | 120 +++++++++++ WinFormsApp2/Form1.vb | 192 ++++++++++++++++++ .../My Project/Application.Designer.vb | 37 ++++ WinFormsApp2/My Project/Application.myapp | 10 + WinFormsApp2/WinFormsApp2.vbproj | 36 ++++ 8 files changed, 523 insertions(+) create mode 100644 WinFormsApp2.sln create mode 100644 WinFormsApp2/ApplicationEvents.vb create mode 100644 WinFormsApp2/Form1.Designer.vb create mode 100644 WinFormsApp2/Form1.resx create mode 100644 WinFormsApp2/Form1.vb create mode 100644 WinFormsApp2/My Project/Application.Designer.vb create mode 100644 WinFormsApp2/My Project/Application.myapp create mode 100644 WinFormsApp2/WinFormsApp2.vbproj diff --git a/WinFormsApp2.sln b/WinFormsApp2.sln new file mode 100644 index 0000000..e1252b3 --- /dev/null +++ b/WinFormsApp2.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.35327.3 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "WinFormsApp2", "WinFormsApp2\WinFormsApp2.vbproj", "{508A856A-F65C-4020-8380-A914C8E423E2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {508A856A-F65C-4020-8380-A914C8E423E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {508A856A-F65C-4020-8380-A914C8E423E2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {508A856A-F65C-4020-8380-A914C8E423E2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {508A856A-F65C-4020-8380-A914C8E423E2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A222D55C-6BDC-4826-A2A4-3D87222D8F7F} + EndGlobalSection +EndGlobal diff --git a/WinFormsApp2/ApplicationEvents.vb b/WinFormsApp2/ApplicationEvents.vb new file mode 100644 index 0000000..cf403a0 --- /dev/null +++ b/WinFormsApp2/ApplicationEvents.vb @@ -0,0 +1,29 @@ +Imports Microsoft.VisualBasic.ApplicationServices + +Namespace My + ' The following events are available for MyApplication: + ' Startup: Raised when the application starts, before the startup form is created. + ' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally. + ' UnhandledException: Raised if the application encounters an unhandled exception. + ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. + ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected. + + ' **NEW** ApplyApplicationDefaults: Raised when the application queries default values to be set for the application. + + ' Example: + ' Private Sub MyApplication_ApplyApplicationDefaults(sender As Object, e As ApplyApplicationDefaultsEventArgs) Handles Me.ApplyApplicationDefaults + ' + ' ' Setting the application-wide default Font: + ' e.Font = New Font(FontFamily.GenericSansSerif, 12, FontStyle.Regular) + ' + ' ' Setting the HighDpiMode for the Application: + ' e.HighDpiMode = HighDpiMode.PerMonitorV2 + ' + ' ' If a splash dialog is used, this sets the minimum display time: + ' e.MinimumSplashScreenDisplayTime = 4000 + ' End Sub + + Partial Friend Class MyApplication + + End Class +End Namespace diff --git a/WinFormsApp2/Form1.Designer.vb b/WinFormsApp2/Form1.Designer.vb new file mode 100644 index 0000000..6b694a6 --- /dev/null +++ b/WinFormsApp2/Form1.Designer.vb @@ -0,0 +1,74 @@ + +Partial Class Form1 + Inherits System.Windows.Forms.Form + + 'Form overrides dispose to clean up the component list. + + Protected Overrides Sub Dispose(ByVal disposing As Boolean) + Try + If disposing AndAlso components IsNot Nothing Then + components.Dispose() + End If + Finally + MyBase.Dispose(disposing) + End Try + End Sub + + 'Required by the Windows Form Designer + Private components As System.ComponentModel.IContainer + + 'NOTE: The following procedure is required by the Windows Form Designer + 'It can be modified using the Windows Form Designer. + 'Do not modify it using the code editor. + + Private Sub InitializeComponent() + ListBox1 = New ListBox() + Button1 = New Button() + ListBox2 = New ListBox() + SuspendLayout() + ' + ' ListBox1 + ' + ListBox1.FormattingEnabled = True + ListBox1.ItemHeight = 15 + ListBox1.Location = New Point(23, 264) + ListBox1.Name = "ListBox1" + ListBox1.Size = New Size(765, 319) + ListBox1.TabIndex = 0 + ' + ' Button1 + ' + Button1.Location = New Point(23, 12) + Button1.Name = "Button1" + Button1.Size = New Size(119, 26) + Button1.TabIndex = 1 + Button1.Text = "Button1" + Button1.UseVisualStyleBackColor = True + ' + ' ListBox2 + ' + ListBox2.FormattingEnabled = True + ListBox2.ItemHeight = 15 + ListBox2.Location = New Point(22, 44) + ListBox2.Name = "ListBox2" + ListBox2.Size = New Size(766, 214) + ListBox2.TabIndex = 2 + ' + ' Form1 + ' + AutoScaleDimensions = New SizeF(7.0F, 15.0F) + AutoScaleMode = AutoScaleMode.Font + ClientSize = New Size(800, 625) + Controls.Add(ListBox2) + Controls.Add(Button1) + Controls.Add(ListBox1) + Name = "Form1" + Text = "Form1" + ResumeLayout(False) + End Sub + + Friend WithEvents ListBox1 As ListBox + Friend WithEvents Button1 As Button + Friend WithEvents ListBox2 As ListBox + +End Class diff --git a/WinFormsApp2/Form1.resx b/WinFormsApp2/Form1.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/WinFormsApp2/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WinFormsApp2/Form1.vb b/WinFormsApp2/Form1.vb new file mode 100644 index 0000000..8642af6 --- /dev/null +++ b/WinFormsApp2/Form1.vb @@ -0,0 +1,192 @@ +Imports System.Runtime.InteropServices +Imports System.Text +Imports System.Media +Imports System.Xml.Linq +Imports System.IO +'Imports NAudio.Wave + + +'Public Class AudioPlayer +' Private player As IWavePlayer +' Private reader As AudioFileReader + +' Public Sub Play(filePath As String) +' Try +' player = New WaveOutEvent() ' Usa DirectSound +' reader = New AudioFileReader(filePath) +' player.Init(reader) +' player.Play() +' Catch ex As Exception +' MessageBox.Show($"Errore durante la riproduzione: {ex.Message}") +' End Try +' End Sub + +' Public Sub StopPlayback() +' player?.Stop() +' reader?.Dispose() +' player?.Dispose() +' End Sub +'End Class + +Public Class Form1 + ' Costanti per l'hook della tastiera + Private Const WH_KEYBOARD_LL As Integer = 13 + Private Const WM_KEYDOWN As Integer = &H100 + + ' Delegati e handle dell'hook + Private Delegate Function HookProc(nCode As Integer, wParam As IntPtr, lParam As IntPtr) As IntPtr + Private Shared _hookID As IntPtr = IntPtr.Zero + Private Shared _proc As HookProc = AddressOf HookCallback + Private Shared setup As Boolean = False + + ' Dizionario per mappare i tasti ai file WAV + Private Shared keySoundMapping As New Dictionary(Of Keys, String)() + + ' Variabile per tracciare se siamo nella fase di selezione di un file per un tasto + Private Shared isSelectingFile As Boolean = False + + ' Percorso del file XML di configurazione + Private Shared configFilePath As String = "key_sound_mapping.xml" + + ' Importazioni delle API di Windows + + Private Shared Function SetWindowsHookEx(idHook As Integer, lpfn As HookProc, hMod As IntPtr, dwThreadId As UInteger) As IntPtr + End Function + + + Private Shared Function UnhookWindowsHookEx(hhk As IntPtr) As Boolean + End Function + + + Private Shared Function CallNextHookEx(hhk As IntPtr, nCode As Integer, wParam As IntPtr, lParam As IntPtr) As IntPtr + End Function + + + Private Shared Function GetModuleHandle(lpModuleName As String) As IntPtr + End Function + + ' Metodo per installare l'hook + Private Sub InstallHook() + Dim hMod = GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName) + _hookID = SetWindowsHookEx(WH_KEYBOARD_LL, _proc, hMod, 0) + If _hookID = IntPtr.Zero Then + MessageBox.Show("Errore nell'impostazione dell'hook.") + End If + End Sub + + ' Metodo per rimuovere l'hook + Private Sub RemoveHook() + If _hookID <> IntPtr.Zero Then + UnhookWindowsHookEx(_hookID) + End If + End Sub + + ' Callback dell'hook + Private Shared Function HookCallback(nCode As Integer, wParam As IntPtr, lParam As IntPtr) As IntPtr + If nCode >= 0 AndAlso wParam = CType(WM_KEYDOWN, IntPtr) Then + Dim vkCode = Marshal.ReadInt32(lParam) + Dim key = CType(vkCode, Keys) + + If setup Then + ' Modalità setup: mappa il tasto al file WAV + If Not isSelectingFile Then + isSelectingFile = True ' Inizia la selezione del file + Dim openFileDialog As New OpenFileDialog With { + .Filter = "File Audio WAV (*.wav)|*.wav", + .Title = $"Seleziona il file WAV per il tasto {key.ToString()}" + } + + If openFileDialog.ShowDialog() = DialogResult.OK Then + Dim selectedFilePath As String = openFileDialog.FileName + + ' Aggiunge o aggiorna la mappatura + If keySoundMapping.ContainsKey(key) Then + keySoundMapping(key) = selectedFilePath + Else + keySoundMapping.Add(key, selectedFilePath) + End If + + ' Salva il mapping in un file XML + SaveMappingsToFile() + + MessageBox.Show($"Associato il file '{selectedFilePath}' al tasto {key}.") + End If + + isSelectingFile = False ' Finisce la selezione del file + End If + Else + ' Modalità normale: riproduce il suono associato + If keySoundMapping.ContainsKey(key) Then + Dim soundFilePath = keySoundMapping(key) + Dim soundPlayer As New SoundPlayer(soundFilePath) + soundPlayer.Play() + + ' Aggiungi log nella ListBox + Current.ListBox1.Items.Add($"Premuto tasto: {key}, suono riprodotto.") + Else + ' Log nel caso non sia stato associato un suono + Current.ListBox1.Items.Add($"Nessun suono associato al tasto {key}.") + End If + Current.ListBox1.SelectedIndex = Current.ListBox1.Items.Count - 1 + End If + End If + + Return CallNextHookEx(_hookID, nCode, wParam, lParam) + End Function + + Public Shared Current As Form1 + + ' Metodo per salvare la mappatura dei tasti su file XML + Private Shared Sub SaveMappingsToFile() + ' Crea o aggiorna il file XML con la mappatura dei tasti + Dim xmlDoc As New XDocument( + New XElement("Mappings", + From entry In keySoundMapping + Select New XElement("Mapping", + New XElement("Key", entry.Key.ToString()), + New XElement("FilePath", entry.Value)) + ) + ) + + ' Salva il file XML + xmlDoc.Save(configFilePath) + LoadMappingsFromFile() + End Sub + + ' Metodo per caricare le mappature dei tasti da file XML + Private Shared Sub LoadMappingsFromFile() + If File.Exists(configFilePath) Then + Dim xmlDoc As XDocument = XDocument.Load(configFilePath) + + keySoundMapping = (From mapping In xmlDoc.Descendants("Mapping") + Let key = CType([Enum].Parse(GetType(Keys), mapping.Element("Key").Value), Keys) + Let filePath = mapping.Element("FilePath").Value + Select KeyValuePair.Create(key, filePath)).ToDictionary(Function(x) x.Key, Function(x) x.Value) + + ' Popola ListBox2 con i tasti e i relativi percorsi + Current.ListBox2.Items.Clear() + For Each kvp As KeyValuePair(Of Keys, String) In keySoundMapping + Current.ListBox2.Items.Add($"{kvp.Key.ToString()} - {kvp.Value}") + Next + End If + End Sub + + ' Eventi del form per installare/rimuovere l'hook + Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load + InstallHook() + Current = Me + Button1.Text = "Setup = " & setup.ToString() + + ' Carica la mappatura dei tasti all'avvio e popola ListBox2 + LoadMappingsFromFile() + End Sub + + Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing + RemoveHook() + End Sub + + Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click + setup = Not setup + Button1.Text = "Setup = " & setup.ToString() + End Sub +End Class diff --git a/WinFormsApp2/My Project/Application.Designer.vb b/WinFormsApp2/My Project/Application.Designer.vb new file mode 100644 index 0000000..007b31f --- /dev/null +++ b/WinFormsApp2/My Project/Application.Designer.vb @@ -0,0 +1,37 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + +Namespace My + + 'NOTE: This file is auto-generated; do not modify it directly. To make changes, + ' or if you encounter build errors in this file, go to the Project Designer + ' (go to Project Properties or double-click the My Project node in + ' Solution Explorer), and make changes on the Application tab. + ' + Partial Friend Class MyApplication + + + Public Sub New() + MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows) + Me.IsSingleInstance = False + Me.EnableVisualStyles = True + Me.SaveMySettingsOnExit = True + Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses + End Sub + + + Protected Overrides Sub OnCreateMainForm() + Me.MainForm = Form1 + End Sub + End Class +End Namespace diff --git a/WinFormsApp2/My Project/Application.myapp b/WinFormsApp2/My Project/Application.myapp new file mode 100644 index 0000000..0f12f32 --- /dev/null +++ b/WinFormsApp2/My Project/Application.myapp @@ -0,0 +1,10 @@ + + + true + Form1 + false + 0 + true + 0 + true + \ No newline at end of file diff --git a/WinFormsApp2/WinFormsApp2.vbproj b/WinFormsApp2/WinFormsApp2.vbproj new file mode 100644 index 0000000..f6d0d6a --- /dev/null +++ b/WinFormsApp2/WinFormsApp2.vbproj @@ -0,0 +1,36 @@ + + + + WinExe + net8.0-windows + Sub Main + true + WindowsForms + + + + + + + + + + + + + + + True + True + Application.myapp + + + + + + MyApplicationCodeGenerator + Application.Designer.vb + + + + \ No newline at end of file