• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

How do I read data under the cursor in Windows?


When you have no access to an application written in Windows, there may still be a need to "read" information under the cursor.  Of course, the data is in pixel form and would need to be converted to character format when the cursor is not over a picture.  

I have noticed that there are a few applications that can "magnify" the pixels under the cursor within their application (such as SnagIt! from TechSmith.  I recall several other programs that create a "magnifying glass" as a cursor to "Zoom in" while using a floating cursor.  

My goal is to create an application that remains external to any specific Windows application, but has the capability of "grabbing" a block of pixels when the right mouse button is used.  (if the application uses the right mouse button, I may need to find a way to activate the "grab" function some other way).

Anyone a detailed Windows person that can help me create the "cursor capture" function?
0
DSIGRIS
Asked:
DSIGRIS
  • 3
  • 2
1 Solution
 
rcarlanCommented:
First of all, you'll have to install a mouse hook to get mouse messages while the mouse cursor is over a window belonging to another process.

Secondly, to copy a portion of the screen, you need to get the screen DC - i.e. GetDC(NULL), and BitBlt from it to a memory DC compatible with the screen DC.

Radu
0
 
rushtoshankarCommented:
Try these piece of code.

void CClrFndrDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
    // say m_static is a label.
    // if the user clicks the that label we ready to read the pixel under the mouse cursor.
    CRect rect;
    m_static.GetWindowRect(&rect);
    ClientToScreen(&point);
    if (IsInside(&rect, point)) // check whether mouse is clicked inside the label
    {
        SetCapture();
        m_bTrackingMouse = true;
    }
    CDialog::OnLButtonDown(nFlags, point);
}

void CClrFndrDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
    if (m_bTrackingMouse)
    {
        ReleaseCapture();
        m_bTracking = false;
    }
    CDialog::OnLButtonUp(nFlags, point);
}

void CClrFndrDlg::OnMouseMove(UINT nFlags, CPoint point)
{
    CString szString;
    POINT pt;

    if (m_bTrackingMouse)
    {
            GetCursorPos(&pt);
            // display the position of the mouse
            szString.Format ("%d, %d", pt.x, pt.y);
            m_editCursorPosition.SetWindowText((LPCTSTR)szString);

            CDC *pDesktopHandle = CDC::FromHandle ( ::GetDCEx(NULL, NULL, 0));
            m_colCurrent = pDesktopHandle->GetPixel(pt);

            BYTE byRed   = GetRValue(m_colCurrent);
            BYTE byGreen = GetGValue(m_colCurrent);
            BYTE byBlue  = GetBValue(m_colCurrent);

            //  display the pixel color under the mouse
            szString.Format("%02x, %02x, %02x", byRed, byGreen, byBlue);
            m_editRGBValue.SetWindowText((LPCTSTR)szString);

            //  release all dc handles
            ReleaseDC(pDesktopHandle);
      }
    CDialog::OnMouseMove(nFlags, point);
}

Hope this will help.
0
 
DSIGRISAuthor Commented:
This looks great.  I have no idea how the code could be compiled and executed as a program.  Is this code meant to be placed inside of a Visual Basic program, or is it meant to be used in conjunction with a lower level language such as Java?

Since I am a beginner in the area of programming at lower level codes (I have only done a few programs in VB), I presume I should begin studying an appropriate language for this kind of processes.  Can you recommend documentation or study course that I might take to work on programs at this level?

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
rcarlanCommented:
code sample is C++ & MFC
0
 
DSIGRISAuthor Commented:
I know what C++ looks like, but I do know what MFC does.  Can you elaborate?
0
 
rcarlanCommented:
Microsoft Foundation Classes - comes with VC++
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now