How to get cursor position in status bar?
-
Hello...This question may sound silly to some of you but I've been stuck on it for few days and can't find any answer... So I need to have the mouse position x and y displayed in the status bar. So far I add new string to the table, in the indicators array, afx_msg void OnUpdateCurPos(CCmdUI *pCmdUI) in the message map and ON_UPDATE_COMMAND_UI(ID_INDICATOR_CURSOR,OnUpdateCurPos) When I run it's there but can't find the right way to update the cords. I think it must work with ON_MOUSEMOVE func...I've tried several codes in ON_MOUSEMOVE and OnUpdateCurPos but it doesn't work at all... Working with SDI.
-
Hello...This question may sound silly to some of you but I've been stuck on it for few days and can't find any answer... So I need to have the mouse position x and y displayed in the status bar. So far I add new string to the table, in the indicators array, afx_msg void OnUpdateCurPos(CCmdUI *pCmdUI) in the message map and ON_UPDATE_COMMAND_UI(ID_INDICATOR_CURSOR,OnUpdateCurPos) When I run it's there but can't find the right way to update the cords. I think it must work with ON_MOUSEMOVE func...I've tried several codes in ON_MOUSEMOVE and OnUpdateCurPos but it doesn't work at all... Working with SDI.
What does your
OnUpdateCurPos()
andOnMouseMove()
functions look like? Have you calledSetCapture()
?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
What does your
OnUpdateCurPos()
andOnMouseMove()
functions look like? Have you calledSetCapture()
?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
Well that is the problem :P I've added SetCapture() when you press LButton, but I'm not rly sure if I need it?
void CMainFrame::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
SetCapture();
CFrameWnd::OnLButtonDown(nFlags, point);
}void CMainFrame::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(GetCapture()==this){
posX=point.x;
posY=point.y;
}
CFrameWnd::OnMouseMove(nFlags, point);
}void CMainFrame::OnUpdateCursor(CCmdUI *pCmdUI){
CString pos;
pos.Format(ID_INDICATOR_CURSOR,posX,posY);
m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_CURSOR),pos);
}Well atleast now the sting is updated with 0's. Its defined as " x: %d ,y: %d ". So the OnUpdateCursor() is working but not with the right values...
-
Well that is the problem :P I've added SetCapture() when you press LButton, but I'm not rly sure if I need it?
void CMainFrame::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
SetCapture();
CFrameWnd::OnLButtonDown(nFlags, point);
}void CMainFrame::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(GetCapture()==this){
posX=point.x;
posY=point.y;
}
CFrameWnd::OnMouseMove(nFlags, point);
}void CMainFrame::OnUpdateCursor(CCmdUI *pCmdUI){
CString pos;
pos.Format(ID_INDICATOR_CURSOR,posX,posY);
m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_CURSOR),pos);
}Well atleast now the sting is updated with 0's. Its defined as " x: %d ,y: %d ". So the OnUpdateCursor() is working but not with the right values...
-
What happens when you change your Format statement to
pos.Format(" x: %d ,y: %d " ,posX,posY);
Nothing. Stays the same:
"x: 0 , y: 0"
-
Nothing. Stays the same:
"x: 0 , y: 0"
-
Yes... Seems like OnMouseMove doesn't update posX and posY. If I do :
void CMainFrame::OnUpdateCursor(CCmdUI *pCmdUI){
CString pos;
posX=100;
posY=200;
pos.Format(L" x: %d ,y: %d ",posX,poxY);
m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_CURSOR),pos);
}It does put
"x: 100,y: 200"
in the status bar...
-
Yes... Seems like OnMouseMove doesn't update posX and posY. If I do :
void CMainFrame::OnUpdateCursor(CCmdUI *pCmdUI){
CString pos;
posX=100;
posY=200;
pos.Format(L" x: %d ,y: %d ",posX,poxY);
m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_CURSOR),pos);
}It does put
"x: 100,y: 200"
in the status bar...
-
Well that is the problem :P I've added SetCapture() when you press LButton, but I'm not rly sure if I need it?
void CMainFrame::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
SetCapture();
CFrameWnd::OnLButtonDown(nFlags, point);
}void CMainFrame::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(GetCapture()==this){
posX=point.x;
posY=point.y;
}
CFrameWnd::OnMouseMove(nFlags, point);
}void CMainFrame::OnUpdateCursor(CCmdUI *pCmdUI){
CString pos;
pos.Format(ID_INDICATOR_CURSOR,posX,posY);
m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_CURSOR),pos);
}Well atleast now the sting is updated with 0's. Its defined as " x: %d ,y: %d ". So the OnUpdateCursor() is working but not with the right values...
In
OnMouseMove()
, what is the value ofpoint.x
andpoint.y
?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
In
OnMouseMove()
, what is the value ofpoint.x
andpoint.y
?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
I can't rly get the debuger to stop there ... It's kinda like skipping it all? Any other way of checking ?
-
Hello...This question may sound silly to some of you but I've been stuck on it for few days and can't find any answer... So I need to have the mouse position x and y displayed in the status bar. So far I add new string to the table, in the indicators array, afx_msg void OnUpdateCurPos(CCmdUI *pCmdUI) in the message map and ON_UPDATE_COMMAND_UI(ID_INDICATOR_CURSOR,OnUpdateCurPos) When I run it's there but can't find the right way to update the cords. I think it must work with ON_MOUSEMOVE func...I've tried several codes in ON_MOUSEMOVE and OnUpdateCurPos but it doesn't work at all... Working with SDI.
Try this!
void CDlgStatusBarDlg::OnMouseMove(UINT nFlags, CPoint point)
{
CString s;
s.Format("X=%d Y=%d",point.x,point.y);
m_bar.SetPaneText(0,s);
CDialog::OnMouseMove(nFlags, point);
}Source: [Adding a status bar to an MFC dialog[^]]
-
I can't rly get the debuger to stop there ... It's kinda like skipping it all? Any other way of checking ?
Vladislav Gospodinov wrote:
Any other way of checking ?
TRACE()
."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Vladislav Gospodinov wrote:
Any other way of checking ?
TRACE()
."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
So it doesn't TRACE() anything at all when called in
CMainFrame::OnMouseMove
so it's like it doesn't get the mouse moving at all in MainFrame class... it does trace correct values if I call it in the View class
CpositionView::OnMouseMove
however I can't find a way to send them from View to MainFrame, although I have included ***View.h and taka them like
CpositionView::positionX
I get a lot of errors :P