Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vertical tab in a Windows OS window

Status
Not open for further replies.

rih5342

Marine/Ocean
May 8, 2007
40
I'm running my program from a windowsOS command line window and outputting data and character strings to the same window.

I can write non-advancing output and overwrite the same line via backspaces and writing again (on the same line).

Is it possible, with Fortran, to do an upward vertical tab and overwrite the line above, in a windowsOS command line window?

Thank you.

 
Replies continue below

Recommended for you

If you're running XP, it will work on command.com provided ansi.sys is loaded (you need to change config.nt). It doesn't work on cmd.exe. Just make sure that the height of "Window Size" and "Screen buffer size" are the same. Alternatively there are some windows routines to move the cursor to any point on the screen.
 

Thank you.

Regarding Alternatively there are some windows routines to move the cursor to any point on the screen.

To get me started, what are the names of these windows routines?

Are they in the form of a dll requiring a multilanguage call from Fortran to C++ via interface statements?

 
Which development system are you using (Silverfrost, Intel, gcc etc)? The routine names vary.

They are normally multilanguage but dev systems like Intel already have the interfaces: all you need to do is call them. I may even be able to give you an example but I have to know what development system you're using.
 
Sorry - no makefile. I don't use make on windows. To build
Code:
gfortran -g -o cursorg.exe cursorg.f90
The following puts a message at 40,10 on the screen
Code:
module winconsole
   use, intrinsic:: ISO_C_BINDING
   type, bind(C):: COORD
      integer(C_SHORT) X 
      integer(C_SHORT) Y 
   end type  COORD
   
   integer (C_LONG), parameter:: STD_INPUT_HANDLE = -10
   integer (C_LONG), parameter:: STD_OUTPUT_HANDLE = -11
   integer (C_LONG), parameter:: STD_ERROR_HANDLE = -12
   interface       
      function GetStdHandle(nStdHandle) &
         bind (C, name='GetStdHandle')
         import
         !GCC$ attributes dllexport, stdcall :: GetStdHandle
         integer (C_INTPTR_T) GetStdHandle
         integer (C_LONG), value:: nStdHandle
      end function GetStdHandle
      
      function SetConsoleCursorPosition (hConsoleOutput, dwCursorPosition ) &
         bind (C, name='SetConsoleCursorPosition')
         import
         !GCC$ attributes dllexport, stdcall :: SetConsoleCursorPosition
         integer(C_INT) SetConsoleCursorPosition
         integer(C_INT), value:: hConsoleOutput
         type(COORD), value:: dwCursorPosition
      end function SetConsoleCursorPosition
 
      function  WriteFile (hConsoleOutput ,lpCharacter ,nLength , lpNumberOfCharsWritten, overlapped ) &
         bind (C, name='WriteFile')
         import
         !GCC$ attributes dllexport, stdcall :: WriteFile
         integer (C_INT) WriteFile
         integer (C_INT), value:: hConsoleOutput
         character(kind=C_CHAR):: lpCharacter(1)
         integer (C_INT), value:: nLength
         integer (C_INT) lpNumberOfCharsWritten
         integer (C_INT) overlapped
      end function WriteFile
      
      function GetLastError() bind(C, name='GetLastError')
         import
         !GCC$ attributes dllexport, stdcall:: GetLastError
         integer (C_INT) GetLastError
      end function GetLastError
   end interface

contains
end module winconsole

program cursorg
   use, intrinsic :: ISO_C_BINDING
   use winconsole
   
   integer(C_LONG):: ires, written, leng
   integer(C_INTPTR_T):: hout
   type(COORD) posn
   integer, parameter:: TITLE_LEN = 80
   character(len=TITLE_LEN):: str
   
   hout = GetStdHandle(STD_OUTPUT_HANDLE)
   if (hout .eq. -1) then
      ires = GetLastError()
      print *, ires
      stop
   end if
   posn%x = 40
   posn%y = 10
   str = 'Hey it works'
   
   ires = SetConsoleCursorPosition(hout, posn)
   leng = len_trim(str)
   ires = WriteFile(hout, str, leng, written, 0)
   read (*,*) str
end program
This will need kernel32.a which can be obtained from the gcc website. The cmd prompt needs to have the same number of lines in the screen buffer and the window.
 
Great, thank you, I'll check it out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor