Results 1 to 10 of 15

Hybrid View

  1. #1
    Join Date
    Dec 2004
    Location
    Wisconsin
    Posts
    1,422

    C# (or C++) Get window handle

    Hey everybody -

    I am in need... I need a way to get a handle for a specified window, so later I can then call that window, and make it active.

    I've looked around, and everything is a bit over my head atm, and was wondering if someone knew how to do this, and break it down a bit for me




    Oh... and w00t 1,000th post

  2. #2
    Join Date
    Mar 2004
    Posts
    0
    hmm, im not understanding you, dude

    if you are using C#, you can have a reference to the form you want to activate later, and call the Show() function if the window has not been shown, change the Visable property to true if the window was hidden, or the Focus() function if you just want to bring the window to the front and select it.
    for example, if you have a form class entitled OptionsForm in your program (IE, it was created in the form designer), if another pice of you you could put
    OptionsForm frm = new OptionsForm(); frm.Show();
    to show the form, or you could save it as a member variable so you can focus/show/make visable the form later.

    is that what you were looking for?

  3. #3
    Join Date
    Dec 2004
    Location
    Wisconsin
    Posts
    1,422
    No not quite. I'm looking to bring focus to a window which is outside of my C# app. Here is what my objective is:

    At work, I must enter a bunch of rudundant data into a really old (1986'ish) command prompt type application. It is very boring and tedious.

    I'd like to create a GUI front-end for it. Since I have no access to the source code of the app, or any other options regarding updating the actual original program - the only wat I can see to do it is with a really nasty hack.

    What I plan to do is rather simple really. First I will 'monitor' the command window by copying all the text from that prompt - then parsing through that text to determine the various fields on that part of the program.

    This is where I would need to find all the active window's handles, so I can select which window to grab the text from. I will then will use a SendKeys command to the prompt to select all the text, then ctrl-c to copy all that text to the clipboard, and finally bring that text into my C# app to parse.

    After I figure out which fields to input the data to, I will then need to go back into the command prompt and SendKeys again to fill out the various fields.


    That's pretty much what I have planned for the basic version of this; although I'd like to extend it so it actually pulls all the data I need to input from a different prompt, and adds it into the other correct prompt.

    It's all a part of my evil, maniacal plan to make myself indispensable person at work since I am only a temp.

  4. #4
    Join Date
    Oct 2002
    Location
    Leicester, UK
    Posts
    3,335
    This site has an example of using the Win32 FindWindow() function from .NET.

    Another possible approach: Maybe you could get the input and output streams of the command line program and manipulate them?
    Forget the username, call me Keith

  5. #5
    Join Date
    Dec 2004
    Location
    Wisconsin
    Posts
    1,422
    Quote Originally Posted by keithathaide
    This site has an example of using the Win32 FindWindow() function from .NET.

    Another possible approach: Maybe you could get the input and output streams of the command line program and manipulate them?
    That looks like it might work. I'm not totally sure on how to use it, but haven't had much time to look at it either.

    The app isn't a command line per se, it is a prompt - I've already tried to explain this to ostamo, and failed badly. So I'll post some screen shots of what I'm working with lol

    Thanks (yet again) for the link Keith

  6. #6
    Join Date
    Jun 2005
    Location
    NY
    Posts
    1,374
    This is for C++ since I don't know too much C#.

    Code:
    HWND fWindow; // Window handle of the window you want to get
    
    fWindow = FindWIndow(NULL, "Text_Of_Window_To_Find"); // Find the window
    
    BringWindowToTop(fWindow); // Activate the window
    Pretty straightfoward.

    MSDN Function References:
    FindWindow()
    BringWindowToTop()
    CodeGuru: DLL Tutorial For Beginners by me. Rated 4 1/2 out of 5.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •