Can NativeWindow be used for a window whose handle isn't exposed by a Form or Control in the current WinForms app?

Robert Gustafson 606 Reputation points
2023-01-19T07:07:52.73+00:00

WHAT I HAVE:

Visual Basic 2019, WinForms, .NET Framework 4 and up

MY ISSUE:

I wonder if a NativeWindow instance can be assigned the handle for a window that isn't exposed by one of the current WinForms app's forms or controls so that it can catch such a window's messages--for instance, the handle to a combo box's drop-down list (which has to be retrieved using Win32 API), or the handle to a window in a foreign process (retrieved by, say, Process.MainWindowHandle). My intuition says yes, but I want to be sure.

Please reply ASAP, and given any answers in VB.NET and as simply as possible.

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,827 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,568 questions
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. Castorix31 81,636 Reputation points
    2023-01-19T09:18:22.1833333+00:00

    so that it can catch such a window's messages

    or the handle to a window in a foreign process

    Not for external processes, where a Global hook (DLL) is needed to intercept windows messages


  2. Robert Gustafson 606 Reputation points
    2023-01-25T03:56:55.6666667+00:00

    To: Castorix31

    You just answered my questions. Thank you!