By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,948 Members | 1,553 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,948 IT Pros & Developers. It's quick & easy.

Subclassing problem... CROSS

P: n/a
Why can't I subclass any window except mine in VB?
Do I have to write dll for this?
I've tried to subclass it with SetWindowLong but without success...

Does anyone know how to subclass window ANY window in VB?

Thanks...

Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On Sat, 23 Aug 2003 22:16:30 +0200, WhiteRavenEye
<wh***********@hotmail.com> wrote:
Why can't I subclass any window except mine in VB?
Do I have to write dll for this?
I've tried to subclass it with SetWindowLong but without success...

Does anyone know how to subclass window ANY window in VB?

SetWindowsHookEx, but you'll have to have it in a real DLL.

--

Regards, Frank
Jul 17 '05 #2

P: n/a
fa**@xxxxoptushome.com.au (Frank Adam) wrote in message news:<3f****************@news-vip.optusnet.com.au>...
On Sat, 23 Aug 2003 22:16:30 +0200, WhiteRavenEye
<wh***********@hotmail.com> wrote:
Why can't I subclass any window except mine in VB?
Do I have to write dll for this?
I've tried to subclass it with SetWindowLong but without success...

Does anyone know how to subclass window ANY window in VB?

SetWindowsHookEx, but you'll have to have it in a real DLL.


That is not subclassing, that is window hooking (which has similar
effects, but essentially copies the window message, unlike subclassing
where it's your job to forward the message back to the original
procedure).

So why doesn't it work with SetWindowLong? Form MSDN: "GWL_WNDPROC:
[...] You cannot change this attribute if the window does not belong
to the same process as the calling thread."
So you cannot subclass windows of other processes.
Seems like window hooking may be your only way to go.

Robert
Jul 17 '05 #3

P: n/a
Asperamanca wrote:
fa**@xxxxoptushome.com.au (Frank Adam) wrote in message news:<3f****************@news-vip.optusnet.com.au>...
On Sat, 23 Aug 2003 22:16:30 +0200, WhiteRavenEye
<wh***********@hotmail.com> wrote:

Why can't I subclass any window except mine in VB?
Do I have to write dll for this?
I've tried to subclass it with SetWindowLong but without success...

Does anyone know how to subclass window ANY window in VB?


SetWindowsHookEx, but you'll have to have it in a real DLL.

That is not subclassing, that is window hooking (which has similar
effects, but essentially copies the window message, unlike subclassing
where it's your job to forward the message back to the original
procedure).

So why doesn't it work with SetWindowLong? Form MSDN: "GWL_WNDPROC:
[...] You cannot change this attribute if the window does not belong
to the same process as the calling thread."
So you cannot subclass windows of other processes.
Seems like window hooking may be your only way to go.

Robert


I must have missed that part of MSDN...
Looks like I'll have to write dll in Delphi...
Too bad it can't be written in VB... Damn ActiveX DLL...
Anyway thanks...

By WhiteRavenEye

Jul 17 '05 #4

P: n/a
On Mon, 25 Aug 2003 12:00:12 +0200, WhiteRavenEye
<wh***********@hotmail.com> wrote:
<snip>

I must have missed that part of MSDN...
Looks like I'll have to write dll in Delphi...
Too bad it can't be written in VB... Damn ActiveX DLL...
Anyway thanks...


I may be wrong, but I believe that the SetWindowsHookEx is mainly
about 'snooping' - not really subclassing

<snip>
Chaining to the next hook procedure (that is, calling the
CallNextHookEx function) is optional. An application or library can
call the next hook procedure either before or after any processing in
its own hook procedure. Although chaining to the next hook is
optional, it is highly recommended; otherwise, the other applications
that have installed hooks will not receive hook notifications and may
behave incorrectly as a result
</snip>

However the Help Files are a bit unclear on all this
Jul 17 '05 #5

P: n/a
On 25 Aug 2003 00:20:31 -0700, as*********@yahoo.com (Asperamanca)
wrote:
fa**@xxxxoptushome.com.au (Frank Adam) wrote in message news:<3f****************@news-vip.optusnet.com.au>...
On Sat, 23 Aug 2003 22:16:30 +0200, WhiteRavenEye
<wh***********@hotmail.com> wrote:
>Why can't I subclass any window except mine in VB?
>Do I have to write dll for this?
>I've tried to subclass it with SetWindowLong but without success...
>
>Does anyone know how to subclass window ANY window in VB?
> SetWindowsHookEx, but you'll have to have it in a real DLL.


That is not subclassing, that is window hooking (which has similar
effects, but essentially copies the window message, unlike subclassing
where it's your job to forward the message back to the original
procedure).

So CallNextHookEx is just for kicks ?
SetwindowsHook installs a hook at the start of the chain, a subclass
replaces the procedure's address with an address of it's own handler.
IOW, it chains 'in', instead of in front. The difference is minimal up
to that point.
When it comes to handling and changing the messages it gets a litlle
trickier using the hook.. Blocking is easy enough.
So you cannot subclass windows of other processes.
Seems like window hooking may be your only way to go.

Hm.. if only i would have thought of that.. ;-p

--

Regards, Frank
Jul 17 '05 #6

P: n/a
> SetwindowsHook installs a hook at the start of the chain, a subclass
replaces the procedure's address with an address of it's own handler.
IOW, it chains 'in', instead of in front. The difference is minimal up
to that point.
When it comes to handling and changing the messages it gets a litlle
trickier using the hook.. Blocking is easy enough.


There are some serious differences in performance and stability.
Subclassing is somewhat faster than hooking (in my experience), and
some types of hooks are explicitly labeled "for debugging purposes
only" (but not the kind we're talking about). On the other hand, there
are things you can do with a hook that you cannot do with subclassing
(as we found out), also things like monitoring all keyboard / mouse
events.

Robert
Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.