QAID # 1037 Published
Question / Problem:
How can I determine the current module from a Custom Panel?
Answer / Solution:
There is no exposed property that reports the current module, however there are two possible workarounds:
- You can register the Panel twice, giving them two different Display Names for the different modules. In the code you can access the Panel name (using the Application object's PanelName property) and associate this with the given module.
- You can use the Windows API to get the parent window of the Panel and obtain the name this way.
Public Function GetAscentModuleName(hwnd As Long) As String Dim lRtn, hParent As Long Dim sText As String * 256 hParent = GetAncestor(hwnd, 2) sText = String(256, 0) lRtn = GetWindowText(hParent, sText, 255) GetAscentModuleName = Trim(Replace(sText, vbNullChar, " ")) End Function
- hWnd is passed in and is the handle to the Custom Panel.
- GetAncestor traverses windows until it finds the window that started it all (excluding the desktop).