Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Advanced Subclassing

Status
Not open for further replies.

YerMom

Programmer
Oct 3, 2006
127
0
0
US
Hello.

I need to create an application that will subclass a control on a window within a third-party application. I tried the SetWindowLong function, using the GWL_WNDPROC flag, but then discovered the following note in the documentation:

"The SetWindowLong function fails if the window specified by the hWnd parameter does not belong to the same process as the calling thread."

Is it possible to do what I want to do?

Thanks.


 
Let's just tyake a quick overview here

Every process runs in it's own private address space. Address &H100 in for process A is not the same as address &H100 for process B

When you subclass, you pop in the address of your own function. This resides at say address &H400, so it is &H400 that replaces the window proc address. But in another process &H400 will not be pointing to your function. Indeed it is highly likely that it is pointing to an area of memory that is not the entry point for any function at all, and hence the other application would probably crash.

And that's why NT etc don't let you subclass across processes.

(there are ways around this involving the use of a DLL, and injecting code into other processes but in theory this isn't feasible with VB)

Perhaps if you can explain why you feel you need to subclass we can offer some alternative solutions.

 
Hi strongm,

Thanks very much for your explanation -- things are much clearer to me now.

Ultimately I don't know if subclassing is the best solution -- I chose it because I read about it in my VB win32 API Guide and decided to give it a try.I'm open to any solution. Also, I had chosen VB to do a prototype just to see if what I want to do is possible. I could very well use MFC or a straight C program.

Here's more detail about what I'm trying to do. The tech pubs people here at work use a very advanced editor for their work. The editor has a find dialog that allows you to search for text, but does not remember past searches the way a product such as MS Word does. I was thinking it would be useful to somehow add functionality to enable the "search for" field on the find dialog to cycle through a list of strings to search for. My only roadblock is figuring out how to interact with the "search for" field. Of course it's possible that something like this can't be done, but I wanted to give it a try.

Please let me know if you need more information.
 
You might want to have a look at an API call called AttachInputThread
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top