DDT with FreeBasic Project

Started by José Roca, May 03, 2025, 06:02:20 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca

I have managed to replicate the PowerBasic dialog engine. Besides being able to use dialog units or pixels, you can also use your own class name. No more problem to use FindWindow because all PB dialogs use the "#32770" class.

   ' // Set process DPI aware
   AfxSetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE)
   ' // Enable visual styles without including a manifest file
   AfxEnableVisualStyles

   ' // Create an instance of the Dialog class. The default font is Segoe UI, 9 points.
   ' // You can specify the font, size, style and charset, e.g. DIM pDlg AS CDialog = CDialog("Tahoma", 9).
   DIM pDlg AS CDialog = CDialog("Segoe UI", 9)
   DIM dwStyle AS LONG = WS_OVERLAPPEDWINDOW OR DS_MODALFRAME OR DS_CENTER

   ' // Create dialog using dialog units
   DIM hDlg AS HWND = pDlg.DialogNew(0, "Dialog New",,, 440, 190, dwStyle)
   ' // Create custom dialog using dialog units
'   DIM hDlg AS HWND = pDlg.DialogNew("MyClassName", 0, "Dialog New",,, 440, 190, dwStyle)

   ' // Create dialog using pixels
'   DIM hDlg AS HWND = pDlg.DialogNewPixels(0, "Dialog New",,, 1344, 777, dwStyle)
   ' // Create custom dialog using pixels
'   DIM hDlg AS HWND = pDlg.DialogNewPixels("MyClassName", 0, "Dialog New",,, 1344, 777, dwStyle)

Thanks to Pierre Bellisle for letting me know about the possibility of using visual styles without including a manifest file. Very useful for testing.

José Roca

The option of using pixels does not work as it should. Using dialog units works perfectly, both using the predefined dialog class and a custom class.

José Roca

#2
Problem solved. When using pixels, resizing has to be done using the High DPI ratios, which are not the same as the dialog units to pixels ratios.

Now we have four possibilities: classic dialog (#32770), custom dialog (custom class), classic dialog using pixels, custom dialog using pixels.

Using CDialog with pixels works like CWindow. Therefore, I don't need to adapt CWindow.

The advantage of using dialog units is that the main window and the controls are resized changing the font. The disadvantage is that the ratios change, making it hard to work with the Windows standard controls that work with pixels.

José Roca

#3
I have fully replicated (and improved) the PowerBasic dialog engine. Like PB can work with classic dialogs (window class #32770), both using dialog units or pixels, and unlike PB it allows the creation and use of custom dialogs wirh the class name of your choice and it is DPI aware when workimg with pixels. Works with 32 and 64-bit without changing anything in the code.

I also have integrated optional anchoring of the controls for easy automatic resizing when the size of the dialog changes.

Code available in GitHub:

https://github.com/JoseRoca/WinFBX2

José Roca

#4
I'm writing now a procedural wrapper to allow the use of CDialog with a DDT-like syntax. Do you think that it is DDT-friendly enough? The main difference if that it will use functions instead of these outdated and horrible statements, i.e. instead of CONTROL GET TEXT hDlg, id& TO txt$, it will use txt = ControlGetText(hDlg, id).

#include once "Afx2/DDT.inc"
USING DDT

' // Forward declaration
DECLARE FUNCTION DlgProc (BYVAL hDlg AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

' // Button identifier
CONST IDC_BUTTON = 1001

' ******* PROGRAM START ******

' // Create a dialog using dialog units
' // It is equivalent to DIALOG NEW (the class name used is the standard #32770)
DIM dwStyle AS LONG = WS_OVERLAPPEDWINDOW OR DS_CENTER
DIM hDlg AS HWND = DialogNew(NULL, "Dialog New", 50, 50, 175, 75, dwStyle)

' // Add a button
' // It is equivalent to CONTROL ADD (can be used with any control)
ControlAdd "Button", hDlg, IDC_BUTTON, "&Click me", 95, 45, 50, 12

' // Anchor the button to the bottom and right sides of the dialog
' // The button will be repositioned automatically to the new width
' // and height of the dialog when you resize it.
' // This has not equivalence in DDT
ControlAnchor(hDlg, IDC_BUTTON, ANCHOR_BOTTOM_RIGHT)

' // Display and activate the dialog as modal
' // This is equivalent to DIALOG SHOW MODAL
DialogShowModal(hDlg, @DlgProc)

' ******* PROGRAM END ******
END

' ========================================================================================
' Main window procedure
' ========================================================================================
FUNCTION DlgProc (BYVAL hDlg AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

   SELECT CASE uMsg

      CASE WM_INITDIALOG
         RETURN TRUE

      CASE WM_COMMAND
         SELECT CASE CBCTL(wParam, lParam)
            CASE IDCANCEL
               ' // If ESC key pressed, close the application by sending an WM_CLOSE message
               IF CBCTLMSG(wParam, lParam) = BN_CLICKED THEN
                  SendMessageW hDlg, WM_CLOSE, 0, 0
               END IF
            CASE IDC_BUTTON
               IF CBCTLMSG(wParam, lParam) = BN_CLICKED THEN
                  MsgBox "Button pressed"
               END IF
         END SELECT

      CASE WM_CLOSE
         ' // End the application
         ' // This is equivalent to DIALOG END
         DialogEnd(hDlg)

   END SELECT

   RETURN FALSE

END FUNCTION
' ========================================================================================

José Roca

BTW Paul Squires is finishing a new editor that will make the use of my framework and FreeBasic a breeze.

José Roca

To subclass controls, it is much better to use the SetWindowSubclass API function that the outdated method used by DDT when you add CALL callback to CONTROL ADD. Things evolve and we and to keep up to date.


Theo Gottwald

#7
Quote from: José Roca on June 02, 2025, 03:24:32 PMBTW Paul Squires is finishing a new editor that will make the use of my framework and FreeBasic a breeze.


Means he also did not want to stay so long without work in pension and is back at the computer.
Did he reopen his Forum or where is he publishing?

Ok, i see he is using GitHub (Microsoft).
So if so I recommend to take a  look here.

Openai Codex for Github.
https://chatgpt.com/codex/onboarding/connections

Imagin this will just scan your files and find hidden buugs, or make changes yo tell it to do.
Included is a lot of free API Access!



José Roca


José Roca

QuoteOpenai Codex for Github.
https://chatgpt.com/codex/onboarding/connections

Imagin this will just scan your files and find hidden buugs, or make changes yo tell it to do.
Included is a lot of free API Access!

I doubt it will be of any help. Maybe it will work well with C++ (there is a lot of code to steal), but with FreeBasic they don't produce valid code. I use Copilot sometimes, inestead of Goodle, to find some information.

José Roca

Why you don't ask AI to write an user manual for O2?

Theo Gottwald

I can tell you that its in its simple form unable to write any output larger then 60 kToken, in real mostly much less. Input with Google AI-Studio is up to 1024 MToken.
So you need to code a "large output engine"" first.

However you could code a KI-Coder-Browser easily.  i saw a lot of people currently try to make browsers that can do things using calling an KI-API. I thought "Jose could do it better if he want".

You can use www.openrouter.ai free Models for testing, it will not cost anything, you just need to register and then your Browser could call the free Models that are available there and this way you could make a browser that can do many things automatically and it shoiuld contain an MCP Server so it can be used as Agent from Roocode, Cline, Cursor, Windsurf and all other KI's out there.

Such programs that can connecct to AI have a huge demand currently.
Actually there is so much demand for KI-Stuff that can be coded so easily (as KI can do most of the work for you).
Generally you an take any program "of the past" and connect it to KI using an MCP-Server or just give it an Interface to Openrouter so the user can just "say to the Texteditor" -> "Make me all functions use Register variables". And the editor will call the AI (As said there are many free AI's and also you can use Local AI's if you want privacy) - and the Editor will just do that.
Where AI currently struggles is the limited Input Context (Free AI mostly 128-56 KToken) especially the short Output-length (often 8 kToken or less).
However there are solutions and you can then alterantively use (paid) google API's they bring you 1MToken Inoput Kontext and up to 65KToken Output Kontext.

Have you ever thought of making a KI-driven version of the SED-Editor?
What could KI do in an Editor to make your life easier?
ANd remember - you can use free LI (for example using OpenRouter as Backend, also OpenAI gives you 10 MToken each Day free API Access) and if you want privacy, you can use LM-Studio and the KI will run on your private computer.

Good luck, i made a video on that:

Theo Gottwald

Thats not a problem, because for example using Mistral.ai (you can define an freebasic agent yourself)
of using Google AI-Studio, you can just use a 1 MB Textfile with all of Freebasic's Syntax and then tell him what to do with it.
I can tell you "it works" because using this system it will even code SPR-Programs and the SPR code is far from any conventional syntax.
In fact you can design an own programming language, feed the definition into AI Studio, an the KI can immediately code with it. Give it a try.

Theo Gottwald

Since he seems to have dropped all support even for his paid software there is not so much for me in there.
His Fireflyy visaul designer was a fine product - i still use it.
However it would definitely need some updates.

Theo Gottwald

We have now the good old Powerbasic (which i use because all my code is in that and i know the syntax)

then we have Charles very interestig O2 - which i corporates some genius conceptsand we have the source code so we could even change it like we want if we need.

and now we have freebasic.

And all of these incompatible with each other and that is the main problem.