Re: Are VBA userforms always child of Windows desktop?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



It looks Spy++ presents this a bit confusing.
When I load a modeless userform then in Spy++ the treeview suggests that the form is a child of the desktop.
Also when you open up the hierarchy of XLMain then you I can't find the form.
But if you right-click the form icon in Spy++ and do properties, windows then you can see that XLMain is
the parent window.
Exactly same applies to a modal form.

RBS

"NickHK" <TungCheWah@xxxxxxxxxxx> wrote in message news:etCE4sopHHA.1852@xxxxxxxxxxxxxxxxxxxxxxx
Peter,
Whilst I would be the first to acknowledge my hazy understanding of Parent
v. Owner, I do notice this:

A quick look with Spy++ shows the owner and parent of a modeless userform to
be XLMAIN.
Not that sure what GetAncestor actually means, but here it returns something
different to GetParent

<From API-guide>
[in] Specifies the ancestor to be retrieved. This parameter can be one of
the following values.
GA_PARENT
Retrieves the parent window. This does not include the owner, as it does
with the GetParent function.
</From API-guide>

Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long

Private Sub UserForm_Activate()
Dim hwnMe&, hwnAncestor&, hwnDesktop&, hwnParent&, hwnXLMain&
Dim MstStr As String

hwnMe = FindWindowA("ThunderDFrame", Me.Caption)
hwnAncestor = GetAncestor(hwnMe, GA_PARENT)
hwnDesktop = GetDesktopWindow
hwnParent = GetParent(hwnMe)
hwnXLMain = FindWindowA("XLMAIN", Application.Caption)

MstStr = MstStr & "Me: " & hwnMe & vbCr
MstStr = MstStr & "Ancestor: " & hwnAncestor & vbCr
MstStr = MstStr & "Desktop: " & hwnDesktop & vbCr
MstStr = MstStr & "Parent : " & hwnParent & vbCr
MstStr = MstStr & "XLMAIN : " & hwnXLMain

MsgBox MstStr

End Sub

NickHK

"Peter T" <peter_t@discussions> wrote in message
news:enwrKDRpHHA.3952@xxxxxxxxxxxxxxxxxxxxxxx
Hi Bart,

Whenever I've looked, which is not that often, the Userform's window's
parent has always been the Desktop. But to check perhaps -

Private Declare Function FindWindowA Lib "user32" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function GetAncestor Lib "user32.dll" ( _
ByVal hwnd As Long, ByVal gaFlags As Long) As Long

Private Declare Function GetDesktopWindow Lib "user32" () As Long
Const GA_PARENT = 1

Private Sub UserForm_Activate()
Dim hwnMe&, hwnParent&, hwnDesktop&

hwnMe = FindWindowA("ThunderDFrame", Me.Caption)
hwnParent = GetAncestor(hwnMe, GA_PARENT)
hwnDesktop = GetDesktopWindow
MsgBox hwnMe & vbCr & hwnParent & vbCr & hwnDesktop

End Sub

> as I know I can alter the parent window of a form.

Do you know if it's possible to make a borderless/captionless VB6 form the
child of a userform, so it will remain withing the userform ?

Regards,
Peter T


"RB Smissaert" <bartsmissaert@xxxxxxxxxxxxxxxx> wrote in message
news:eQzW7SQpHHA.4112@xxxxxxxxxxxxxxxxxxxxxxx
> Had a look at some code in the the book of Bullen et Al, Professional
Excel
> Development.
> I thought that it was suggested that VBA Userforms are the children of
the
> Excel
> desktop window, but it appears that this is not the case and that these
> windows are the
> direct children of the Windows desktop.
> Is this always the case?
> I am interested in this as I need the form's hwnd.
> I used to do this with the FindWindow API and this only needs the > form's
> class name
> (ThunderDFrame or ThunderXFrame) and the form's caption.
> Possibly it is faster (not tested yet) to get this hwnd with the
> FindWindowEx API, but then
> I need to know for sure that the Windows desktop is indeed always the
parent
> of this form.
> This is directly after the window is created as I know I can alter the
> parent window of a form.
> Thanks for any advice/insight.
>
> RBS
>





.



Relevant Pages

  • Re: VBE Help: Size of code pane
    ... the child windows to fit inside the parent window. ... the userform Controls box appears somewhere near the userform instead of ...
    (microsoft.public.word.vba.general)
  • Re: VBA stealing keys from ActiveX control?
    ... >> We have a VB application that launches the VBA IDE. ... I create a UserForm that has a single TextBox in it. ... >> the backspace key in one window deletes text in another window. ...
    (microsoft.public.vb.general.discussion)
  • RE: Sounds and Title Bar (Userforms)
    ... Of course you can remove the 'titlebar' of a Userform in Excel! ... window and therefore we can apply to it any window style that is ... Private Declare Function GetWindowLong _ ...
    (microsoft.public.excel.programming)
  • Re: Hide Start Orb - Vista
    ... Get the process ID of the Explorer process that owns the task bar. ... If it is the same as Explorer's, get the window text. ... Work Software Systems ... I have used WinID and Spy & Capure, two tools that work just like Spy++, to ...
    (microsoft.public.vb.winapi)
  • Re: how to call a java script function in a child window from the
    ... The htm in the parent window and needs ... The child window displays a contact form that is to be ... I was trying to from the parent window script> ...
    (microsoft.public.frontpage.programming)