I am making a bare bone application and I would like to avoid adding a form class to my project.
Here is what I have done so far
First my new project is a "Empty Project (.NET framework"

Then I added a single empty class file

Then I added the system.windows.forms reference to my project

Lastly I add the following code
Imports System.Windows.Forms
Public Class AppCore
Inherits ApplicationContext
Shared Sub main()
Dim myAppCore As AppCore
myAppCore = New AppCore
System.Windows.Forms.Application.Run(myAppCore)
End Sub
End Class
From that point on, I have a barebone working app that does nothing but stays running forever.
Now I want to registers the keys combo "ALT+F6" and "ALT+F7"
I add the following code
Public Const MOD_CONTROL As Integer = &H11
Public Const MOD_SHIFT As Integer = &H10
Public Const MOD_ALT As Integer = &H1
Public Const WM_HOTKEY As Integer = &H312
Public Declare Function RegisterHotKey Lib "user32.dll" Alias "RegisterHotKey" (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Integer
Public Declare Function UnregisterHotKey Lib "user32.dll" Alias "UnregisterHotKey" (ByVal hwnd As IntPtr, ByVal id As Integer) As Integer
Sub New()
RegisterHotKey(Me.Handle, 100, MOD_ALT, Keys.F6)
RegisterHotKey(Me.Handle, 200, MOD_ALT, Keys.F7)
End Sub
Protected Overrides Sub DefWndProc(ByRef m As System.Windows.Forms.Message)
MyBase.DefWndProc(m)
Dim x As Long
If m.Msg = WM_HOTKEY Then
Select Case CType(m.WParam, Integer)
Case 100
Beep()
Case 200
Beep()
End Select
End If
End Sub
This is where I run into trouble
First in Sub New(), the IDE is telling me that Handle is not part of appcore/applicationcontext

Second, I get the following error

At this point I am stuck !
How can I create hotkeys without adding a form ?
For DefWndProc, maybe I can get away with only removing the "Overrides" keywork and dropping "MyBase.DefWndProc(m)" ?
But I think the bigger problem is how to get a handle ? Maybe I should look at the CreateWindow API ?
EDIT :
I have modified this project to include a new class of type NativeWindow
as follows
Imports System.Windows.Forms
Public Class clsHotkey
Inherits NativeWindow
Public Const WM_HOTKEY As Integer = &H312
Protected Overloads Sub DefWndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_HOTKEY Then
Select Case CType(m.WParam, Integer)
Case 100
Console.WriteLine("ID 100")
Case 200
Console.WriteLine("ID 200")
End Select
End If
End Sub
End Class
This provides the bare minimum to have a window handle for RegisterHotkey. I have also modified the AppCore class to work with it.
It compiles and runs without error but the hotkeys do nothing
I believe this is because I have replaced the override keywork in the definition of the DefWndProc subroutine by overloads
If I try to use overrides, I get the following error
BC31086 'Protected Overrides Sub DefWndProc(ByRef m As Message)' cannot override 'Public Overloads Sub DefWndProc(ByRef m As Message)' because it is not declared 'Overridable'.
At this point I am stuck. I would rather not use a form class because of the added complexity (especially the addition of a designer file for it which will make manual compiling more complicated)
Is there a way to make it work with NativeWindow class ? Or some other alternative class that can obtain a window handle ?
Thanks !