forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Creating window with win32API
Goto page 1, 2  Next
 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
ursuselasticus



Joined: 26 Mar 2005
Posts: 66

PostPosted: Thu Dec 01, 2022 8:21 pm    Post subject: Creating window with win32API Reply with quote

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
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7481
Location: Salford, UK

PostPosted: Thu Dec 01, 2022 10:37 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message AIM Address
ursuselasticus



Joined: 26 Mar 2005
Posts: 66

PostPosted: Fri Dec 02, 2022 1:46 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7481
Location: Salford, UK

PostPosted: Fri Dec 02, 2022 4:38 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message AIM Address
ursuselasticus



Joined: 26 Mar 2005
Posts: 66

PostPosted: Fri Dec 02, 2022 4:58 pm    Post subject: Reply with quote

Thanks Paul.

I had looked up all the resources you indicated.

Looking forward to this release.

Cheers
Norbert
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2343
Location: Yateley, Hants, UK

PostPosted: Fri Dec 02, 2022 5:09 pm    Post subject: Reply with quote

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 ).
Back to top
View user's profile Send private message
ursuselasticus



Joined: 26 Mar 2005
Posts: 66

PostPosted: Sat Dec 03, 2022 10:19 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
ursuselasticus



Joined: 26 Mar 2005
Posts: 66

PostPosted: Sat Dec 03, 2022 10:38 pm    Post subject: Reply with quote

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.

Code:

!
!   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
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7481
Location: Salford, UK

PostPosted: Sun Dec 04, 2022 9:42 am    Post subject: Reply with quote

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+.
Back to top
View user's profile Send private message AIM Address
ursuselasticus



Joined: 26 Mar 2005
Posts: 66

PostPosted: Sun Dec 04, 2022 6:09 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7481
Location: Salford, UK

PostPosted: Sun Dec 04, 2022 8:14 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7481
Location: Salford, UK

PostPosted: Mon Dec 05, 2022 9:29 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message AIM Address
ursuselasticus



Joined: 26 Mar 2005
Posts: 66

PostPosted: Mon Dec 05, 2022 11:12 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7481
Location: Salford, UK

PostPosted: Mon Dec 05, 2022 4:40 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message AIM Address
ursuselasticus



Joined: 26 Mar 2005
Posts: 66

PostPosted: Mon Dec 05, 2022 6:24 pm    Post subject: Reply with quote

Quote:
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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group