Get hWnd of the current window/form in VB6?
Asked Answered
S

3

6

Ho do I get hWnd of the current window/form in VB6?

Shuffleboard answered 15/2, 2010 at 14:11 Comment(0)
C
16

If you're on the form: Me.hWnd. If you don't know which form is the current form: Screen.ActiveForm.hWnd

Cormophyte answered 15/2, 2010 at 14:29 Comment(0)
M
8

Using Windows API, GetForegroundWindow() will get the handle of the topmost window regardless of which application it is from, and GetActiveWindow() will get the handle of your application's active window. The Declare statements you will need:

Declare Function GetForegroundWindow Lib "user32.dll" () As Long
Declare Function GetActiveWindow Lib "user32.dll" () As Long 

Calling either function will return a window handle as described above.

Mathew answered 15/2, 2010 at 14:34 Comment(0)
P
4

It's been a long time since I used VB6, but this is what I remember:

You'll want to open the API Viewer, which should be in the Start Menu around the VB6 entry. When you open it, you want to select win32api.txt, and you'll get a list of all of the Win32 API functions. This is the easiest way to not mess up the function signatures. Copy and paste the function declaration into one of your VB6 modules.

I always "cheated" and just looked for my window by caption name, instead of looping over all of the available windows with GetWindow. If you're okay with this, you want to use FindWindow and pass the caption name as the second parameter.

Phantasy answered 15/2, 2010 at 14:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.