1

I have MFC project, which has two chart on dialog window.

I am trying to synchronize cursor movement between those two charts. So when I move cursor over one chart, second chart tracks this mouse movement and have its cursor follow same path. I use custom cursor. Not the system arrow. Same about axis. Once I update axis for one of them, second should be updated in the same way. So far no luck.

So obviously onMouseMove should be somehow utilize here. Coordinate and axises settings from one chart should transferred to the second one once they are changed.

Was not able to find any good example on similar case.

To add chart to Dialog window I updated CMyDlg rc with "custom control", set the Class field to "CMyChart", ID to "IDC_CHART_TOP". Did similar for bottom chart.

please find some simplified version of my code.

//// CMyDlg.cpp ////
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_CHART_TOP, m_ChartTop);
    DDX_Control(pDX, IDC_CHART_BOTTOM, m_ChartBottom);
}
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
END_MESSAGE_MAP()
void CMyDlg::plotDataTop()
{
    // init and plot m_ChartTop
}
void CMyDlg::plotDataBottom()
{
    // init and plot m_ChartBottom
}
BOOL CMyDlg::OnInitDialog()
{
    CDialog::OnInitDialog();
    plotDataTop();
    plotDataBottom();
    return TRUE;
}

//// MyDlg.h ////
class CMyDlg : public CDialog
{
public:
    CMyDlg(CWnd* pParent = nullptr);
    virtual ~CMyDlg();

#ifdef AFX_DESIGN_TIME
    enum { IDD = DLG_MYDLG };
#endif

protected:
    virtual void DoDataExchange(CDataExchange* pDX);
    virtual BOOL OnInitDialog();
    DECLARE_MESSAGE_MAP()
    CMyChart m_ChartTop;
    CMyChart m_ChartBottom;
public:
    // plot data
    void plotDataTop();
    void plotDataBottom();
};
id347627
  • 46
  • 5
  • Sorry, but it's not quite clear what exactly you want to do (update axes simultaneously?), ie what kind of "updates" you want. It's not clear even what you are asking for, eg how to make a custom cursor, how to use the `OnMouseMove()` event etc. You haven't posted what you do in your `OnMouseMove()` implementation either. And finally, I don't think you can find code sample on the i-net about that simultaneous charts updates, it's sth very special. Better post your implementation so far (with comments pls) and let the forum members review it and make suggestion. – Constantine Georgiou Oct 13 '21 at 23:58
  • Thank you for your feedback. I updated description. I want two cursors synchronize their behavior for two charts. when I move cursor left over one chart, same movement should be done for second chart' cursor at the same time. once axis where updated for one char, same updates should be applied for second one. – id347627 Oct 14 '21 at 00:59
  • I believe same technic would be used if we are filling tow textfields simultaneously with same text. we type in one, and same text appears in the second textfield. – id347627 Oct 14 '21 at 01:26
  • You can only have one system cursor at a time. You are using some custom chart, maybe it has a "cursor like" feature. See if you can simplify your question such that it relates to standard MFC features. – Barmak Shemirani Oct 14 '21 at 01:57
  • Thanks you, but I guess my code is working now just sened wm_mouseMove to parent, from there I can update second chart with new cursor position, and axises. Im not using system cursore. there is custom cursore made out of two lines – id347627 Oct 14 '21 at 03:56
  • `WM_MOUSEMOVE` is a **posted** message. You aren't supposed to send (or even post) it yourself. The system does that. You should invest some more time into understanding the *problem* you want to solve (communicating data) rather than trying to infer a solution from incomplete information. – IInspectable Oct 14 '21 at 08:29
  • Thank you for reply, can you suggest some good resources to get more familiar with similar cases – id347627 Oct 14 '21 at 19:10
  • Collateral question: what kind of char you use in MFC ? I search for some time to choose a suitable MFC chart, that's why I ask this. Of course, if you can say here. – Flaviu_ Oct 15 '21 at 07:27

0 Answers0