Subclassing windows

Hello,

I've been digging through pages and pages of Google search results looking for some good examples on subclassing and hooking windows in C#, but have yet to find anything that adequately explains how to do so. I'm relatively new to C# and C++, so the the few things I've found thus far are pretty confusing to me. Maybe someone here can take a moment and point me in the right direction.

Here's what I'm trying to do, if possible: I want to subclass a FireFox window so I can intercept and inject messages to it.

Comments

  • I believe you can use the Process class to grab a specific process

    var ff = Process.GetProcessesByName("FireFox").FirstOrDefault();

    and from there you can grab the primary windows handle

    var hndl = ff.MainWindowHandle

    and then instantiate a window using the "Form" class

    var win = Form.FromHandle(hndl);


    buuuuut - I'm not sure your evironment is going to allow this since that would violate protected memory.

    what exactly is it you are trying to do?
    ><//~Psightoplasm`~
  • Honestly, I'm not trying to accomplish anything in particular, just messing around for now. I coded a in VB back when I was younger and just recently started messing around with C#. I'm just curious as to what exactly I can do with the language. I've been fooling with Java for over a year now and after realizing how much of a PIMA it is, I decided to switch my focus to C#.

    But anyways, I'm just trying to control Firefox from a C# app (to automate tasks). I don't need to be able to subclass it right away but eventually I would like to. I'm using SendMessage to send cmds, but I can't figure out how to get the handles of specific controls so I can send cmds to them indvidually. When I figure that out, I'll try to subclass so I can capture msgs.


  • Fair enough. - C# actually inherits from Java, but yes - it has some huge advantages, especially in its library and the fact that it is native to the windows environment.

    What I might suggest is to forget whatever strategies you had in the past with vb and sort of alter your way of attacking issues like this. Modern windows programming is much, much less about controlling the environment around/outside of your application and way more about giving your application the power it needs to do everything itself.

    True you can still screen scrape your way around other applications, but if you really explore the .net library you will find that you will never have to.

    As far as manipulating fire fox - Check out the "WebBrowser" control that you can add to your windows. This control gives you absolute control over the web pages you browse with it and you have access to the pages in the form of the Document Object Model. The DOM actually will give you such granular control over the web page that you can go in and change the values of hidden inputs, change a tags type or its value - or reorganize the structure of the page's html hierarchy all together and then STILL be able to interact with the server it came from.

    this by far is way more access then you would ever gain via a screen scraping application.

    Anyways - good luck and feel free to post any more questions here as you explore.
    ><//~Psightoplasm`~
  • I used to code AOL progz back in the day, which if you know anything about them, explains why I'm trying to code this kind of stuff today. :)

    That definitely makes sense to make more use of the .NET libraries, since they can do virtually anything. Given it'll probably take a lot more time and research, I'll start trying to do this stuff in my own app instead of hi-jacking Firefox.

    Thanks for the ideas, I really do appreciate it. :)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories