Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Using cursors with the CWGraph PlotMouseMove event

I have imported CWGraph into Borland C++Builder 6, and have been using the graph without too much trouble. However, I'm running into a problem with using cursors on the graph while I have a PlotMouseMove event defined. The cursors no longer respond to mouse events. That is, I can't drag the cursors at all. I can move them programatically, but it's going to be difficult to replicate the cursors' functions if I have to do it manually. In fact, nearly impossible, since i have no idea how to do it.

Is there a way to retain the default functionality of the cursors while specifying other actions to be performed in the PlotMouseMove event?
0 Kudos
Message 1 of 5
(4,465 Views)
Hello JRenaut,

If you set the CWGraph's TrackMode to cwGTrackPlotAreaEvents, you'll have to replicate the cursor functionality yourself. It's not too difficult - you can replicate the cursor's SnapMode = cwCSnapFloating functionality with the following code:

Private Sub CWGraph1_PlotAreaMouseMove(Button As Integer, Shift As Integer, XPos As Variant, YPos As Variant)
If (Button And vbLeftButton) Then
CWGraph1.Cursors(1).SetPosition XPos, YPos
End If
End Sub

Private Sub CWGraph1_PlotAreaMouseDown(Button As Integer, Shift As Integer, XPos As Variant, YPos As Variant)
CWGraph1.Cursors(1).SetPosition XPos, YPos
End Sub


David Mc.
NI Applications Engineer
0 Kudos
Message 2 of 5
(4,465 Views)
Could I also do this for multiple cursors? Ideally, I'd like the cursors to function as they do now. That is, if I click and drag a cursor, it moves until I let up the mouse button.

Also, I assume this should work in more or less the same way using C++?

Thanks very much

Jon Renaut
0 Kudos
Message 3 of 5
(4,465 Views)
Hello Jon,

Yes, you could use the CursorMouseMove event to accomplish the same thing with multiple cursors:

Private Sub CWGraph1_CursorMouseMove(Button As Integer, Shift As Integer, XPos As Variant, YPos As Variant, CursorIndex As Integer, CursorPart As Long)
If ((Button And vbLeftButton) And (CursorPart = cwCursorCrosshair)) Then
CWGraph1.Cursors(CursorIndex + 1).SetPosition XPos, YPos
End If
End Sub

Note that now we're checking that the left mouse button is pressed and that the user has clicked on the crosshair part of the cursor before moving the cursor around. You'll have to have CWGraph1.TrackMode = cwGTrackAllEvents in order to get this to work. Also, the CursorIndex is zero-based, and the CWGraph's cursor colle
ction is one-based, which is why the CursorIndex+1 statement is in the code I listed above.

My code here is Visual Basic, but I hope this works the same for you. However I don't have access to a copy of Borland C++ Builder to try this out.

David Mc.
NI Applications Engineer
0 Kudos
Message 4 of 5
(4,465 Views)
Okay, I just about have it all working. The VB code is close enough - this is the C++:

void __fastcall TStripChart::MoveOnCursor(TObject *Sender, short *Button,
short *Shift, Variant *XPos, Variant *YPos, short *CursorIndex,
long *CursorPart)
{
Variant idx;
idx = *CursorIndex+1;
if (*Button == 1)
{
if (*CursorPart == cwCursorCrosshair)
{
Graph->Cursors->Item(idx)->SetPosition(*XPos, *YPos);
}
}
}

Anyway, thanks very much for your help.
0 Kudos
Message 5 of 5
(4,465 Views)