AfxNova progress

Started by José Roca, November 14, 2025, 11:37:56 PM

Previous topic - Next topic

José Roca

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

José Roca

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

Paul Squires

Incredible work, thanks a million for this, I am amazed at the amount of work you've put into GDI+ and WebView2
Paul Squires
PlanetSquires Software

José Roca

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.

José Roca

#4
The events are solved. I will provide overridable classes that the user can override like this:

' ########################################################################################
' 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 pEvt AS CWebView2NavigationCompletedEventHandlerImpl PTR
pEvt = 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.

José Roca

#5
All the essential is done and tested. What remains is to wrap the latest interfaces and events, most of which aren't essential unless you intend to write a full web browser. What we have is a very useful control that can do all that a web browser can do: maps, charts, images, graphics, videos, audio, web pages, etc. It can be embedded in any window, the most suitable being a label control.

The attached capture shows a WebView control embedded into a label displaying a Goodle map.

José Roca

#6
I have been playing with dark mode. Here you will find templates for most of the standard Windows controls except Menus: https://github.com/JoseRoca/AfxNova/tree/main/Templates/SDK%20Templates

For easy identification, these examples have "_DarkMode" as the suffix.

José Roca

#7
I also have started to post WebView2 examples:

https://github.com/JoseRoca/AfxNova/tree/main/Examples/CWebView2

The WebView2Loader.dll that I'm using is them one for 64 bit. It you want to try 32 bit, rename WebView2Loader_32.dll as WebView2Loader.dll.

A good place where to find examples that can be adapted to work with WebView2 is WC3 Schools: https://www.w3schools.com/html/default.asp

Johan Klassen


hajubu

HI,jose

!great work!
- dark modes are fine
- just tested the webview2 samples - worked fine.  Thank's for your effort done.
----hajubu---

Just a small hint:
samples (*.bas) in utf16LE like the both "GoogleCircularChart.bas"  and "Chartjs_CircularChart.bas"
are getting mixed up , when you use the the full zip download.
' ########################################################################################
�✀ 䴀椀挀爀漀猀漀昀琀 圀椀渀搀漀眀猀ഀഀ
' File: Google circular chart.bas

Download as single raw file selection keeps the UTF16LE correct format.
' ########################################################################################
' Microsoft Windows
' File: Google circular chart.bas

Is there a real need to use UTF16LE instead of UTF8 ?
(mho : Tiko is save for UTF16 and UTF8 , which is not true for the zips in Gith.)



José Roca

Thanks very much. I have reuploaded them. There is not need to use UTF-16, except that I tried to see if it worked with these examples. I used Ελιές, (Olives in Greek). It worked, but forgot to set Tiko back to Ansi. Sorry for the inconvenience.

docroger

Hello José,

With last version afxnova, i cant compile cw_menu_icon_01... : compiling resource failed.

Seems icons are missing in resources dir (into templates).

Am i missing something ?

hajubu

#12
hi  docroger
hi jose

yes here some icons missing - even some are doubled in DDT_Templates resources.
my fast analysis for the several SDK CW_xxx.rc files references for the SDK_Templates, especially for the menu_icon_01
home_32,home_64, save_32, save_64

just in case ...
here a shared file with the missing icons inside:

sdk_resources_save+home.7z

José Roca

#13
Yes, some icons were missing. I have reuploaded them.

Seems that I uploaded them to the Resources folder of the DDT templates and forgot to do the same in the Resources folder of the SK Templates. I'm sorry. I've been so busy with GDI++, WebView and Dark Mode that I'm being a bit forgetful.

José Roca

Microsoft is developing WebView2 very rapidly. There are 27 new interfaces and 18 new events in ICoreWebView (unless they've implemented more since my last check). Every time they add one or two methods, they implement a new interface, which inherits from the existing ones. The reason there are so many event interfaces is that WebView2 works asynchronously, so you generally don't get the result directly when you call a method, but rather in the event callbacks. Most of the new methods aren't essential, but rather refinements.