LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to access/control the device handles of controls on other open windows with Lab Windows CVI?

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?

0 Kudos
Message 1 of 6
(3,915 Views)

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.

National Instruments
0 Kudos
Message 2 of 6
(3,891 Views)

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...

 

 

peregrine.jpg

0 Kudos
Message 3 of 6
(3,829 Views)

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

Message 4 of 6
(3,800 Views)

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 the
       keyboard/mouse! In other words, you don't have to have
       the game opened upfront in order to emulate key/mouse
       presses, it's very helpful if it's a game that runs
       in 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


 

 

 

0 Kudos
Message 5 of 6
(3,780 Views)

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 the
       keyboard/mouse! In other words, you don't have to have
       the game opened upfront in order to emulate key/mouse
       presses, it's very helpful if it's a game that runs
       in 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 the
       keyboard/mouse! In other words, you don't have to have
       the game opened upfront in order to emulate key/mouse
       presses, it's very helpful if it's a game that runs
       in 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


 

 

 


 

0 Kudos
Message 6 of 6
(2,901 Views)