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: 

LabWindows/CVI Tips 'n Tricks

Hello LabWindows/CVI community members,
 
After receiving multiple requests to collect all LabWindows/CVI tips/tricks in one area, we've decided to create this thread where you can post your tips and read other community-submitted suggestions.  Share your knowledge and learn helpful features of LabWindows/CVI straight from the development team!
 
So what can you do with this thread?
1) Post your own tips/tricks
2) Read tips / tricks submitted by NI developers
3) Link to any helpful discussion forum threads as you find them
 
How should I post to this thread?
1) Please change the subject line of your response to indicate the topic of the tip/trick.
2) Please indicate the lowest version of LabWindows/CVI that the tip/trick works with (if known)
 
The key to the success of this thread is making sure any tip/trick you find or use on a regular basis is posted to this thread.  If you find an answer in another thread that you feel would be helpful to the general LabWindows/CVI community, posted a link to that thread here.
 
Cheers! 
Message 1 of 42
(54,632 Views)

Hello everyone,

This is a tip that I've seen posted on a few forum threads but I wanted to include it here:

Improving the Performance of Table Controls

1. Try to update multiple cells at the same time with SetTableCelRangeVals function.  This reduces the overhead of updating cells greatly.

2. If you need to update a single cell at a time (as may be the case if you want to update a row with different datatypes, use the SetTableCellAttribute (...,ATTR_CTRL_VAL,...) function instead of the SetTableCellVal function.  Note: This will only make a difference if the table is not the active control on the panel.  So if it is the active control, programmatically make another control active before updating the table, and then make the table active again.  This will update the table without displaying the updates until the next call to ProcessDrawEvents or upon the exiting the current callback.  This is ideal when making repeated updates.

Original forum post:

SetTableCellRangeVals using for loading rows: http://forums.ni.com/ni/board/message?board.id=180&message.id=21055 

Using SetTableCellVal() in LW/CVI to display about 20000 lines of data. But the speed is very slow,how can I improve it?: http://forums.ni.com/ni/board/message?board.id=180&message.id=6577

 

Thanks

Message 2 of 42
(54,748 Views)
Interactively Change the Settings of Multiple Controls
 
Starting with LabWindows/CVI 8.1, you can select multiple user interface controls of the same type and edit them simultaneously.  Select multiple controls on the User Interface Editor and choose Edit>>Controls or double click the controls to open the Edit Control dialog box.
 
 
Minimum Version: 8.1
 
 
Thanks

Message Edited by Wendy L on 03-13-2007 12:26 AM

Message 3 of 42
(54,768 Views)

Handling menu items state depending on application state

In several applications it's common to have well-structured menu bars that collect useful functions in the program. Normally, not all menu items can be executed in every program conditions: you may want to avoid taking a copy of test data while a test is still running to prevent the risk of accessing the same data file from two operations; again, you may want to permit starting a test only after an explicit confirmation that testing conditions are safe; even more, you cannot start a test which is already running ( Smiley Surprised ), and so on.

Individual menu items can be dimmed with SetMenuBarAttribute (, , ATTR_DIMMED, ) when operating conditions change; a disadvantage in doing this is that in every single moment in the program you detect a change in operating conditions you must proceed to dim / undim all menu items interested by this change: this can be long and boring and you may run the risk of forgetting some particular precaution and place the application in an unforeseen (possibly dangerous) state. Moreover, all these operations are performed even if not necessary.

CVI offers an easy and elegant instrument to centralize all menu handling, that additionally adds no unnecessary overhead to the application since it is executed only when the operator fires up the menu bar. This instrument is

InstallMenuDimmerCallback (menuBarHandle, MenuDimmerFunction);

Being called before the menu shows, in MenuDimmerFunction we can individually show or dim individual menu items depending on program working conditions thus being sure that every time the operator is presented with all and only legal items.

Attached sample shows a very simple example of this functionality.

Message Edited by Roberto Bozzolo on 03-13-2007 05:08 PM



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?
Message 4 of 42
(54,711 Views)
I'll add a couple of sub-tips to Roberto's tip:

1. The menu dimmer callback is sent not only when you click on the menu, but also when you hit a key that might invoke a menu item. This allows you to intercept shortcut keys as well as mouse actions. The ATTR_SEND_DIMMER_EVENTS_FOR_ALL_KEYS menubar attribute determines whether only the callback is called only for the currently specified shortcut keys, or for any key that could conceivably be a shortcut key (this allows you to also set and unset shortcut keys on demand).

2. If you'd like to receive specific dimmer callbacks for individual menus, in addition to (or instead of) a global callback, there is an undocumented function (okay... it's not officially supported, but I guess that's what this thread is for Smiley Tongue) that you can use. To use it, you'll have to include the following extern statements in your code:

typedef void (__cdecl * MenuDimmerExCallbackPtr)(int menuBar, int menu, int menuItem, int panel, int event, void *callbackData, int eventData);
extern int InstallMenuDimmerCallbackEx (int menuBar, int menu, MenuDimmerExCallbackPtr dimmerFunction, void *callbackData);

Luis
Message 5 of 42
(54,685 Views)
"Hidden" features in the CVI IDE
There are a few features in the CVI Interactive Development Environment (IDE) that took me a while to discover, simply because I stuck with my old workflow habits. Make sure you know how to put these to good use:
  • Options > Environment > Auto hide Project and Library Trees
  • Tools > Preprocess Source File to easily see what is being "#include"ed when your source compiles
  • Ctrl-Tab to cycle between source code files.
  • The "Programmers ToolBox", particularly for string and filename manipulation.   To load it choose Library > Customize > Browse; then navigate to ..<cvidir>\toolslib\toolbox\toolbox.fp
  • Right-click on just about anything in your source code and choose the "Browse Identifier".  Very powerful to see where variables are used and declared, and which functions call what.
Message 6 of 42
(52,862 Views)
I use this one every day. If have a CVI project open and sometimes I want to go to the folder where my file(C or UIRor fp) is on my HD. This would mean trying to figure out where it is by looking at the CVI title bar or by looking at the fulls file paths in the project file list. Thats too much work. Instead, I just added an entry in the CVI tools menu that would make my life easier.

Go to Tools menu >> Customize
In the Customize Tools Menu dialog, add a menu item name. I call it explorer
Set the program name to "explorer.exe" (without the quotes)
Set the command line arguments to " /select, "%FILE%"  " (you need the inner quotes)

I have a snapshot attached of what all the options are.



Now if you have a C/UIR open in CVI, and you go to Tools >> explorer, another explorer window will popup and highlight the file that was open in CVI, showing you the full path to it.

Enjoy!
 

Message Edited by bilalD on 03-16-2007 04:13 PM

Bilal Durrani
NI
Message 7 of 42
(54,551 Views)

Good suggestion, Bilal! I can add that prepending to some letter in Menu item name the usual double underscore ( "__" ) you can set an accelerator key for the option. Smiley Happy

...unfortunately Tools menu is already full of items, so only the following letters are available; B D G H J K M N Y W Smiley Surprised I have added this option to the tools menu, calling it "File bro__wser" to use Alt + T + W as accelerator key Smiley Wink

If only adding some shortcuy key was possible....



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?
Message 8 of 42
(54,535 Views)

Hello all,

unfortunately, Labwindows has no support for the mouse wheel, which is nowadays commonly used in applications. When using textboxes in the user interface, I think that most users automatically think that the mouse wheel can be used to scroll this textbox up and down (so would I). So I wrote a piece of code that I now include in all my projects to support this request. It's actually quite simple. For each panel that gets loaded, I use the InstallWinMsgCallback function, with the MessageNumber parameter set to WM_MOUSEWHEEL.

Important note: for WM_MOUSWHEEL to be defined, windows.h should be included, and _WIN32_WINNT should be at least defined to 0x0400. To make sure this last definition is made, open the Build Options window (can be found in the Options menu), and enter /D_WIN32_WINNT=0x0400 in the "Compiler Defines" field.

I attached an example program to this message, which shows how to enable textbox scrolling with the mouse wheel in a very simple way. More information on the WM_MOUSEWHEEL message number can be found in the MSDN library:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/us...

I hope this post is usefull for at least some of you guys Smiley Wink

Message 9 of 42
(54,418 Views)

A few accelerators are present in the IDE that can help a lot in developing applications.

Everybody knows that in the UIR editor right-clicking on a control popups a menu by which it's possible to jump directly to control's callback (item "View control callback").

The symmetric action from a source code window is to place the cursor on a control name and press Ctrl-F: you will jump into the UIR editor window with the stated control already selected. This option is equivalent to right-clicking on the control name and select "Find UI object" option).

I recently discovered that this option is present on callback function names too: selecting the function name and pressing Ctrl-F jumps me to the UIR editor window Smiley Happy If the function is associated to more controls, a popup window will be shown with the list of controls for we to select the desired control to select.



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?
Message 10 of 42
(54,351 Views)