PlanetSquires Forums

Support Forums => José Roca Software => Topic started by: José Roca on November 14, 2025, 11:37:56 PM

Title: AfxNova progress
Post by: José Roca on November 14, 2025, 11:37:56 PM
I have done much work with GDI+.

GDI+ Flat API

As the FreeBasic headers for GID+ are a mess, with different headers for 32 and 64 bit, with many naming conflicts and import libraries partially broken, I have writen my own headers: AfxGdiPlus.bi.

All the 600+ functions are documented here:
https://github.com/JoseRoca/AfxNova/tree/main/docs/Graphics%20/GdiPlus%20Flat%20%20Api

And there are hundreds of examples here:
https://github.com/JoseRoca/AfxNova/tree/main/Examples/GdiPlus%20Flat%20API

GDI+ classes

These classes replicate the C++ ones.

hey are documented here:
https://github.com/JoseRoca/AfxNova/tree/main/docs/Graphics%20/GdiPlus%20Classes

And there are hundreds of examples here:
https://github.com/JoseRoca/AfxNova/tree/main/Examples/GdiPlus%20Classes
Title: Re: AfxNova progress
Post by: José Roca on November 14, 2025, 11:46:43 PM
Currently, I'm working in a class, called CWebView2, that allows to embed the WebView2 control in a FreeBasic application.

he main part is already implemented and working. There is still much work to do to write the many event's classes.

With this short code you can create an instance of WebView2 and navigate to a site.

FUNCTION wWinMain (BYVAL hInstance AS HINSTANCE, _
                   BYVAL hPrevInstance AS HINSTANCE, _
                   BYVAL pwszCmdLine AS WSTRING PTR, _
                   BYVAL nCmdShow AS LONG) AS LONG

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

   DIM pWindow AS CWindow
   DIM hWin AS HWND = pWindow.Create(NULL, "WebView2", @WndProc)
   pWindow.SetClientSize(1050, 500)
   pWindow.Center
'   DIM pWebView2 AS CWebView2 = hWin
   DIM pWebView2 AS CWebView2 = CWebView2(hWin, ExePath)
   IF pWebView2.IsReady(5000) THEN
      ' // Navigate to the web page
      pWebView2.Navigate("https://www.planetsquires.com/protect/forum/index.php")
   ELSE
      ' // Timeout
   END IF

   ' // Dispatch Windows messages
   FUNCTION = pWindow.DoEvents(nCmdShow)

END FUNCTION
Title: Re: AfxNova progress
Post by: Paul Squires on November 15, 2025, 09:25:52 AM
Incredible work, thanks a million for this, I am amazed at the amount of work you've put into GDI+ and WebView2
Title: Re: AfxNova progress
Post by: José Roca on November 15, 2025, 03:48:01 PM
It is needed to deal with the high resolution monitors. The old WebBrowser control is obsolete and we need WebView2. And regading GDI+, I have found solutions to make graphics DPI aware. And DWSTRING provides optional support to fix broken surrogate pairs and allows to use utf-8. I do the same trick that Windows uses with the "A" functions: convert utf-8 to utf-16 on input, allowing to use all the string functions and operators, and optionally convert to utf-8 on output. It only requires a constructor and two properties.

Afx needed a modernization.
Title: Re: AfxNova progress
Post by: José Roca on November 17, 2025, 05:22:15 AM
The events are solved. I will provide overridable classes that the user can override liks ethis:

' ########################################################################################
' CWebView2NavigationCompletedEventHandlerImpl class
' Implementation of the ICoreWebView2NavigationCompletedEventHandler callback interface.
' ########################################################################################
TYPE CWebView2NavigationCompletedEventHandlerImpl EXTENDS CWebView2NavigationCompletedEventHandler

   ' ICoreWebView2NavigationCompletedEventHandler
   DECLARE FUNCTION Invoke (BYVAL sender AS Afx_ICoreWebView2 PTR, BYVAL args AS Afx_ICoreWebView2NavigationCompletedEventArgs PTR) AS HRESULT

   DECLARE CONSTRUCTOR (BYVAL pWebView2 AS CWebView2 PTR)
   DECLARE DESTRUCTOR

   m_pWebView2 AS CWebView2 PTR
   m_token AS EventRegistrationToken

END TYPE
' ########################################################################################

' ========================================================================================
CONSTRUCTOR CWebView2NavigationCompletedEventHandlerImpl (BYVAL pWebView2 AS CWebView2 PTR)
   CWV2_DP("")
   IF pWebView2 THEN
      m_pWebView2 = pWebView2
      pWebView2->AddNavigationCompleted(cast(ANY PTR, @this), @m_token)
   END IF
END CONSTRUCTOR
' ========================================================================================
' ========================================================================================
DESTRUCTOR CWebView2NavigationCompletedEventHandlerImpl
   CWV2_DP("")
   IF m_pWebView2 THEN m_pWebView2->RemoveNavigationCompleted(m_token)
END DESTRUCTOR
' ========================================================================================
' ========================================================================================
FUNCTION CWebView2NavigationCompletedEventHandlerImpl.Invoke (BYVAL sender AS Afx_ICoreWebView2 PTR, BYVAL args AS Afx_ICoreWebView2NavigationCompletedEventArgs PTR) AS HRESULT
   CWV2_DP("*** Navigation completed ***")
   RETURN S_OK
END FUNCTION
' ========================================================================================

And will set as follows:

DIM pEnv AS CWebView2NavigationCompletedEventHandlerImpl PTR
pEnv = NEW CWebView2NavigationCompletedEventHandlerImpl(@pWebView2)

Now I only have to implement classes for all the events (there are many) and we will have a great control ready to use.