Results 1 to 7 of 7

Thread: Check pixel at x,y of an app's window (RESOLVED)

  1. #1

    Thread Starter
    Addicted Member SavedByGrace's Avatar
    Join Date
    May 2006
    Posts
    130

    Smile Check pixel at x,y of an app's window (RESOLVED)

    We are running an old bbs DOS based (bulletin board system) in a windows environment, occasionally it will crash and we need to detect when that happens (the application does not close or send any windows info that can be detected, instead the app shows a ANSI colored error message within the app window and waits for user's input), the only way we can automatically detect an error is to find a red pixel within a specified area of the window. How would we be do that? It wouldn't be a problem If the app started up at the same place on the screen every time, but that is not the case. All suggestion are welcomed and appreciated.
    Last edited by SavedByGrace; Aug 12th, 2009 at 01:11 AM. Reason: RESOLVED

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Check pixel at x,y of an app's window

    Quote Originally Posted by SavedByGrace View Post
    the only way we can automatically detect an error is to find a red pixel within a specified area of the window. How would we be do that? It wouldn't be a problem If the app started up at the same place on the screen every time, but that is not the case. All suggestion are welcomed and appreciated.
    Never really played with a DOS window, so just some ideas that may or may not work.

    You can use GetPixel API to find what color is on the screen at a certain x,y position.

    You could move the window so it's always in the same position using the MoveWindow API, use FindWindw API to get the windows handle and pass that to MoveWindow with the position you want.

    Or if you know the pixel you are looking for is at say (100,100) when DOS window is at say the very top-left of the screen (0,0) , then use GetWindowRect to get the current top & left position of the window and add that to your known pixle position x,y to see if its red or not.

  3. #3
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Check pixel at x,y of an app's window

    You can use the GetPixel() API function...

    1. Get hWnd (window handle) of application by its Title using FindWindow or FindWindowEx
    2. Get the Window's hDC (device context handle) using the GetDC API function
    3. Use GetPixel on that hDC to get the color value

  4. #4

    Thread Starter
    Addicted Member SavedByGrace's Avatar
    Join Date
    May 2006
    Posts
    130

    Re: Check pixel at x,y of an app's window

    Edgemeal - The app will be starting in our absence at predefined times - so we cannot guarantee a location for the app
    DigiRev - Those seem like really good suggestions and I have seen those references for api for this type of issue, unfortunately, I am not very knowledgeable with using api and don't know how to put those to work for this problem.

  5. #5
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Check pixel at x,y of an app's window

    Not sure this will help but heres a fast way to find a color on the screen, the example also moves the mouse cursor to the position which you can easily remove. See the project in post #25 here, and the last few comments after that.

    EDIT Oh I see you are the one who asked that Q in that link, in that case never mind, you've seen that before!
    Last edited by Edgemeal; Aug 11th, 2009 at 11:22 PM.

  6. #6

    Thread Starter
    Addicted Member SavedByGrace's Avatar
    Join Date
    May 2006
    Posts
    130

    Re: Check pixel at x,y of an app's window

    Thanks Edgemeal

  7. #7

    Thread Starter
    Addicted Member SavedByGrace's Avatar
    Join Date
    May 2006
    Posts
    130

    Re: Check pixel at x,y of an app's window

    Thank you to those who gave info and advise to my post. I was able to resolve this by heavily modifying http://www.vbforums.com/showthread.p...ndWindow+GetDC Post #11 to suit my needs.

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