CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Mar 2010
    Posts
    48

    GetProcessesByName - Help grabbing java screenshot

    Okay, I moved from using "FindWindow" to "GetProcessesByName". My main goal is to get a screenshot of a java applet embedded into an internet browser. I thought you could simply get the process handle to java.exe, then go "MainWindowHandle", however apparently this is not the case.

    So the question is, how would I go about handling this. I wish to take a screenshot of this applet even if it's not currently in view. Thanks.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: GetProcessesByName - Help grabbing java screenshot

    The first thing to do is get out the Spy++ tool and check out the window hierarchy and process for the java applet.

    That will tell you what process you need to look for and, once you find the correct process, what the correct hierarchy is to get to the window you need to capture.

    As far as being able to capture a window that isn't visible... That's going to be a no-op. In order to capture the window, it must be visible.

  3. #3
    Join Date
    Mar 2010
    Posts
    48

    Re: GetProcessesByName - Help grabbing java screenshot

    Well, the window heiarchy is Mozilla, UI class, UI class, UI class, SunAwtFrame, SunAwtCanvis, SunAwtCanvis exc.. Now I know a way to get a screenshot of a window when it is not on top, or hidden behind other windows. Though I'm not sure how to get the handle of that SunAwtCanvis class.

    If anyone has an idea on how to get it, maybe using FindWindowEx, help would be appriciated.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: GetProcessesByName - Help grabbing java screenshot

    Quote Originally Posted by ADT_Clone View Post
    Now I know a way to get a screenshot of a window when it is not on top, or hidden behind other windows. Though I'm not sure how to get the handle of that SunAwtCanvis class.

    If anyone has an idea on how to get it, maybe using FindWindowEx, help would be appriciated.
    Let me try to say this again since you missed it the first time:

    You can't take a screenshot of a window if it is covered by another window.

    Typically you handle this by finding the window, move it to the top, and then take a screenshot of it.

  5. #5
    Join Date
    Aug 2008
    Posts
    902

    Re: GetProcessesByName - Help grabbing java screenshot

    Quote Originally Posted by Arjay View Post
    You can't take a screenshot of a window if it is covered by another window.
    In windows XP yes, but this might not be the case for Vista or Windows 7 since it uses a compositing window manager and has window previews.

  6. #6
    Join Date
    Mar 2010
    Posts
    48

    Re: GetProcessesByName - Help grabbing java screenshot

    Thank you Chris lol. I know it is possible to take a screenshot on Windows XP plus of a window behind another. Let me find the function:

    [DllImport("user32.dll")]
    private static extern bool PrintWindow(IntPtr hwnd, IntPtr hdcBlt,
    uint nFlags);

    It was a new addition to the Windows API.

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: GetProcessesByName - Help grabbing java screenshot

    Let me know how that works for you.

  8. #8
    Join Date
    Mar 2010
    Posts
    48

    Re: GetProcessesByName - Help grabbing java screenshot

    It doesn't work, that's why I've posted lol. I'm attempting to get the window handle for the java applet. However, when I try to get it from GetProcessByName("java"), it's MainWindowHandle is 0. So I don't actually know where I can find the window handle for the java applet.

  9. #9
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: GetProcessesByName - Help grabbing java screenshot

    What language are you coding in? Is it C#? If so, your in the wrong forum.

    At any rate, did you use the spy tool? You should use the spy tool and its Find window to select the window you want. Next, in the "Windows" tab, you click on Parent Window until you reach the outermost parent window, next click on the "Process" tab to get the process id. Convert the hex pid to decimal and find the process id in task manager to get the name of the process.

    In your case it may very well turn out to be "java" or "java.exe".

    As far as MainWindowHandle being 0, this handle isn't always set properly. Use the spy tool to what class and title is used for the main window, then use EnumWindows to retrieve it (and filter it by the process id).

  10. #10
    Join Date
    Apr 1999
    Posts
    27,449

    Re: GetProcessesByName - Help grabbing java screenshot

    Quote Originally Posted by ADT_Clone View Post
    Okay, I moved from using "FindWindow" to "GetProcessesByName". My main goal is to get a screenshot of a java applet embedded into an internet browser.
    May I ask why you're attempting to do this, instead of just using a program similar to Snag-It or some other utility?

    Regards,

    Paul McKenzie

  11. #11
    Join Date
    Mar 2010
    Posts
    48

    Re: GetProcessesByName - Help grabbing java screenshot

    This is part of a program that will then do image analysis. I would like to make it easy for the user so they don't have to select the program. It will always be a java applet.

  12. #12
    Join Date
    Mar 2010
    Posts
    48

    Re: GetProcessesByName - Help grabbing java screenshot

    Thank you for the help. I actually found another resource and found that by using repeated FindWindowEx commands, I can actually get this java applet and take a screenshot.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured