Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SetParent or SetWindowLong

423 views
Skip to first unread message

RB Smissaert

unread,
May 21, 2009, 6:08:50 AM5/21/09
to
Using these API's in VB6 to change the parent window and wonder what the
difference is between these two
and which one is the preferred one to use. Did a good Google for this, but
can find anything that explains.
Appleman's book doesn't tell either.

RBS

Juergen Thuemmler

unread,
May 21, 2009, 2:00:48 PM5/21/09
to
Hi RBS,

SetParent() lets a window (control or form) behave like a "real" child of
another window (one of your own or even a foreign window); it is sticked to
the parent, but it is still your window: you'll get the events etc. I'm
using it to give the MS OE Toolbar a new button (a VB picturebox) for
storing a interesting newsgroup posting in a textfile.
The function
Function SetOwner&(ByVal hwndOwned&, ByVal hwndOwner&)
SetOwner = SetWindowLong(hwndOwned, GWL_HWNDPARENT, hwndOwner)
End Function
lets the hwndOwned be an owned window of hwndOwner. That's the same as
frmOwned.Show , frmOwner
frmOwned is displayed in front of frmOwner, will be invisible when frnOwner
is minimized, but will not be moved together with frmOwner.

Juergen.


Nobody

unread,
May 21, 2009, 3:13:19 PM5/21/09
to
"RB Smissaert" <bartsm...@blueyonder.co.uk> wrote in message
news:Owsxqwf2...@TK2MSFTNGP06.phx.gbl...

First, try using "Container" Property, so VB knows which window is a child
or a parent.

Second, from SetWindowLong Remarks section: "You must not call SetWindowLong
with the GWL_HWNDPARENT index to change the parent of a child window.
Instead, use the SetParent function."

Third, if you use SetParent, make sure that you save the old parent, and
restore the parent before existing. I had once an API created control and
used SetParent to glue it to a form, and the application would crash when
exiting under Windows 98, but not under XP. The solution was to set the
parent back. Make sure that the hWnd for the parent is still the same,
perhaps by using IsWindow() and checking the class name. You can also use
SetProp() to be sure that you are dealing with the same window.

RB Smissaert

unread,
May 21, 2009, 4:04:59 PM5/21/09
to
Thanks to both and I will go for SetParent then and make sure to return to
the original Parent
before closing the form. Can't do Container etc. as I am coding this in VBA.

RBS


"RB Smissaert" <bartsm...@blueyonder.co.uk> wrote in message
news:Owsxqwf2...@TK2MSFTNGP06.phx.gbl...

MikeD

unread,
May 22, 2009, 9:00:24 AM5/22/09
to
Then why did you specifically say VB6? If you give misinformation like that, you're going to get non-relevant, or in some cases
downright incorrect, answers.

--
Mike


"RB Smissaert" <bartsm...@blueyonder.co.uk> wrote in message news:e020z9k2...@TK2MSFTNGP03.phx.gbl...

RB Smissaert

unread,
May 23, 2009, 7:52:34 AM5/23/09
to
I am using them in both VB6 and VBA and I think I got relevant answers.

RBS


"MikeD" <nob...@nowhere.edu> wrote in message
news:OrFmG1t2...@TK2MSFTNGP02.phx.gbl...

MikeD

unread,
May 23, 2009, 8:47:01 AM5/23/09
to

"RB Smissaert" <bartsm...@blueyonder.co.uk> wrote in message
news:%23qUsA05...@TK2MSFTNGP02.phx.gbl...

>I am using them in both VB6 and VBA and I think I got relevant answers.
>

I was talking more about future posts. Although even in this case, the
suggestion to use the Container property was non-relevant and if you had
said VBA instead of VB6, we'd have known that. Also, it wouldn't surprise
me at all if SetParent "behaves" differently ,or doesn't work at all, with
VBA UserForms. I'm just saying that misinformation on what you're actually
using can lead to bad answers.

--
Mike

RB Smissaert

unread,
May 23, 2009, 11:06:34 AM5/23/09
to
> the suggestion to use the Container property was non-relevant

It wasn't as I use this in VB6 as well.

RBS


"MikeD" <nob...@nowhere.edu> wrote in message

news:Opl2US62...@TK2MSFTNGP06.phx.gbl...

MikeD

unread,
May 23, 2009, 3:26:35 PM5/23/09
to

"RB Smissaert" <bartsm...@blueyonder.co.uk> wrote in message
news:usPUbg72...@TK2MSFTNGP04.phx.gbl...

>> the suggestion to use the Container property was non-relevant
>
> It wasn't as I use this in VB6 as well.
>


I'm not trying to be an idiot or anything, but why then did you write:

> Can't do Container etc. as I am coding this in VBA.

I'm just trying to understand. It seems like you're saying one thing and
then in your next message, something completely different.

--
Mike

RB Smissaert

unread,
May 23, 2009, 3:51:31 PM5/23/09
to
It was mainly for VBA, but also for VB6.

RBS


"MikeD" <nob...@nowhere.edu> wrote in message

news:eZwNnx92...@TK2MSFTNGP03.phx.gbl...

0 new messages