Silverfrost Forums

Welcome to our forums

Creating window with win32API

1 Dec 2022 7:21 #29651

Hi,

does anybody have a working example of how to create a window by way of win32API in FTN95? Or a way to establish a window-procedure to a clearwin+ window?

What i am lacking is a way to define a pointer to my WndProc as needed in wndclass.

Cheers Norbert

1 Dec 2022 9:37 #29652

Norbert

Can you provide more details of what you want to do and how you aim to do it?

The whole point of ClearWin+ is to handle this kind of complexity for you.

2 Dec 2022 12:46 #29653

To put it simple: I have a good text-book on windows programming (by Charles Petzold) that I find easy to follow and I am lacking one on Clearwin+.

First off: I am not a professional programmer, just on occasion I pursue some privat projects. So most of the time I have to follow a more or less steep learnbing curve.

With that said, my current idea is to do kind of a real world simulation of our power grid. This would require the user to move things on a map, zoom in and out, input data and the like. I have tried Clearwin+ on a prior occasion and found that it does not support this kind of task very well (or I failed to spot any help from the documentation which amounts to the same).

Some of the Clearwin-functions work with OpenGL-windows, others don't Get_Mouse_Info@ for instance. To get my mouse input working I had to provide quite a number of different callbacks namely

  • to catch movement of the mouse wheel
  • to get the mouse position with any button pressed and without
  • to get doubleclick

And for all I know I have to define such functions for any window. In win32API the data I need to act on come with the call of windows-procedure.

I have worked with win32API before (with Compaq-Fortran) and found it not too difficult.

Hopefully that clarifies my position a bit.

Cheers Norbert

2 Dec 2022 3:38 #29654

There is a 'getting started' section in FTN95.chm under ClearWin+ → ClearWin+ Tutorial.

There are videos provided at https://www.silverfrost.com/59/ftn95/videos.aspx.

Sample programs are provided in the default installation. On my maching the path to the samples is C:\Users\<My name>\OneDrive\Documents\FTN95 Examples\clearwin.

Additional help for users like yourself is expected in the next full release which should appear shortly.

2 Dec 2022 3:58 #29655

Thanks Paul.

I had looked up all the resources you indicated.

Looking forward to this release.

Cheers Norbert

2 Dec 2022 4:09 #29656

Hi Norbert,

I have helped several 'beginners' and have written a c. 200 page book on the subject of developing Windows GUIs using ClearWin+. I've given it FOC to Silverfrost to include in their software. My current draft has some typos, but if you are prepared to forgive them, and send me an e mail address, I can send you a PDF.

It's targetted at people like yourself who are competent at Fortran, and suggests an order in which to do things that is intended to flatten the learning curve.

Eddie

PS It's currently being run through to get rid of those typos. (Send the email address via a private message ).

3 Dec 2022 9:19 #29661

Thanks, Eddie, for your kind offer. You will receive a personal message from me presently. And with the typos: Usually I deploy quite a considerable set of them whenever I try to type things into my keyboard. And I find them only long after I have submitted my text. So it seems I am pretty good in overlooking them.

Cheers Norbert

3 Dec 2022 9:38 #29662

More or less out of curiosity I started to try my luck with a full window-application. I used my old files from CVF as source and here is what I came up with - together with some weird error messages. This sample code will open a Window an write 'Hello world' to it.

!
!	Programm Hellowin nach 'Windows-Programmierung',S.48
!
	integer function winmain (hInstance, hPrevInstance, szCmdLine, nCmdShow)
		!DEC$ ATTRIBUTES STDCALL, DECORATE, ALIAS:”WinMain” :: WinMain

    use MyDFWINTY
	implicit none
	include <windows.ins>, nolist

	interface	
		integer(HANDLE) function WndProc(hwnd, message, wPAram, lParam) 
		integer hwnd, message, wParam, lParam
		end function WndProc
	end interface

	character*10 :: szAppName = 'HelloWin'

	integer(HANDLE) hInstance, hPrevInstance
    integer(3) szCmdLine 
	integer(3) nCmdShow
	integer(HANDLE) hwnd
    
!    wparam,lparam

	integer irslt
	logical lrslt

	type (T_WNDCLASS) wndclass
	type (T_MSG) msg


	wndclass%style = ior(CS_Hredraw,CS_Vredraw)
	wndclass%lpfnWndProc = loc(WndProc)
	wndclass%cbClsExtra = 0
	wndclass%cbwndextra = 0
	wndclass%hInstance = hinstance
	wndclass%hIcon = LoadIcon (NULL, IDI_APPLICATION)
	wndclass%hCursor = LoadCursor (NULL, IDC_ARROW)
	wndclass%hbrBackground = GetStockObject (WHITE_BRUSH)
	wndclass%lpszMenuName = NULL
	wndclass%lpszClassName = loc(szAppName)

	irslt = RegisterClass (wndclass)

	if (irslt.eq.0) then
		irslt = MessageBox(NULL,'Fensterregistrierung fehlgeschlagen',szAppName,MB_IconError)
		winmain = 0				!	<---- ERROR 1037
		return
	endif

	hwnd = CreateWindowEX(	CW_USEDEFAULT,						&
    						szAppName,							&
							'Das erste echte Programm'C,		&
							int4(WS_OVERLAPPEDWINDOW),			&
							CW_USEDEFAULT,						&
							CW_USEDEFAULT,						&
							CW_USEDEFAULT,						&
							CW_USEDEFAULT,						&
							NULL,								&
							NULL,								&
							hInstance,							&
							NULL)	! <--- ERROR 283

	lrslt = ShowWindow(hwnd,SW_SHOWNORMAL)
	lrslt = UpdateWindow(hwnd)

	do while (GetMessage(msg,NULL,0,0))
		irslt = Translatemessage (msg)
		irslt = Dispatchmessage (msg)
	enddo

	winmain = msg%wParam		! <---- ERROR 1037

	return
	end

On compiling I get three error messages, I indicated the flagged lines.

(twice) error 1037 - Variables with the EXTERNAL attribute, such as (RESULT of WINMAIN), cannot be in assignment expressions (with '=')

and

error 283 - INT4 must appear in a type declaration because IMPLICIT NONE has been used

I fail to see what would be wrong. Anybody else?

Cheers Norbert

4 Dec 2022 8:42 #29663

Norbert

At the core of ClearWin+ there is a message loop like the one in this code. In others words ClearWin+ provides an interface into the Windows API that allows users to avoid this complexity.

There will probably be a fix that makes this code work but I suspect that it will take you down the wrong path if you want to use ClearWin+.

4 Dec 2022 5:09 #29664

Paul,

I am not yet really convinced that Clearwin is the proper solution for me. But I am willing to give it a try.

As to my code: Problem seems to be that there is an external WinMain defined, somewhere in the files that get included with <windows.ins>. And this definition is still present even if I only include win32API.ins and win32prm.ins skipping clearwin.ins.

So for all I know it is impossible to use FTN95 to build a full windows application. Why is that? What would be wrong about this approach?

Cheers Norbert

4 Dec 2022 7:14 #29665

Norbert

There is no reason to suppose that you won't be able to do it with FTN95.

Naturally I am tempted by the challege but to be sensible there is really no good reason to take this route.

5 Dec 2022 8:29 #29666

Some further points that may be of interest...

  1. A 'Hello World' program in ClearWin+ takes the form PROGRAM main iw = winio@('Hello World') END PROGRAM main

    The @ character can be replaced by $ and adding WINAPP before the program line provides instructions to the linker that makes the app a 'Windows' app rather than a 'Console' app.

  2. There is no 'message loop' in a ClearWin+ program. It is provided for you within the ClearWin+ library. The only situation where you need direct access to the message loop is when the program is doing a time consuming calculation. This might, for example, cause the mouse cursor to freeze. In which case you can call TEMPORARY_YIELD@() and this forces a message loop catch-up.

  3. The program presented above uses a comment embedded directive !DEC that will not be recognised by FTN95. So the whole of that line has no effect.

  4. The module MyDFWINTY is need for compilation.

  5. When writing a program in C it begins int main(... For Microsoft and Windows programs this becomes int WinMain(.... main and WinMain are applied at the level of the linker when communicating with the operating system. The return value from this 'function' relates to an exit code from the program. There is no direct equivalent in Fortran in the sense that PROGRAM is more like a 'subroutine' than a 'function' returning a value.

So how does one go about writing a low-level Windows application using FTN95 and SLINK or SLINK64? Off hand I don't know and my initial reaction is not to attempt it.

5 Dec 2022 10:12 #29668

Thanks, Paul for your elaborate explanation. Of course I understand that Clearwin has its advantages and is the application of choice for certain tasks.

But: could you do something like this with Clearwin?

https://simulation.transurb.com/en/news/a-micro-simulator-to-recruit-future-belgian-train-drivers

This requires a running loop performed in fixed short intervals to update the status variables - which might include some lengthy calculations - while handling occasional user inputs.

I tried to do something similar with Clearwin using the timer (%dl). But I ran into problems once the computing time to update my status variables got longer than the timestep ('multiple call to subroutine'). Of course I could stop the timer while the update is under way, but this was not a good solution either because it yielded irregular time steps.

In Windows (using Compaq Visual Fortran) I was able to define two threads, one for doing the calculations, one for handling user-communication.

Is this possible with clearwin?

Cheers Norbert

5 Dec 2022 3:40 #29669

Independently of ClearWin+, an FTN95 program can create a separate thread via a call to Start_Thread@. In other words you can create a thread in a console application or in a Windows application via ClearWin+.

A calculation that is performed in a thread within a Windows application will leave the ClearWin+ part free to handle Windows events without interuption.

5 Dec 2022 5:24 #29670

FTN95 program can create a separate thread via a call to Start_Thread@.

That is good news. From this document here I took it that this would require to work in the NET frame: https://www.silverfrost.com/ftn95-help/netprog/threads.aspx

Okay, I will give it a try.

Cheers Norbert

6 Dec 2022 7:27 #29672

Start_thread@ works without NET too.

6 Dec 2022 4:48 #29673

Thanks Dan.

Please login to reply.