Aggiungere i file di progetto.

This commit is contained in:
luca.mustacchio@outlook.it
2026-01-31 14:10:08 +01:00
parent 8479ece6bc
commit 06f5eb914d
8 changed files with 523 additions and 0 deletions

25
WinFormsApp2.sln Normal file
View File

@@ -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

View File

@@ -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

74
WinFormsApp2/Form1.Designer.vb generated Normal file
View File

@@ -0,0 +1,74 @@
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()>
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.
<System.Diagnostics.DebuggerStepThrough()>
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

120
WinFormsApp2/Form1.resx Normal file
View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

192
WinFormsApp2/Form1.vb Normal file
View File

@@ -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
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
Private Shared Function SetWindowsHookEx(idHook As Integer, lpfn As HookProc, hMod As IntPtr, dwThreadId As UInteger) As IntPtr
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
Private Shared Function UnhookWindowsHookEx(hhk As IntPtr) As Boolean
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
Private Shared Function CallNextHookEx(hhk As IntPtr, nCode As Integer, wParam As IntPtr, lParam As IntPtr) As IntPtr
End Function
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
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

View File

@@ -0,0 +1,37 @@
'------------------------------------------------------------------------------
' <auto-generated>
' 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.
' </auto-generated>
'------------------------------------------------------------------------------
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
<Global.System.Diagnostics.DebuggerStepThroughAttribute()>
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
<Global.System.Diagnostics.DebuggerStepThroughAttribute()>
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = Form1
End Sub
End Class
End Namespace

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MySubMain>true</MySubMain>
<MainForm>Form1</MainForm>
<SingleInstance>false</SingleInstance>
<ShutdownMode>0</ShutdownMode>
<EnableVisualStyles>true</EnableVisualStyles>
<AuthenticationMode>0</AuthenticationMode>
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
</MyApplicationData>

View File

@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<StartupObject>Sub Main</StartupObject>
<UseWindowsForms>true</UseWindowsForms>
<MyType>WindowsForms</MyType>
</PropertyGroup>
<ItemGroup>
<Import Include="System.Data" />
<Import Include="System.Drawing" />
<Import Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NAudio" Version="2.2.1" />
</ItemGroup>
<ItemGroup>
<Compile Update="My Project\Application.Designer.vb">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Application.myapp</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Update="My Project\Application.myapp">
<Generator>MyApplicationCodeGenerator</Generator>
<LastGenOutput>Application.Designer.vb</LastGenOutput>
</None>
</ItemGroup>
</Project>