DSIGRIS
asked on
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?
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(&re ct);
ClientToScreen(&point);
if (IsInside(&rect, point)) // check whether mouse is clicked inside the label
{
SetCapture();
m_bTrackingMouse = true;
}
CDialog::OnLButtonDown(nFl ags, point);
}
void CClrFndrDlg::OnLButtonUp(U INT nFlags, CPoint point)
{
if (m_bTrackingMouse)
{
ReleaseCapture();
m_bTracking = false;
}
CDialog::OnLButtonUp(nFlag s, point);
}
void CClrFndrDlg::OnMouseMove(U INT 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.SetWi ndowText(( LPCTSTR)sz String);
CDC *pDesktopHandle = CDC::FromHandle ( ::GetDCEx(NULL, NULL, 0));
m_colCurrent = pDesktopHandle->GetPixel(p t);
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.SetWindowTe xt((LPCTST R)szString );
// release all dc handles
ReleaseDC(pDesktopHandle);
}
CDialog::OnMouseMove(nFlag s, point);
}
Hope this will help.
void CClrFndrDlg::OnLButtonDown
{
// 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(&re
ClientToScreen(&point);
if (IsInside(&rect, point)) // check whether mouse is clicked inside the label
{
SetCapture();
m_bTrackingMouse = true;
}
CDialog::OnLButtonDown(nFl
}
void CClrFndrDlg::OnLButtonUp(U
{
if (m_bTrackingMouse)
{
ReleaseCapture();
m_bTracking = false;
}
CDialog::OnLButtonUp(nFlag
}
void CClrFndrDlg::OnMouseMove(U
{
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.SetWi
CDC *pDesktopHandle = CDC::FromHandle ( ::GetDCEx(NULL, NULL, 0));
m_colCurrent = pDesktopHandle->GetPixel(p
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.SetWindowTe
// release all dc handles
ReleaseDC(pDesktopHandle);
}
CDialog::OnMouseMove(nFlag
}
Hope this will help.
ASKER
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?
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?
code sample is C++ & MFC
ASKER
I know what C++ looks like, but I do know what MFC does. Can you elaborate?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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