LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

related to mouse-click

Hi ,
In a application I have many buttons, a graph control etc . Now when I am clicking Mouse then how can I get to know On which button I have clicked or on graph control I have clicked ? .Plz reply me soon .
 
Regards
subrata
0 Kudos
Message 1 of 3
(3,321 Views)

Hello Subrata,

all this information you can find in the callback function parameters.

  • Check the panel and control parameters to see on which control you have clicked.
  • Check the event parameter to see on which mouse button you have clicked. When you generate the code for your callback function automatically ,using "Generate Control Callback" in the user interface editor, you will see that the only even in the case-switch is EVENT_COMMIT. However, when you look in the CVI Help, you will see that a lot of events can be generated, including EVENT_LEFT_CLICK and EVENT_RIGHT_CLICK.

Example of a callback funtion:

int CVICALLBACK CallbackFunction (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2) {
 char message_str[250];
 char control_str[100];
 
 GetCtrlAttribute (panel, control, ATTR_CONSTANT_NAME, control_str);
 
 switch (event) {
  case EVENT_LEFT_CLICK:
   Fmt (message_str, "Left Clicked the %s control", control_str);
   MessagePopup ("Action", message_str);
   break;
  case EVENT_RIGHT_CLICK:
   Fmt (message_str, "Right Clicked the %s control", control_str);
   MessagePopup ("Action", message_str);
   break;
 }
 return 0;
}

Try out the example in the attachment

Message Edited by Wim S on 03-13-2007 04:00 PM

0 Kudos
Message 2 of 3
(3,318 Views)
First of all, when you click on a control (button, graph, string...) with an associated callback function, it's this function that recevies mouse and other events, so if every control on your panel has its own callback function you have no problems in discriminating which control was clicked on.
 
Only in case more controls share the same callback function you can rely on "control" parameter in the callback function to discirminate which control is generating the event. You may simply use a switch statement with the adequate number of cases:
 
switch (control) {
 case PANEL_COMMANDBUTTON1:
  // Place your code here
  break;
 case PANEL_COMMANDBUTTON2:
  // Place your code here
  break;
 // Add other cases as necessary
}
 
In case the same callback is shared among control on more than one panel, then you must first discriminate which panel is the active one, possibly using the panel title or the associated constant name. Only after this step you can insert the above switch statement.
 
On the other hand, if your problem is to discriminate individual events so that you can operate differently on each of them you can rely on Wim's suggestion and his good example.
 
There are other tricks that can be useful in particular situations, so if you may add some detail more on your actual problem we may suggest some hint more.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 3
(3,310 Views)