a) To prevent the modeless window from capturing the Escape key, you can handle the KeyDown
event of the window and check if the pressed key is Escape. If it is, you can set the Handled
property of the KeyEventArgs
object to true
, which will prevent the key from being processed by the window. Here's an example:
Private Sub ModelessForm_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then
e.Handled = True
' End the slideshow here
End If
End Sub
b) To find the handle of the Presenter View window, you can use the FindWindow
function from the user32.dll
library. The window class name of the Presenter View window is "screenClass", so you can pass that as the lpClassName
parameter to the function. Once you have the handle, you can use it as the owner of your modeless window by setting the Owner
property of the window to the handle. Here's an example:
' Import the FindWindow function from user32.dll
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
' Find the Presenter View window by class name
Dim presenterViewHandle As IntPtr = FindWindow("screenClass", Nothing)
' Set the Presenter View window as the owner of the modeless form
ModelessForm.Owner = presenterViewHandle
Note that you should call this code after the Presenter View window has been created, which may not happen immediately when the slideshow starts. You can use a timer to periodically check if the window has been created and then set the owner when it is available.