LabWindows/CVI User Group Documents

Showing results for 
Search instead for 
Did you mean: 

LabWindows/CVI Tip: Use Splitter Controls to Handle Panel Sizing

A common user interface requirement is to ensure proper layout for your controls when the window hosting the controls is resized.  As a LabWindows/CVI developer, you might attack this problem in a couple different ways:

  1. Explicitly respond to panel sizing events and programmatically move and size all the controls on the panel accordingly.
    • This is cumbersome, and puts the entire burden of control management on the developer.  Countless hours may be spent perfecting algorithms and refining layouts.
  2. Enable the "Scale Contents on Resize" option for each panel.
    • This doesn't require any time from the developer, but results in a UI that is not consistent with most other Windows programs.
  3. Use splitter controls to find a happy medium between these two options.

You can attach multiple controls to a splitter control, and define a behavior for each control individually when the splitter moves.  You can leverage this behavior to move and size controls automatically when the panel sizes, enabling control over the layout of the controls on your panel.  The trick to this is programmatically operating the splitter when the panel sizes with the OperateSplitter CVI library function call.  This does require some implementation, but because the sizing and moving of controls is entirely handled by the splitter control, the most burdensome part of the first listed option is removed.

To make things even easier, I've written a very small library (SplitterSizing.c and SplitterSizing.h) that should further simplify the process.  It is attached to this post, and exhibited with a simple example program.  There are three public functions:

  1. InitializeSplitterSizingForPanel
    • Initializes the library for a particular panel.  This function must be called for each panel that requires dynamic layout of it's controls.  The function also allows a minimum width and height to be defined for the panel.
  2. AddSplitterMoveControl
    • Configures a control to be moved when the panel is sized.
  3. AddSplitterSizeControl
    • Configures a control to be sized when the panel is sized.

The example program does nothing but show the sizing in action.  You can manually size the panel, maximize the panel, and move the panel around, but the controls on the panel maintain a very specific layout.  Consider the following before and after screenshots:

NickB0003 2011-01-19.pngNickB0004 2011-01-19.png

Member cwadding

Hi Nick, this is exactly the kind of problem I am trying to solve but I can nt get your sample code to compile. Probably something simple - I get:  found identifier expecting ; on the following line typedef intptr_t  SizingHandle;     in SplitterSizing.h  any ideas? Is it because I am running CVI 8.5 / 32bit perhaps?

Active Participant nickb
Active Participant

Yes, the issue you're running into is because you're using CVI 8.5, which does not define intptr_t in cvidef.h.  An easy way to resolve the error would be to replace the intptr_t int the typedef with void*.  You might need to then perform a cast to void* in the return statement of InitializeSplitterSizingForPanel.