Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Context Menu on CniGraph

Some month ago, the subsequent conversation was postetd in this forum. Now I'm looking for an answare for this question, but couldn't find any.
Can someone help me?

Thank Poirez






"Context Menu on CniGraph 2D"

"Hello,
I use MeasurementStudio 6 ( vers 7 0 0 343) with Visual C++ 6
I will wish to make a contextual menu on a graph 2d to change the TrackEventmode.
In Ni Example �Simple graph� I add the function �OnMouseDownCwgraphmouse� if Button is ButtonRight I call TrackPopmenu function with two items zoom, cursor.
cursor set TrackDragCursor, zoom set TrackZoomRectX.

After this call cursordrag and zoom never work, pan is OK.
If I comment the line pmnu->trackpopmenu all is working.
Where are my mistakes?
Thank
in advance for your help.."

-posted by ras on 6/29/2004




--------------------------------------------------------------------------------
Sissa on 7/5/2004 answered:
"Hi ras
Can you provide me a sample code which reproduce your
problem. I'll try to see what's going wrong with it.

Regards


Salissou ISSA
Applications Engineer
National Instrumnents France"

This answer has not yet been rated.
Rate this answer:


ras on 7/6/2004 commented:
"hello,

Thanks for your help.


On attached file SimpleGraph.zip you can find the original Ni sampleGraph and my modifications, they are signed "// jlr".


Regards.


PS: Ni France ? are you in France ? my english is still a beta release french is better for me."


SimplGraph modified (Zip Compressed Data, 260K)
0 Kudos
Message 1 of 16
(5,242 Views)
Poirez,

So are you having the same problem? Is your code the same as attached? Let me know and I will go from there.

Allan S.
National Instruments
0 Kudos
Message 2 of 16
(5,241 Views)
Thanks Allen
Yes, I have almost the same Problem.
The code I use is the following.
After calling the context menu, the zoomfunction and the function to move the cursor don't work anymore.



void CPiezoGraphView::OnMouseDownCwgraph(short Button, short Shift, long x, long y)
{
if (Button == 2 && !m_bKeyDown)
{
CMenu menu, *pContextMenu;

menu.LoadMenu(IDR_PIEZOGTYPE);
pContextMenu = menu.GetSubMenu(2);

RECT graph_rect;
m_graph.GetWindowRect(&graph_rect);

pContextMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, x + graph_rect.left, y + graph_rect.top, AfxGetMainWnd());
pContextMenu->DestroyMenu();
}
}
0 Kudos
Message 3 of 16
(5,241 Views)
Could you attach a project that displayed this actual behavior? That would help me out immensely in diagnosing the problem. Hope your having a great day!

Allan S.
National Instruments
0 Kudos
Message 4 of 16
(5,241 Views)
this weekend, I saw, that the contextmenu in windows is created on the mouseup-event. I tried it in my application and it works.

the only thing i changed is not to call the contextmenu on the mousedown-event. Now i call it on the mouseup-event.

Thanks for helping me Allan.


Greets Poirez
0 Kudos
Message 5 of 16
(5,241 Views)
I am sorry I didn't do more. Glad you are making progress. Have a great day!

Allan S.
National Instruments
0 Kudos
Message 6 of 16
(5,241 Views)
Hi

I do encountered the same problem on Context menu, if anyone has the solution to Zoom, Pan and Cursor placement pls do let me know. And one more thing is how do i reset to actual display after zooming or panning. Can anyone suggest on this.

here is the code how i handle context menu..

/**********************************************/
void CTest_DataView::onMouseDownOnGraph(short Button, short Shift, long x, long y)
{

int tempX = x + 120;
int tempY = y + 110;


CString str = "";

if(Button == 2)
{
CMenu sGrphMenu;
sGrphMenu.CreatePopupMenu();

sGrphMenu.AppendMenu(MF_STRING | MF_ENABLED, IDM_CURSOR,"Cursor");
sGrphMenu.AppendMenu(MF_STRING | MF_ENABLED, IDM_ZOOM, "Zoom");
sGrphMenu.AppendMenu(MF_STRING | MF_ENABLED, IDM_PAN, "Pan");

sGrphMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_NONOTIFY, tempX, tempY, this );
}

}

LRESULT CTest_DataView::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if(message == WM_COMMAND)
OnRButtonMenuCmd(wParam);

return CFormView::DefWindowProc(message, wParam, lParam);
}

void CTest_DataView::OnRButtonMenuCmd(UINT CMD_ID)
{
switch(CMD_ID)
{
case IDM_CURSOR:
m_Graph.SetTrackMode(CNiGraph::TrackDragCursor);
break;
case IDM_ZOOM:
m_Graph.SetTrackMode(CNiGraph::TrackZoomRectXY);
break;
case IDM_PAN:
m_Graph.SetTrackMode(CNiGraph::TrackPanPlotAreaXY);
break;
}
}
/**********************************************/

Thanks & regards
venky
0 Kudos
Message 7 of 16
(5,022 Views)
Hello Venky,

There is a graph property called, "CNiGraph::TrackMode" that "Determines how the mouse interacts with the graph. Use this property to enable zooming and panning for the graph." You may have to have a mechanism for switching between modes (ie: switching between panning and zooming modes). To undo, there are special modes such as "CNiGraph::TrackZoomRectXYWithUndo". Holding down the shift key and clicking will undo the operation; however, I am currently having trouble getting the undo modes working in VS 6.0. I hope this helps. If I can get it working, I will be sure to send you my code. Take care!


Regards,

Aaron B.
National Instruments
0 Kudos
Message 8 of 16
(4,998 Views)
Hello Venky,

The Undo modes were only made available in Measurement Studio 7.0 and 7.1; however, if you have Measurement Studio 6.0, there is a free patch that will allow you to upgrade to the current version of all of the Visual Studio 6.0 Measurement Studio Controls and libraries. It can be found on our website at the following URL: "http://digital.ni.com/softlib.nsf/websearch/2AAC97491D073A6C86256EEF005374CE?opendocument&node=132060_US".

The file, "Mstudio71NewFeaturesforVS60.html", has a section labeled, "Using the New Features in Visual C++ 6.0". There it tells you to use direct numbers instead of the constants that you would use in the VS .NET environment.

Here is a snippet of my code:

void CZoomingDlg::OnButton1()
{
// type cast the numeric value 10 to a CNiGraph::GraphTrackModes enum type
m_graph.TrackMode = (CNiGraph::GraphTrackModes)10;
}

void CZoomingDlg::OnButton2()
{
m_graph.TrackMode = CNiGraph::TrackPanPlotAreaXY;
}

I have a graph on my dialog assigned to the variable, m_graph. There are two buttons as well. When I press the first button, it allows me to zoom on my graph. To undo the zoom changes, I just hold shift and left-click. When I press on the other button, it allows me to pan.

I hope that this helps. Take care!


Regards,

Aaron B.
National Instruments
0 Kudos
Message 9 of 16
(4,989 Views)
Hi Aaron,

Thanks for the reply, I did handled the Undo for Zoom and Panning through some hardcoded way. May be this is not the correct procedure but i'm able to handle it, here it is how i had done...

After Zooming on click of the Reset Button (Rbutton Click of Menu Button). Iam resetting the XAxis and YAxis, Min and Max to normal range. Then setting the YAxis to AutoScale. I guess this way is not that good to handle things.

m_Graph.Axes.Item(1).Minimum = 0;
m_Graph.Axes.Item(1).Maximum = 2047;

CNiAxis yAxis = m_Graph.Axes.Item(2);
yAxis.SetMinMax(yMinVal, yMaxVal);
yAxis.AutoScale = TRUE

Setting axis to normal range can be done in anyof the ways as shown above.

Do suggest whether my approach is correct or not. I shall try downloading the patch and check as per your suggestion.

Thanks & Regards
Venky
0 Kudos
Message 10 of 16
(4,984 Views)