10-27-2010 02:44 AM
Hello,
I am using CVI 8.5.1. If I create a graph control with the NewCtrl function, the events EVENT_GOT_FOCUS and EVENT_LOST_FOCUS will not be called. I tried a workaround with the EVENT_LEFT_CLICK event but I need the EVENT_LOST_FOCUS too. How can solve this problem?
Thanks in advance
Inomed
10-27-2010 03:50 AM
To have the control to process events it must have a callback installed: have you called InstallCtrlCallback with a proper callback after creating the graph?
10-27-2010 04:08 AM
Hello,
yes I called InstallCtrlCallback with a proper callback. It only will work if I create the control in uir File, but not with the NewCtrl function.
Thanks in advance
Inomed
10-27-2010 04:44 AM
That's odd: I just tried doing that and all worked well. For your infromation, these are the instructions I used:
ctrlHandle = NewCtrl (panel, CTRL_GRAPH_LS, "Diagram", 10, 10);
GetCtrlAttribute (panel, ctrlHandle, ATTR_CTRL_MODE, &mode); // Just to be sure the new control is in hot mode
error = InstallCtrlCallback (panel, ctrlHandle, myCallback, NULL);
There may be some issues with handling control events: is the graph on top or there are controls that ovelap on it?
Are you sure you can operate on the graph? You could add those lines and check if you can edit Yaxis labels on the new graph:
SetAxisScalingMode (panel, ctrlHandle, VAL_LEFT_YAXIS, VAL_MANUAL, 0.0, 100.0);
SetCtrlAttribute (panel, ctrlHandle, ATTR_ENABLE_EDITABLE_AXES, 1);
Additionally you may add a breakpoint at the very beginning of the control callback and check if at least the callback is executed when the mouse is on the control (responding to EVENT_MOUSE_POINTER_MOVE event).
10-27-2010 05:00 AM
Hello,
The graph is in hot mode, is placed on top and the waveforms are plotted.
I only get some events. For exmaple the EVENT_MOUSE_POINTER_MOVE, EVENT_LEFT_CLICK or EVENT_LEFT_CLICK_UP. I get the EVENT_GOT_FOCUS only at the first click in my graph control, but the EVENT_LOST_FOCUS is never called.
Thanks for help
Inomed1
10-27-2010 07:25 AM
Hi Inomed1,
this is definitely a strange behavior for controls created at runtime!
Can you attach a simple example project that shows it consistently? This may help somebody here to understand what's happening.
10-27-2010 07:46 AM
Hi Roberto,
thank for your help. I have no tab order set, may this cause that problem?
Im using Visual Studio with C++, but I have the same behaviour in C functions. Here is my example code, I have a panel with only one graph control and no other controls on it.
Thanks in advance
Inomed1
//Constructor of my Class which creates a graph control
CviGraph::CviGraph (CviPanel* panel, int top, int left, string label)
: Graph(panel)
{
mId = NewCtrl(mPanel->GetId(), CTRL_GRAPH, label.c_str(), top, left);
mColor = ((CviPanel*)mPanel)->GetSkin()->windowBackgroundColor_unselected;
SetCtrlAttribute (mPanel->GetId(), mId, ATTR_CTRL_MODE, VAL_HOT);
InstallCtrlCallback(mPanel->GetId(), mId, &HandleEvent, this);
SetCtrlAttribute(mPanel->GetId(), mId, ATTR_EDGE_STYLE, VAL_FLAT_EDGE);
SetCtrlAttribute(mPanel->GetId(), mId, ATTR_GRAPH_BGCOLOR, mColor);
}
//my static class method who Handles the events
int CviGraph::HandleEvent(int panel, int ctrl, int event, void *callbackData, int eventData1, int eventData2)
{
if (NULL == callbackData)
return 0;
CviGraph* cviGraph = (CviGraph*)callbackData;
if (NULL == cviGraph)
return 0;
IEventHandler* eventHandler = cviGraph->GetEventHandler();
if (NULL == eventHandler)
return 0;
switch (event)
{
case EVENT_LEFT_CLICK_UP:
//this event is called
eventHandler->HandleEvent(cviGraph, EVENT_LEFT_CLICK_UP, eventData1, eventData2);
break;
case EVENT_GOT_FOCUS:
//this event is only one time called
eventHandler->HandleEvent(cviGraph, EVENT_GOT_FOCUS, eventData1, eventData2);
break;
case EVENT_LOST_FOCUS:
//this event is never called
eventHandler->HandleEvent(cviGraph, EVENT_LOST_FOCUS, eventData1, eventData2);
break;
}
return 0;
}
10-27-2010 05:29 PM
Unfortunately I have no experience on interaction between Visuali Studio and CVi.
Let's see if anybody else can suggest something on this matter.