LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Use Toggle Button to Simulate Holding Ctrl

Solved!
Go to solution

Thanks very much for that, will give it a try shortly, certainly looks like it should work. Also, apologies for the delay in response, this was something I was trying to do at work towards the end of the week and only just back in the office to check this thread!

0 Kudos
Message 11 of 16
(1,282 Views)

No luck at the moment, getting a few errors back. Can I ask what the HWND hwnd bit is? It's also not liking VK_CONTROL or WM_LBUTTONDOWN, just coming back as undeclared identifiers. Also getting about 4 missing prototype errors.

0 Kudos
Message 12 of 16
(1,278 Views)

Cottonb,

 

My apologies, I forgot to mention that you need to #include <Windows.h>. Make sure this is at the top of the list of includes to avoid conflicts.

National Instruments
0 Kudos
Message 13 of 16
(1,271 Views)

Ah yes, sorry thanks, I appreciate the help. That gets rid of the errors anyway however it's still not playing ball at the mo! No errors or anything, just not working as intended.

 

This is what I have, with all the variable declared as you have in the sample code:

 

int CVICALLBACK Zoom (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{   
	HWND hwnd;
	int zoomonoff = 0;
	switch (event)
	{
		case EVENT_LEFT_CLICK:
			GetKeyboardState(oldKeyState);
			GetCtrlVal(panelHandle, PANEL_ZOOM, &zoomonoff);
			
			if (zoomonoff)
			{
				memcpy(newKeyState, oldKeyState, 1);
				
				newKeyState[VK_CONTROL] = 128;
				SetKeyboardState(newKeyState);
				
				SetActiveCtrl(panelHandle, PANEL_OUTPUT);
				GetPanelAttribute(panelHandle, ATTR_SYSTEM_WINDOW_HANDLE, (intptr_t*)&hwnd);
				isFakeDouble = 1;
				SendMessage(hwnd, WM_LBUTTONDOWN, 0, 0);
				isFakeDouble = 0;
			}
			
			break;
		case EVENT_LEFT_DOUBLE_CLICK:
			
			if (isFakeDouble)
				SetKeyboardState(oldKeyState);
			
			break;
	}
	return 0;
}

 Zoom is the callback function for the toggle button.

0 Kudos
Message 14 of 16
(1,265 Views)

Switch Zoom to be the callback function of the graph and I think this should work. We don't need to have a callback function for the toggle button because we can use getCtrlVal to get it's current state. We want this code in the callback for the graph so that whenever the user clicks on the graph, we can handle that in the EVENT_LEFT_CLICK.

National Instruments
0 Kudos
Message 15 of 16
(1,262 Views)

Eacellent, thanks very much! Works like a charm. Thank you for all of the help, it's greatly appreciated, you can tell I'm new to this!

0 Kudos
Message 16 of 16
(1,259 Views)