From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to close CVI dialog window programmatically

I'm using CVI_AppOpenProject to open up CVI prj on automated tester but if a CVI
dialog window pops up then the window sits there waiting for the operator action defeating the purpose of automation (ie if relative paths change) .

I tried launching a thread to monitor fordialog windows using CVI_AppGetCVIState and using
keybd_event, but I can't bring focus of the CVI window to the foreground.  9There are other apps running on the foreground)

I looked at CVI_AppFakeKeystrokes but dont know how to use it (how to declare and populate a SAFEARRAY). Any suggestions or
examples to solve this problem are much appreciated. Thank you.

0 Kudos
Message 1 of 4
(4,868 Views)

Hello Janete!

 

You should be able to accomplish this scenario using the ActiveX functions: OpenProjectGetCVIState and FakeKeystrokes.

  1. In order to determine whether a modal dialog is blocking the CVI ADE window, you can query the waitingForUserResponseToDialog parameter of GetCVIState:
    http://zone.ni.com/reference/en-XX/help/370051Y-01/cvi/usermanual/actxappgetcvistate/
    Note that you can use the CVI automation sample application, located at <CVI Installation Directory>\samples\activex\cvi\cvidemo.prj, to see how this works. In this application, when there is a dialog open in CVI, the "Waiting for User Response" LED tuns red.
  2. Then, if you determine that a modal dialog is open, you can submit input to that dialog using FakeKeystrokes: Here is a sample code snipett I extracted from another CVI forum post:
    http://forums.ni.com/t5/LabWindows-CVI/Distribution-kit-via-command-line/td-p/197333
    SAFEARRAY *keySafeArray;
    //Alt-B, D, Alt-B
    int strokes[] = {VAL_UNDERLINE_MODIFIER | 'B','D',VAL_UNDERLINE_MODIFIER | 'B'};
    CA_Array1DToSafeArray (strokes, CAVT_INT, 3, &keySafeArray);
    CVI_AppFakeKeystrokes (newCVI, NULL, keySafeArray, &returnVal);

Note, that there is a caveat to using FakeKeystrokes, as this function will only be able to send keyboard input to CVI dialogs (e.g. message boxes, configuration dialogs, etc), but not Windows OS dialogs (e.g. file popup dialogs like 'Save File As').

 

hope this helps!

Best regards!

- Johannes

0 Kudos
Message 2 of 4
(4,845 Views)

Could FakeKeystrokes also send keys to open CVI menus?

0 Kudos
Message 3 of 4
(1,095 Views)

Hi ElectroLund

 

Please use CVI_AppFakeKeystrokes for to send fake keystrokes to CVI, instructing it to open menus in the ADE: https://www.ni.com/docs/en-US/bundle/labwindows-cvi/page/cvi/usermanual/actxappfakekeystrokes.htm

 

Johannes

0 Kudos
Message 4 of 4
(1,081 Views)