I've just set up Code::Blocks with gfortran on my PC (Win 8.1, 64-bit). I'm trying to write a routine to position the text cursor. I've tried several variations on:
[pre]! Locate does the Windows-API-related work of moving the text cursor.
Subroutine Locate(Row, Col) ! bind(C, name='SetConsoleCursorPosition')
use iso_c_binding
integer, INTENT(IN) :: Row ! On screen, 0-24.
integer, INTENT(IN) :: Col ! On screen, 0-79.
integer :: Coord ! Composite value of row and column.
integer :: HandleForConsole ! From GetStdHandle routine.
integer(c_long) :: GetStdHandle
integer(c_long) :: SetConsoleCursorPosition
Row = Row - 1 ! Convert from Fortran 1-based
Col = Col - 1 ! numbering to C 0-based.
Coord = 65536 * Row + Col ! Jam both values into 1 integer.
HandleForConsole = GetStdHandle(STD_OUTPUT_HANDLE)
Call SetConsoleCursorPosition(HandleForConsole, Coord) ! Go!
End Subroutine Locate[/pre]
Nothing works. The program runs, but the subroutine is ineffective. I could use any suggestions.
[pre]! Locate does the Windows-API-related work of moving the text cursor.
Subroutine Locate(Row, Col) ! bind(C, name='SetConsoleCursorPosition')
use iso_c_binding
integer, INTENT(IN) :: Row ! On screen, 0-24.
integer, INTENT(IN) :: Col ! On screen, 0-79.
integer :: Coord ! Composite value of row and column.
integer :: HandleForConsole ! From GetStdHandle routine.
integer(c_long) :: GetStdHandle
integer(c_long) :: SetConsoleCursorPosition
Row = Row - 1 ! Convert from Fortran 1-based
Col = Col - 1 ! numbering to C 0-based.
Coord = 65536 * Row + Col ! Jam both values into 1 integer.
HandleForConsole = GetStdHandle(STD_OUTPUT_HANDLE)
Call SetConsoleCursorPosition(HandleForConsole, Coord) ! Go!
End Subroutine Locate[/pre]
Nothing works. The program runs, but the subroutine is ineffective. I could use any suggestions.