AfxNova: AddControl subclass

Started by Paul Squires, August 07, 2025, 09:10:24 AM

Previous topic - Next topic

Paul Squires

I see that at the pWindow level that I can call SetControlSubclass to subclass a child control (one of your examples actually does this), however, the .AddControl() method says that it allows you to specify a control callback when the control is created (similar to how WinAfx did it).

Did you simply forget to add a call to one of your SetControlSubclass() functions at the end of AddControl if a control callback was specified?

Paul Squires
PlanetSquires Software

Paul Squires

Just to clarify, I am okay with you removing the subclass parameters from the AddControl() method altogether. I would then just use the SetControlSubclass call after the control is created.

Just using the AddControl method (the WinAfx way):

    dim as HWND hPopupListBox = _
        pWindow->AddControl("LISTBOX", , IDC_MENU_LISTBOX, "", 0, 0, 0, 0, _
        WS_CHILD or WS_TABSTOP or LBS_NOINTEGRALHEIGHT or _
        LBS_OWNERDRAWFIXED or LBS_HASSTRINGS or LBS_NOTIFY, WS_EX_LEFT or WS_EX_RIGHTSCROLLBAR, _
        cast(LONG_PTR, @pWindow), cast(WNDPROC, @frmPopupMenu_SubclassProc) )

The newer way, which I actually kind of like because it makes the calls to AddControl a little smaller:

    dim as HWND hPopupListBox = _
        pWindow->AddControl("LISTBOX", , IDC_MENU_LISTBOX, "", 0, 0, 0, 0, _
        WS_CHILD or WS_TABSTOP or LBS_NOINTEGRALHEIGHT or _
        LBS_OWNERDRAWFIXED or LBS_HASSTRINGS or LBS_NOTIFY, WS_EX_LEFT or WS_EX_RIGHTSCROLLBAR )
 
  pWindow->SetControlSubclass( hPopupListBox, @frmPopupMenu_SubclassProc, IDC_MENU_LISTBOX, @pWindow)

So, whichever approach (or both) that you decide on then I'm okay with it.
Paul Squires
PlanetSquires Software

José Roca

#2
When I first added it to Afx was because everybody was using the old subclassing style, using a global to keep the old address. I avoided the use of a global by setting that address as a property. Then it came SetWindowSubclass, that offers many advantages and you don't need to use a global or set a property. The pCallback parameter is a place holder to try to replicate the CALL callback option used by DDT to set a callback procedure where the WM_COMMAND and WM_NOTIFY messages will be sent. Currently isn't used for anything. I still don't know how I will do it, bacause then somebody will ask if he can't choose only command messages, notify messages of both. If I have to send them separately, I will need two callback pointers, one for command messages and another for notify messages. If you want to receive both kind of messages in the same callback, set both pCallback1 and pCallback2 to the same address.

José Roca

One of the latest additions has been CTabPage. With it you can build a tabbed interface with individual CWindows in each page. Much better than the old MDI system, that has been deprecated and totally abandoned, besides being much more difficult to manage.

José Roca

#4
I have collected the information to work with WebView2. There is a problem: unlike the WebBroser control, there is not a DOM model to wotk with the html pages. The only way to wotk with them is using JScript and the now omnipresent JSon. I would need a JSon class that works with FreeBasic and use Unicode.