Message Control not working on a Type

Windows specific questions.
Post Reply
Tolo68
Posts: 105
Joined: Mar 30, 2020 18:18
Location: Spain

Message Control not working on a Type

Post by Tolo68 »

Hello everyone, I have the following code, but the function of processing messages in a TYPE does not go well

Code: Select all


#Include Once "windows.bi"
#include "win\commctrl.bi"

Dim As WNDCLASSEX wc
Dim Shared As String NameClass
NameClass="WinClass"
Dim As HINSTANCE Hinst=GetModuleHandle(0)

Dim Shared msg As MSG

Type ApiWindow

  As Integer Var1
  As Integer Var2
  
  Declare Sub Create(WinName As string, Title As string)
  Declare Function CtrlMsgFunc(WinHwnd As hwnd,uMsg as UInteger,wParam as wParam,lParam as lParam) as LRESULT
  
End Type

Sub ApiWindow.Create(WinName As string, Title As string)

    CreateWindowEx(0,WinName,Title,_
        WS_VISIBLE Or WS_OVERLAPPEDWINDOW, 10, 10, 320, 240, 0, 0, getmodulehandle(0),0)
    
End Sub

Function ApiWindow.CtrlMsgFunc(WinHwnd As hwnd, Msg as UInteger,wParam as wParam,lParam as lParam) as LRESULT

  Select Case Msg
  
      Case WM_CREATE
          
      Case WM_DESTROY
          PostQuitMessage(0)
 
    End Select
    
    return DefWindowProc(WinHwnd,Msg,wparam,lparam)

End function

Function wndproc(hwnd As HWND, msg As UInteger, wparam As WPARAM, lparam As LPARAM) As Integer
    
  Select Case msg
    
      Case WM_CREATE
            
      Case WM_DESTROY
          PostQuitMessage(0)
            
    End Select
    
    Return DefWindowProc(hwnd,msg,wparam,lparam)
    
End Function

With wc
    .cbSize=SizeOf(WNDCLASSEX)
    .style=CS_HREDRAW Or CS_VREDRAW
    '''.lpfnWndProc=@wndproc    ' < ================= This Work
    .lpfnWndProc = @ApiWindow.CtrlMsgFunc    ' < ================= This no Work, does not show the windows, only the console 
    .hInstance=Hinst
    .hIcon=LoadIcon(0,IDI_QUESTION)
    .hCursor=LoadCursor(0,IDC_ARROW)
    .hbrBackground=Cast(HBRUSH,COLOR_WINDOW)
    .lpszClassName=StrPtr(NameClass)
    .hIconSm=.hIcon
End With

Sub AppRun
  While GetMessage(@msg,0,0,0)
      TranslateMessage(@msg)
      DispatchMessage(@msg)
  Wend  
End Sub

' --- Start Program ---

Dim Win1 As ApiWindow
win1.Create(NameClass, "My Window")

apprun



Tolo68
Posts: 105
Joined: Mar 30, 2020 18:18
Location: Spain

Re: Message Control not working on a Type

Post by Tolo68 »

Hello to the whole forum
I was already able to solve it based on other examples with Static...

Declare Static Function CtrlMsgFunc(...)
nastasa eodor
Posts: 182
Joined: Dec 18, 2018 16:37
Location: Germany, Hessdorf
Contact:

Re: Message Control not working on a Type

Post by nastasa eodor »

Tolo68 wrote: Aug 22, 2023 14:21 Hello to the whole forum
I was already able to solve it based on other examples with Static...

Declare Static Function CtrlMsgFunc(...)
don't say....
Post Reply