PlanetSquires Forums

Support Forums => WinFBX - Windows Framework for FreeBASIC => Topic started by: jermy on February 17, 2021, 02:47:35 PM

Title: error 265: SetWindowSubclass
Post by: jermy on February 17, 2021, 02:47:35 PM
why i get error 265 when i try to subclass with pWindow.AddControl ?

error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'pWindow.AddControl(_'

Code: [Select]
Sub CreateControlEx(Byval hwnd As HWND)


  DIM pWindow AS CWindow PTR = AfxCWindowOwnerPtr(hwnd)
 ' IF pWindow THEN pWindow->AddControl("Button", hwnd, IDCANCEL, "&Close", 250, 150, 75, 23) 'works fine

   pWindow.AddControl(_
                                      "Button", _
                                      hwnd , _
                                      IDCANCEL, _
                                      "Click me", _
                                      100, _
                                      100, _
                                      120, _
                                      100, _
                                      -1, _
                                      -1, _
                                      0, _
                                      CAST(SUBCLASSPROC, @ButtonProc), _
                                      IDCANCEL, _
                                      CAST(DWORD_PTR, @pWindow))

' works fine
'     Dim hCtle   As HWND
'           ID = ID + 1
'           hCtle = CreateWindow("BUTTON", "Button2", BS_TEXT or WS_CHILD or WS_VISIBLE, 100, 100, 120, 100, hWnd, Cast(HMENU,ID), hInstance, NULL)
'           SetWindowSubclass(hCtle, @ButtonProc, id, 0)

End Sub

Title: Re: error 265: SetWindowSubclass
Post by: jermy on February 17, 2021, 03:01:21 PM
oh hell, i already found it

Code: [Select]

  DIM pWindow AS CWindow PTR = AfxCWindowOwnerPtr(hwnd)

IF pWindow THEN pWindow-> AddControl(_
                                      "Button", _
                                      hwnd , _
                                      IDCANCEL, _
                                      "Click me", _
                                      100, _
                                      100, _
                                      120, _
                                      100, _
                                      -1, _
                                      -1, _
                                      0, _
                                      CAST(SUBCLASSPROC, @ButtonProc), _
                                      IDCANCEL, _
                                      CAST(DWORD_PTR, @pWindow))


The dot notation is only used for variables, not pointers. With a pointer we need to use the "->" symbol.
Title: Re: error 265: SetWindowSubclass
Post by: Josť Roca on February 17, 2021, 03:02:24 PM
If you declare pWindow as CWindow PTR you have to use the -> syntax (pWindow->AddControl) , not the dotted syntax (pWindow.AddControl). Also you have to use CAST(DWORD_PTR, pWindow) instead of CAST(DWORD_PTR, @pWindow).
Title: Re: error 265: SetWindowSubclass
Post by: jermy on February 17, 2021, 03:37:27 PM
Thanx Josť

how do I get the button's hwnd back?
Code: [Select]
  DIM pWindow AS CWindow PTR = AfxCWindowOwnerPtr(hwnd)
           ID = ID + 1
         pWindow-> AddControl("Button", hwnd , ID, "Click me", 100, 100, 120, 100, -1, -1, 0,  CAST(SUBCLASSPROC, @ButtonProc), ID, CAST(DWORD_PTR, pWindow))
Title: Re: error 265: SetWindowSubclass
Post by: jermy on February 17, 2021, 04:02:29 PM
The best I can think of

Code: [Select]
? GetDlgItem( hwnd, ID)
Title: Re: error 265: SetWindowSubclass
Post by: Josť Roca on February 17, 2021, 04:03:28 PM
<hwnd of the control> = GetDlgItem(<hwnd of the form>, <identifier of the control>)

See: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdlgitem