03-03-2011 04:18 PM
Is it possible to access the device handles of controls on other open windows with Lab Windows CVI?
What I am interested in doing is clicking buttons, reading from and writing to edit boxes, selecting pull down menu items that are located in another application running in Windows, and reading the contents of the clipboard from a lab Windows application.
Can this be done easily from Lab Windows?
03-04-2011 04:37 PM
Robo Jeff,
Is the other Windows application you want to communicate with built in CVI? You cannot directly access controls in another application, but you can pass data between applications in many different ways. If both applications are built in CVI, Measurement Studio, or LabVIEW, then you can use DataSocket or Shared Variables to share the data between applications. If you did not develope the other application, then the best hope would be an ActiveX server.
As for the clipboard, CVI does provide clipboard functions. Look at the Clipboard library under User Interface Library.
04-25-2011 03:47 PM
The other application that I am attempting to control is not a CVI built application. I have been trying to get a handle of the window of this application and then send messages to the window but have not been very successful at it...
I am able to get a handle to the application's window (I think) but when I attempt to send messages to it, nothing happens. Below is an image of my code and the menu item (Windows) that I am attempting to select by sending an alt W to the Peregrine window...
04-26-2011 04:45 PM
Hello,
You could use Windows API function SendInput, that can be used to send keyboard or mouse input to another window. Using it is a bit tricky, MSDN is a good starting point, try http://msdn.microsoft.com/en-us/library/ms646310(v=vs.85).aspx, but you'll find lots of other examples on the net.
Regards
04-27-2011 08:21 AM
Thank you for pointing me in the right driection.
After some searching on Google, I found the example below and modified it to suit my means:
}
@miniMe wrote:
Hello,
You could use Windows API function SendInput, that can be used to send keyboard or mouse input to another window. Using it is a bit tricky, MSDN is a good starting point, try http://msdn.microsoft.com/en-us/library/ms646310(v=vs.85).aspx, but you'll find lots of other examples on the net.
Regards
02-06-2018 09:07 PM
If possible, can you share the modified code?
Thanks.
wrote:
Thank you for pointing me in the right driection.
After some searching on Google, I found the example below and modified it to suit my means:
#include <iostream>#include <windows.h>#include <winable.h> /* Dev-C++ specific */using namespace std;/* HWND = "Window Handle" */HWND GameWindow = FindWindow(0, "Brood War");/* This is a function to simplify usage of sending keys */void GenerateKey(int vk, BOOL bExtended) {KEYBDINPUT kb = {0};INPUT Input = {0};/* Generate a "key down" */if (bExtended) { kb.dwFlags = KEYEVENTF_EXTENDEDKEY; }kb.wVk = vk;Input.type = INPUT_KEYBOARD;Input.ki = kb;SendInput(1, &Input, sizeof(Input));/* Generate a "key up" */ZeroMemory(&kb, sizeof(KEYBDINPUT));ZeroMemory(&Input, sizeof(INPUT));kb.dwFlags = KEYEVENTF_KEYUP;if (bExtended) { kb.dwFlags |= KEYEVENTF_EXTENDEDKEY; }kb.wVk = vk;Input.type = INPUT_KEYBOARD;Input.ki = kb;SendInput(1, &Input, sizeof(Input));return;}int main() {/*SetForegroundWindow will give the window focus for thekeyboard/mouse! In other words, you don't have to havethe game opened upfront in order to emulate key/mousepresses, it's very helpful if it's a game that runsin fullscreen mode, like StarCraft: Brood War does*/SetForegroundWindow(GameWindow);GenerateKey(VK_CAPITAL, TRUE);GenerateKey('I', FALSE);GenerateKey(' ', FALSE);GenerateKey(VK_CAPITAL, TRUE);GenerateKey('A', FALSE);GenerateKey('M', FALSE);GenerateKey(' ', FALSE);GenerateKey('C', FALSE);GenerateKey('O', FALSE);GenerateKey('O', FALSE);GenerateKey('L', FALSE);GenerateKey('E', FALSE);GenerateKey('R', FALSE);GenerateKey(' ', FALSE);GenerateKey('T', FALSE);GenerateKey('H', FALSE);GenerateKey('A', FALSE);GenerateKey('N', FALSE);GenerateKey(' ', FALSE);GenerateKey('Y', FALSE);GenerateKey('O', FALSE);GenerateKey('U', FALSE);GenerateKey(' ', FALSE);GenerateKey('W', FALSE);GenerateKey('I', FALSE);GenerateKey('L', FALSE);GenerateKey('L', FALSE);GenerateKey(' ', FALSE);GenerateKey('E', FALSE);GenerateKey('V', FALSE);GenerateKey('E', FALSE);GenerateKey('R', FALSE);GenerateKey(' ', FALSE);GenerateKey('B', FALSE);GenerateKey('E', FALSE);GenerateKey('n', FALSE);GenerateKey(' ', FALSE);GenerateKey(0x3A, FALSE); /* period key */GenerateKey(0x0D, FALSE); /* enter key */return 0;}
@miniMe wrote:
Hello,
You could use Windows API function SendInput, that can be used to send keyboard or mouse input to another window. Using it is a bit tricky, MSDN is a good starting point, try http://msdn.microsoft.com/en-us/library/ms646310(v=vs.85).aspx, but you'll find lots of other examples on the net.
Regards
wrote:
Thank you for pointing me in the right driection.
After some searching on Google, I found the example below and modified it to suit my means:
#include <iostream>#include <windows.h>#include <winable.h> /* Dev-C++ specific */using namespace std;/* HWND = "Window Handle" */HWND GameWindow = FindWindow(0, "Brood War");/* This is a function to simplify usage of sending keys */void GenerateKey(int vk, BOOL bExtended) {KEYBDINPUT kb = {0};INPUT Input = {0};/* Generate a "key down" */if (bExtended) { kb.dwFlags = KEYEVENTF_EXTENDEDKEY; }kb.wVk = vk;Input.type = INPUT_KEYBOARD;Input.ki = kb;SendInput(1, &Input, sizeof(Input));/* Generate a "key up" */ZeroMemory(&kb, sizeof(KEYBDINPUT));ZeroMemory(&Input, sizeof(INPUT));kb.dwFlags = KEYEVENTF_KEYUP;if (bExtended) { kb.dwFlags |= KEYEVENTF_EXTENDEDKEY; }kb.wVk = vk;Input.type = INPUT_KEYBOARD;Input.ki = kb;SendInput(1, &Input, sizeof(Input));return;}int main() {/*SetForegroundWindow will give the window focus for thekeyboard/mouse! In other words, you don't have to havethe game opened upfront in order to emulate key/mousepresses, it's very helpful if it's a game that runsin fullscreen mode, like StarCraft: Brood War does*/SetForegroundWindow(GameWindow);GenerateKey(VK_CAPITAL, TRUE);GenerateKey('I', FALSE);GenerateKey(' ', FALSE);GenerateKey(VK_CAPITAL, TRUE);GenerateKey('A', FALSE);GenerateKey('M', FALSE);GenerateKey(' ', FALSE);GenerateKey('C', FALSE);GenerateKey('O', FALSE);GenerateKey('O', FALSE);GenerateKey('L', FALSE);GenerateKey('E', FALSE);GenerateKey('R', FALSE);GenerateKey(' ', FALSE);GenerateKey('T', FALSE);GenerateKey('H', FALSE);GenerateKey('A', FALSE);GenerateKey('N', FALSE);GenerateKey(' ', FALSE);GenerateKey('Y', FALSE);GenerateKey('O', FALSE);GenerateKey('U', FALSE);GenerateKey(' ', FALSE);GenerateKey('W', FALSE);GenerateKey('I', FALSE);GenerateKey('L', FALSE);GenerateKey('L', FALSE);GenerateKey(' ', FALSE);GenerateKey('E', FALSE);GenerateKey('V', FALSE);GenerateKey('E', FALSE);GenerateKey('R', FALSE);GenerateKey(' ', FALSE);GenerateKey('B', FALSE);GenerateKey('E', FALSE);GenerateKey('n', FALSE);GenerateKey(' ', FALSE);GenerateKey(0x3A, FALSE); /* period key */GenerateKey(0x0D, FALSE); /* enter key */return 0;}
@miniMe wrote:
Hello,
You could use Windows API function SendInput, that can be used to send keyboard or mouse input to another window. Using it is a bit tricky, MSDN is a good starting point, try http://msdn.microsoft.com/en-us/library/ms646310(v=vs.85).aspx, but you'll find lots of other examples on the net.
Regards