LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Set Cursor Position in Console Window (Either Windows Default or CVI console)

Solved!
Go to solution

Hello all,

 

I am working on a project for my college class with a large amount of data acquisition. Unfortunately, part of the assignment requests it to be done entirely in the console rather than through a User Interface.

 

I have previously programmed in C++ and have used the gotoxy() command. However, this is not part of the ANSI C standard. I cannot find any further information about cursor position in C standards or in CVI. Is there any way to position the cursor in CVI? If I have to, I'll resort to creating a character matrix as a screen buffer and code it manually.

 

Thanks again!

 

-Bryan

CVI 8.5

0 Kudos
Message 1 of 4
(7,205 Views)

gotoxy is not a standard function because console capabilities are not standard. so, the C language does not define any ways of controlling your cursor. 

 

however, 2 characters are almost standard and supported by most environement, and may help for simple tasks:

- '\r' returns the cursor to the beginning of the line. this way you can rewrite a line multiple time.

- '\t' advances the cursor by one tab width (generally 8 characters).

 

under CVI, i don't know of any absolute way to set your character position. using the Windows SDK on a standard console window, there is a lot of functions which allows you to control cursor placement, colors, etc... look for SetConsoleCursorPosition() and its related functions (chapter Character mode applications of the SDK). these functions are a bit trickier to use but are very powerful. unfortunately, they work only under Windows.

 

regarding the character matrix idea:  given the slowness of character output from standard C function, i think this is not a good idea at all... also, keep in mind that the console attributes (width, height, etc...) is not defined from a pure C point of view, so your matrix may break only by setting your console to 50 lines instead of the standard 25 lines.

0 Kudos
Message 2 of 4
(7,195 Views)
Lucky for me, these applications for class will only be run in Windows. Is there a specific method to load the windows libraries into my project? Thanks!
0 Kudos
Message 3 of 4
(7,179 Views)
Solution
Accepted by topic author XBrav

these functions are part of the windows kernel. you only have to #include <windows.h>. if you get a link error, these functions should be in "kernel32.lib" which ships with LabWindows/CVI: add kernel32.lib to the project and everything should be fine (search your x:\Program Files\National Instruments\ folder to locate it, its complete location depends on the version of CVI you are using).

 

of course, this means you need to install the Windows SDK: this is an option in the LabWindows/CVI installer. (you can also download the Windows SDK from the microsoft website, but you'd be better using the one coming with CVI).

 

a little user's guide about the Windows SDK documentation: every function is documented in a single page. on every function documentation page, there is always a small summary at the end of the page telling you how to use the function: which header file you need to include, which library file you need to link with, and on which version of Windows the function is supported. unfortunately, until CVI 8.5.1 (i don't know for CVI 9.0), the SDK documentation does not include the table of content, thus preventing from finding anything useful unless you know what function you are looking for.

Message 4 of 4
(7,156 Views)