Interface to Windows Dialog Boxes

tinyfiledialogs is a cross-platform C library that provides modal dialogs and file dialogs. I’ve recently completed the interface module to call this code from Fortran.

	! calling function tinyfd_inputbox
	write(*,'(A)') "Enter tinyfd_inputbox()"
	aTitle = "a Title" // char(0)
	aMessage = "a Message" // char(0)
	aDefaultInput = "an Input" // char(0)
	cpointer = tinyfd_inputBox(aTitle, aMessage, c_loc(aDefaultInput) )
	! or for a password box: cpointer = tinyfd_inputbox(atitle, amessage, c_null_ptr )
	if ( c_associated(cpointer) ) then
                    ! Convert C Pointer to Fortran pointer
		call c_f_pointer(cpointer, fpointer) 
                    ! Remove NULL character at the end
		string = fpointer(1:index(fpointer,c_null_char)-1) 
		write (*,'(A)') string
	endif

tinyfiledialogs in Fortran handles char strings as UTF-8 (on windows and on unix).

1 Like

Hi @sblionel - is there a good reference with examples for using windows graphics API from Fortran?

The only one I know of is https://www.amazon.com/Compaq-Visual-Fortran-Creating-Applications/dp/1555582494 , but there are several examples provided in the Intel Samples Bundle https://software.intel.com/content/www/us/en/develop/download/776976.html

I also recommend reading https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-reference-build-windows-applications/15-0.html

2 Likes

It works as well with gfortran 13.1.0 (msys2) linking -lcomdlg32

Thanks a lot.

Kai-Uwe