Author Topic: qt about: OxyWindowClass  (Read 3390 times)

0 Members and 1 Guest are viewing this topic.

Frankolinox

  • Full Member
  • ***
  • Posts: 230
qt about: OxyWindowClass
« on: March 14, 2013, 05:52:50 AM »
following the topic from here:
http://www.oxygenbasic.org/forum/index.php?topic=630.msg5172;topicseen#msg5172

hello charles, do you know a good way how to convert.. ?

a) Instance
b) Inherit
c) INTERFACE
d) IUNKNOWN (olewrapper)
e) "property" / "property get" /"property set"
with (method get(), method set() ?)
f) create


Code: [Select]
'frankolinox experimentals for "OxyWindowClass"

FUNCTION MyWindow_RegisterClass (BYVAL hInstance AS SYS, BYVAL lpfnWndProc AS SYS) AS WORD

   LOCAL  wAtom AS sys 'WORD                     ' // Atom
   'LOCAL  wcex AS WNDCLASSEX                ' // WNDCLASSEX structure
   WndClass wc
   MSG      wm

   LOCAL  szClassName AS ASCIIZ * 256       ' // Class name
   STATIC nCount AS LONG                    ' // Counter

   ' // Default handler
   'IF lpfnWndProc = %NULL THEN lpfnWndProc = CODEPTR(MyWindowProc)
   IF lpfnWndProc = %NULL THEN lpfnWndProc = (@MyWindowProc)

   ' // Fill the WNDCLASSEX structure
   szClassName        = "OxyWindowClass:" & str(nCount)
   ''wc.cbSize        = SIZEOF(wc)
   wc.style         = CS_HREDRAW or CS_VREDRAW OR CS_DBLCLKS
   wc.lpfnWndProc   = lpfnWndProc
   wc.cbClsExtra    = 8    ' // Room to save the window and MDI client window handles
   wc.cbWndExtra    = 40   ' // Room for user data
   wc.hInstance     = hInstance
   wc.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
   wc.hbrBackground = GetStockObject WHITE_BRUSH  'COLOR_3DFACE + 1
   wc.lpszMenuName  = %NULL
   wc.lpszClassName = strptr ("OxyWindowClass") 'VARPTR(szClassName)
   'wc.hIcon=LoadIcon 0, IDI_APPLICATION
   wc.hIcon         = 0
   ''wc.hIconSm       = 0

   ' // Register the class
   'wAtom = RegisterClassEx(wcex)
   wAtom=RegisterClass (@wc)
   'RegisterClass (@wc)
   ' // Increment the class counter
   IF wAtom THEN nCount += 1

   ' // Return the atom
   FUNCTION = wAtom

END FUNCTION
' ========================================================================================

-- 'that's working already ;) --

how looks like a very simple class example on oxygen basic?

best regards, frank


Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4326
    • Oxygen Basic
Re: qt about: OxyWindowClass
« Reply #1 on: March 14, 2013, 06:36:01 AM »
Hi Frank,

PowerBasic is locked into the COM model of OOP, which makes PB objects quite complicated. I am studying the interoperability of PB objectswith o2 objects, so I will get something out on this subject fairly soon.

Simple OOP in Oxygen:
Code: [Select]


class rectangle

sys posx,posy
sys lenx,leny
sys color


method Data(sys px,py,lx,ly,rgba)
posx=px
posy=py
lenx=lx
leny=ly
color=rgba
end method

method Area() as sys
return lenx*leny
end method

method show() as string
string tab=chr(9)
string cr=chr(13,10)
return "Rectangle data:"  cr+
       "x pos  " tab posx cr+
       "y pos  " tab posy cr+
       "length " tab lenx cr+
       "height " tab leny cr+
       "color  " tab mid(hex(color,8),-8) cr+
       ""
end method

end class

rectangle rect

rect.data 100,200,30,40,0x80a080c0

print rect.show() + " Area: " + rect.area


Charles

Frankolinox

  • Full Member
  • ***
  • Posts: 230
Re: qt about: OxyWindowClass
« Reply #2 on: March 14, 2013, 08:51:36 AM »
thank you charles for this little example. I have done this example without checking your little oop example. I've started with "myWindowClass" (here: fake) and wanted only to know what's happened.

testfile:
Code: [Select]
'#include "myWindowOxy.inc"
#include "WindowOxyFake2a.inc"
'
print "all ok here for a first attempt!"

include file:
Code: [Select]
#include "inc/MinWin.inc"

' Stock Logical Objects
%WHITE_BRUSH         = 0
%LTGRAY_BRUSH        = 1
%GRAY_BRUSH          = 2
%DKGRAY_BRUSH        = 3
%BLACK_BRUSH         = 4
%NULL_BRUSH          = 5
%HOLLOW_BRUSH        = %NULL_BRUSH
%WHITE_PEN           = 6
%BLACK_PEN           = 7
%NULL_PEN            = 8
%OEM_FIXED_FONT      = 10
%ANSI_FIXED_FONT     = 11
%ANSI_VAR_FONT       = 12
%SYSTEM_FONT         = 13
%DEVICE_DEFAULT_FONT = 14
%DEFAULT_PALETTE     = 15
%SYSTEM_FIXED_FONT   = 16
%DEFAULT_GUI_FONT    = 17
%DC_BRUSH            = 18
%DC_PEN              = 19
%STOCK_LAST          = 19  

%CLR_INVALID         = &HFFFFFFFF???
' Stock Logical Objects End

DECLARE SUB InitCommonControls LIB "ComCtl32.dll" ALIAS "InitCommonControls" ()

extern

'------------------- //
class myWindowOxyFake
'------------------- //
  '
  'only for a dummy test
  '
  METHOD CREATE() as myWindow*
 
    dim m_hwnd AS SYS
    dim m_hInstance as sys
    dim m_hFont AS SYS
    dim m_hAccel AS SYS
    dim m_DPI AS LONG
    dim m_rx AS SYS
    dim m_ry AS SYS
    dim m_wAtom as sys
    DIM m_hRichEditLib as sys
    dim m_szClassName AS ASCIIZ * 260
    
    dim qty as sys

    method Create() as myWindowOxyFake*  
      m_rx = 1
      m_ry = 1
      m_DPI = 96
      ' // Instance handle
      m_hInstance = GetModuleHandle(NULL) '(BYVAL %NULL)
      ' // Default font
      m_hFont = GetStockObject(%DEFAULT_GUI_FONT)
    
    InitCommonControls

'#IF %USEOLECON = 1
      ''OC_Wininit '' OLECON.INC '' FUNCTION plus WINAPI
'#ENDIF

  'if qty<=0 then qty=1
  @method=getmemory sizeof(myWindowFake)+qty*sizeof(myWindowFake) 'extra space for array
  ?method=?this 'share method table
  end method
  '
  method delete()
  clear
  end method
  '
  method clear()
  IF m_hFont THEN DeleteObject m_hFont
#IF %USERICHEDIT = 1
      IF m_hRichEditLib THEN FreeLibrary m_hRichEditLib
#ENDIF
      IF m_szClassName <> "" THEN UnregisterClass(m_szClassName, m_hInstance)
  end method
  '
  
  '
  method show(optional sys i) as string
  ' ?
  end method

end class

print "class example part one ok"

good as I can see that my method show part can be filled know with stuff :)

more to come, questions too.

best regards, frank


Frankolinox

  • Full Member
  • ***
  • Posts: 230
Re: next idea for OxyWindowClass :)
« Reply #3 on: March 14, 2013, 12:13:27 PM »
@charles: perhaps you can use this example as basis for an oxygen sdk window class. I'm not sure if that example can help, but it's worth for a try! there's a few things missing, I know and the area where I have had problems they are marked with "?" as you can see. the code example you can compile, not more. how to show the sdk infos or how to set the "oop" I didn't know yet. But I think you know it ;) I've used the first part of jose roca's cWindow class and try to convert that one.

Code: [Select]
'
'frankolinox experimentals for "OxyWindowClass", 14.march.2013
'
'----------- test demo ---------------------------------------- //
'

#include "inc/MinWin.inc"

#lookahead ' for procedures
  s=error()
  '
  if s then
    print s
    end
  end if
  
%DEFAULT_GUI_FONT    = 17

DECLARE SUB InitCommonControls LIB "ComCtl32.dll" ALIAS "InitCommonControls" ()

DECLARE FUNCTION GetClassNameA LIB "User32.dll" ALIAS "GetClassNameA" _
    (BYVAL hwnd AS SYS, BYREF lpClassName AS ASCIIZ, BYVAL nMaxCount AS LONG) _
    AS LONG

'
'--- BEGIN > ------------------------- //
'
' > one
'
TYPE MyWindow_CREATEPARAMS
   pWindow AS SYS   ' // Reference to an instance the MyWindow class
END TYPE

'
' > two -------------------------- >
'

FUNCTION MyWindow_RegisterClass (BYVAL hInstance AS SYS, BYVAL lpfnWndProc AS SYS) AS WORD

   LOCAL  wAtom AS sys 'WORD                     ' // Atom
   'LOCAL  wcex AS WNDCLASSEX                ' // WNDCLASSEX structure
   WndClass wc
   MSG      wm

   LOCAL  szClassName AS ASCIIZ * 256       ' // Class name
   STATIC nCount AS LONG                    ' // Counter

   ' // Default handler
   'IF lpfnWndProc = %NULL THEN lpfnWndProc = CODEPTR(MyWindowProc)
   IF lpfnWndProc = %NULL THEN lpfnWndProc = (@MyWindowProc)

   ' // Fill the WNDCLASSEX structure
   szClassName        = "OxyWindowClass:" & str(nCount)
   ''wc.cbSize        = SIZEOF(wc)
   wc.style         = CS_HREDRAW or CS_VREDRAW OR CS_DBLCLKS
   wc.lpfnWndProc   = lpfnWndProc
   wc.cbClsExtra    = 8    ' // Room to save the window and MDI client window handles
   wc.cbWndExtra    = 40   ' // Room for user data
   wc.hInstance     = hInstance
   wc.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
   wc.hbrBackground = GetStockObject WHITE_BRUSH  'COLOR_3DFACE + 1
   wc.lpszMenuName  = %NULL
   wc.lpszClassName = strptr ("OxyWindowClass") 'VARPTR(szClassName)
   'wc.hIcon=LoadIcon 0, IDI_APPLICATION
   wc.hIcon         = 0
   ''wc.hIconSm       = 0

   ' // Register the class
   'wAtom = RegisterClassEx(wcex)
   wAtom=RegisterClass (@wc)
   'RegisterClass (@wc)
   ' // Increment the class counter
   IF wAtom THEN nCount += 1

   ' // Return the atom
   FUNCTION = wAtom

END FUNCTION
' ========================================================================================

extern

'
' > three -------------------------- >
'

'
'------------------- OXYGEN_SDK_WINDOW_CLASS ------------- //

'--------------------- //
 class myWindowOxyFake
'-------------------- //
  '
  'only for a dummy test
  '
  METHOD CREATE() as myWindow*
 
    dim m_hwnd AS SYS
    dim m_hInstance as sys
    dim m_hFont AS SYS
    dim m_hAccel AS SYS
    dim m_DPI AS LONG
    dim m_rx AS SYS
    dim m_ry AS SYS
    dim m_wAtom as sys
    DIM m_hRichEditLib as sys
    dim m_szClassName AS ASCIIZ * 260
    
    dim qty as sys
    ''has vector v 'dynamically allocated space at creation time
    'method Create(optional sys qty) as myWindowOxyFake*
    method Create() as myWindowOxyFake*  
      m_rx = 1
      m_ry = 1
      m_DPI = 96
      ' // Instance handle
      m_hInstance = GetModuleHandle(NULL) '(BYVAL %NULL)
      ' // Default font
      m_hFont = GetStockObject(%DEFAULT_GUI_FONT)
    
    InitCommonControls()

'#IF %USEOLECON = 1
      ''OC_Wininit '' OLECON.INC '' FUNCTION plus WINAPI
'#ENDIF

  ' works, but only a dummy test part -------------------------------------------- //
  if qty<=0 then qty=1
  @method=getmemory sizeof(myWindowOxyFake)+qty*sizeof(myWindowOxyFake) 'extra space for array
  ?method=?this 'share method table
  end method
  ' works, but only a dummy test part -------------------------------------------- //
  
  '
  method delete()
  clear
  end method
  '
  method clear()
    IF m_hFont THEN DeleteObject m_hFont
        #IF %USERICHEDIT = 1
            IF m_hRichEditLib THEN FreeLibrary m_hRichEditLib
        #ENDIF
      IF m_szClassName <> "" THEN UnregisterClass(m_szClassName, m_hInstance)
  end method
  
  ' SHOW + SHOW + SHOW + SHOW + SHOW + SHOW + SHOW
  '------ ?????????????????????????????????
  method show(optional sys i) as string
  '
  ' what to show?
  ' oxy sdk window plus buttons for example?
  '
  '------ ?????????????????????????????????
  end method
  ' SHOW + SHOW + SHOW + SHOW + SHOW + SHOW + SHOW
  
'
' > four -------------------------- >
'
 
'----------------------------------------------------- //
  METHOD buildSdk ( _ 'CreateWindow
      BYVAL hParent AS SYS, _             ' // Parent window handle
      BYVAL strTitle AS STRING, _           ' // Window caption
      BYVAL x AS LONG, _                    ' // Horizontal position
      BYVAL y AS LONG, _                    ' // Vertical position
      BYVAL nWidth AS LONG, _               ' // Window width
      BYVAL nHeight AS LONG, _              ' // Window height
      BYVAL dwStyle AS SYS, _             ' // Window style(s)
      BYVAL dwExStyle AS SYS, _           ' // Extended style
      BYVAL lpfnWndProc AS SYS _          ' // Address of the callback function
      ) AS SYS                            ' // Window handle

        dim m_hwnd AS SYS
        dim m_hInstance as sys
        dim m_hFont AS SYS
        dim m_hAccel AS SYS
        dim m_DPI AS LONG
        dim m_rx AS SYS
        dim m_ry AS SYS
        dim m_wAtom as sys
        DIM m_hRichEditLib as sys
        dim m_szClassName AS ASCIIZ * 260

      ' // Exit if the window has already been created
      IF m_hwnd THEN EXIT METHOD
      ' // Centered window
      IF x = 0 AND y = 0 THEN
         x = (GetSystemMetrics(%SM_CXSCREEN) - nWidth) \ 2
         y = (GetSystemMetrics(%SM_CYSCREEN) - nHeight) \ 2
      END IF
      ' // Register a class
      m_wAtom = MyWindow_RegisterClass(m_hInstance, lpfnWndProc)
      IF m_wAtom = 0 THEN EXIT METHOD
      ' // Create the window
      LOCAL dwClass AS SYS
      
      ' ??????????????????????????????????????????
      '------------ MAK ? --------------------- //
      ''dwClass = MAK(SYS, m_wAtom, 0) ' ???
      '------------ MAK ? --------------------- //
      ' ??????????????????????????????????????????
      
      IF dwStyle = 1 then dwStyle = %WS_OVERLAPPEDWINDOW OR %WS_CLIPCHILDREN OR %WS_CLIPSIBLINGS
      
      'IF BITS(LONG, dwStyle) = -1 THEN dwStyle = %WS_OVERLAPPEDWINDOW OR %WS_CLIPCHILDREN OR %WS_CLIPSIBLINGS
      'IF BITS(LONG, dwExStyle) = -1 THEN dwExStyle = %WS_EX_CONTROLPARENT OR %WS_EX_WINDOWEDGE
      
      LOCAL tCreateParams AS MyWindow_CREATEPARAMS
      
      ' ??????????????????????????????????????????
      '------------------------------------ // ???
      ''tCreateParams.pWindow = OBJPTR(ME)
      '------------------------------------ // ???
      '
      ' ??????????????????????????????????????????
      
      m_hwnd = CreateWindowEx(dwExStyle, BYVAL dwClass, byval strTitle, dwStyle, _
               x * m_rx, y * m_ry, nWidth * m_rx, nHeight * m_ry, hParent, %NULL, m_hInstance, tCreateParams)
      'BYCOPY strTitle '?
      
      IF m_hwnd = %NULL THEN EXIT METHOD
      
      ' // Store a pointer to the class
      
      ' ??????????????????????????????????????????
      '------------------------------------ // ???
      ''SetClassLong m_hwnd, 0, OBJPTR(ME)
      '------------------------------------ // ???
      ' ??????????????????????????????????????????
      
      ' // Retrieve the class name
      
      '--------------------------------//
      GetClassNameA(m_hwnd, m_szClassName, SIZEOF(m_szClassName))
      '--------------------------------//
      
      ' // Set the font
      SendMessage m_hwnd, %WM_SETFONT, m_hFont, %FALSE
      ' // Show the window
      IF (dwStyle AND %WS_MAXIMIZE) = %WS_MAXIMIZE THEN
         ShowWindow m_hwnd, %SW_MAXIMIZE
      'ELSEIF (dwStyle AND %WS_MINIMIZE) = %WS_MINIMIZE THEN
      '   ShowWindow m_hwnd, %SW_MINIMIZE
      
      ELSE
         ShowWindow m_hwnd, %SW_SHOW
      END IF
      ' // Update the window
      UpdateWindow m_hwnd
      
     ''--------------- // ------------- insert ????????
     ' sys bRet
     ' MSG      wm
     '
     '   do while bRet := GetMessage (@wm, 0, 0, 0)
     '       if bRet = -1 then
     '       'show an error message
     '       else
     '       TranslateMessage @wm
     '       DispatchMessage @wm
     '   end if
     ' wend
    '------------------ // --------------- insert end ?

      ' // Return the window handle
      METHOD = m_hwnd
   END METHOD
  
END CLASS
'------------------- // END OF CLASS // --------------------

'
' > five -------------------------- >
'
    dim as rect crect 'for WndProc and TimerProc

  '--------------------------------------------------------------
  function MyWindowProc ( hWnd, wMsg, wParam, lparam ) as sys callback
  '==============================================================

    static as sys hdc
    static as String txt
    static as PaintStruct Paintst
 
    '==========
    select wMsg
    '==========
        
      '--------------
      case WM_CREATE
      '=============

      GetClientRect  hWnd,&cRect

      '--------------  
      case WM_DESTROY
      '===============
          
      PostQuitMessage 0
        
      '------------
      case WM_PAINT
      '============
      'TEXT
      'http://msdn.microsoft.com/en-us/library/dd144821(v=VS.85).aspx
      'DRAWING AND PAINTING
      'http://msdn.microsoft.com/en-us/library/dd162760(v=VS.85).aspx

      GetClientRect  hWnd,&cRect
      hDC=BeginPaint hWnd,&Paintst
      
      'style
      '0x20 DT_SINGLELINE
      '0x04 DT_VCENTER
      '0x01 DT_CENTER
      '0x25

       SetBkColor   hdc,yellow
       SetTextColor hdc,red
       DrawText hDC,"Hello World!",-1,&cRect,0x25
       EndPaint hWnd,&Paintst
        
      '--------------  
      case WM_KEYDOWN
      '==============

      '============            
      Select wParam
      '============

Case 27 : SendMessage hwnd, WM_CLOSE, 0, 0      'ESCAPE
      End Select
      
      '--------        
      case else
      '========          
        function=DefWindowProc hWnd,wMsg,wParam,lParam        
    end select
  end function ' WndProc
'--------------------- END OF WndProc ----------------------- //

'
' > six -------------------------- >
'
' testing

print "ok here!"

best regards, frank

Aurel

  • Guest
Re: qt about: OxyWindowClass
« Reply #4 on: March 14, 2013, 03:06:30 PM »
Frank
I was just do some thinking and i made example which use class..
Hmm i hope that is this OOP even i am not sure at all because this looks to me like
different way of using UDT( even OOP is some sort of UDT... :-\)
to try this you must use awinh.inc because i need some api definitions and to simplify
things.Macro Default is just retval of DefWinProc...
I also think that can be possible add this class into header (include file).
here is code:
Code: [Select]
'test OOP window
include "awinh.inc"
#lookahead

CLASS cWindow
'------------------------------------------------------
Method Init()
inst = GetModuleHandle 0
wcx.style = CS_DBLCLKS |CS_OWNDC
wcx.lpfnWndProc = &WndProc
wcx.cbClsExtra =0
wcx.cbWndExtra =0
wcx.hInstance  = inst
wcx.hIcon=LoadIcon 0,IDI_APPLICATION         
wcx.hCursor=LoadCursor 0,IDC_ARROW       
wcx.hbrBackground = CreateSolidBrush(GetSysColor(15))
wcx.lpszMenuName  = ?0
wcx.lpszClassName = @"Oxygen"
RegisterClass &wcx
End Method
'-------------------------------------------------------
Method CreateWindow (string caption,sys style,Wx,Wy,Ww,Wh,wParent) as sys
sys hwnd
_hwnd = CreateWindowEx 0, wcx.lpszClassName, caption, style, Wx, Wy, Ww, Wh, wParent, 0, 0, 0
ShowWindow _hwnd, SW_SHOW
Method = _hwnd
End Method
'-------------------------------------------------------
END CLASS


'################################
' TEST
'################################
Dim w as cWindow

w.Init()
w.CreateWindow("newWindow",WS_SYSMENU,100,100,400,300,0)

Wait()




function WndProc(hWnd, wMsg, wParam, lParam ) as sys callback

select @wMsg
case WM_DESTROY
PostQuitMessage 0
end select

function = Default

end function

Aurel

  • Guest
Re: qt about: OxyWindowClass
« Reply #5 on: March 15, 2013, 06:20:39 AM »
Charles..
is my way proper way to use methods or i miss something  ::)
I never liked this OOP thing but might be useful...

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4326
    • Oxygen Basic
Re: qt about: OxyWindowClass
« Reply #6 on: March 15, 2013, 08:13:56 AM »

Sure Aurel. The class encapsulates methods, and you can also add variables (so-called properties) which are visible to all the methods, but invisible to anything outside an object defined by this class. It keeps the global space of a program clean, and reduces the need to invent new names for everything.

A class is basically a combo of UDT and functions. Unfortunately developers cannot resist adding new bells and whistles to this simple concept. :)

Charles

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4326
    • Oxygen Basic
Re: qt about: OxyWindowClass
« Reply #7 on: March 15, 2013, 08:27:13 AM »
Frank,

What you can do in a class for child windows is to store all the metrics, such as state,id,hwnd,hdc, clientRect and parent hwnd. Then all the methods you create inside the class have access to these variables.

John

  • Hero Member
  • *****
  • Posts: 3683
Re: qt about: OxyWindowClass
« Reply #8 on: March 15, 2013, 08:47:14 AM »
Quote
A class is basically a combo of UDT and functions. Unfortunately developers cannot resist adding new bells and whistles to this simple concept.

With ScriptBasic's flexibility and dynamic aspect of its arrays, (associative and index) I put a proof of concept together of a OOP like programming style with SB. Here is my attempt I did some time ago.


Frankolinox

  • Full Member
  • ***
  • Posts: 230
Re: qt about: OxyWindowClass
« Reply #9 on: March 15, 2013, 09:33:32 AM »
perhaps my way for converting from powerbasic to oxygen is too heavy or nonsense. my example is nearly ready, but I have headache through that work at the moment and it's still like mountain climbing ;)

here's an example (but the button method is missing something!) after aurel's concept it looks very simple and I suppose a good way.
I've built in "hwnd" in method's for windows and buttons because I thought that this can visualize sdk window plus button.

the button method is missing something for displaying..

Code: [Select]
'test OOP window
include "awinh.inc"
#lookahead

%Buttoni=1001

%BS_PUSHBUTTON      = &H00000000???
%BS_DEFPUSHBUTTON   = &H00000001???
%BS_DEFAULT         = %BS_DEFPUSHBUTTON
%BS_FLAT            = &H00008000???

'------------------------------------------------------
CLASS cWindow
'------------------------------------------------------
Method Init()
inst = GetModuleHandle 0
wcx.style = CS_DBLCLKS |CS_OWNDC
wcx.lpfnWndProc = &WndProc
wcx.cbClsExtra =0
wcx.cbWndExtra =0
wcx.hInstance  = inst
wcx.hIcon=LoadIcon 0,IDI_APPLICATION          
wcx.hCursor=LoadCursor 0,IDC_ARROW      
wcx.hbrBackground = CreateSolidBrush(GetSysColor(15))
wcx.lpszMenuName  = ?0
wcx.lpszClassName = @"Oxygen"
RegisterClass &wcx
End Method

'-------------------------------------------------------
Method Control()
'? control in general for buttons, edit, tab etcpp
END METHOD

'------------------------------------------------------- //
Method CreateWindow (sys hwnd, string caption,sys style,Wx,Wy,Ww,Wh,wParent) as sys
sys inst,myButton
_hwnd = CreateWindowEx 0, wcx.lpszClassName, caption, style, Wx, Wy, Ww, Wh, wParent, 0, 0, 0
    
     'myButton =  CreateWindowEx(0, _                                            
     '                            "Button", _                                        
     '                            "push me!", _                                      
     '                            %WS_CHILD OR %WS_VISIBLE OR _                        
     '                            %BS_PUSHBUTTON OR %BS_FLAT, _            
     '                            22, 20, _                              
     '                            80, 24, _                              
     '                            _hWnd, %Buttoni, _  ' that's working for a test but only with "_hwnd"
     '                            inst, 0)                              


ShowWindow _hwnd, SW_SHOW
Method = _hwnd
End Method

'-------------------------------------------------------
METHOD AddButton (sys hwnd, string caption, title, sys style,wx,wy,ww,wh,wparent,id,inst,0) as sys
    sys myButton,hFont
    _myButton=CreateWindowEx(0, _                                            
                                 "Button", _                                        
                                 ""+title, _ '
                                 style+%WS_CHILD OR %WS_VISIBLE OR _                        
                                 %BS_PUSHBUTTON OR %BS_FLAT, _            
                                 wx, wy, _                              
                                 ww, wh, _                              
                                 hwnd, %Buttoni, _  'hWnd
                                 inst, 0)                              
    
      'SendMessage myButton, WM_SETFONT, hFont, 1 '%TRUE
METHOD = _myButton
END METHOD

END CLASS

'################################
' TEST
'################################

Dim w as cWindow
sys hwnd,inst,wParent
w.Init()
w.CreateWindow(hwnd, "newWindow",WS_SYSMENU,100,100,400,300,hwnd)
w.Addbutton(hwnd, "button","test",WS_SYSMENU OR WS_CHILD OR WS_VISIBLE,20,20,120,40,wParent,%Buttoni,inst,0)
Wait()
function WndProc(hWnd, wMsg, wParam, lParam ) as sys callback
select @wMsg
        case WM_DESTROY
        PostQuitMessage 0
end select
function = Default
end function


questions:

a) "_hwnd" what's that for a construct ? never seen before!

b) is there's a need for making a "control" class for buttons, edit, scintilla, toolbar and so on .. ?

thanks for infos charles about methods and the link jrs, after working with this easy class like above way I will understand more about that one. I thought the win api stuff can made much easier and the exe file thinner and working faster with class type, that's correct ?

Quote
A class is basically a combo of UDT and functions. Unfortunately developers cannot resist adding new bells and whistles to this simple concept. Smiley

I second that one!


best regards, frank

Aurel

  • Guest
Re: qt about: OxyWindowClass
« Reply #10 on: March 15, 2013, 11:03:04 AM »
Quote
A class is basically a combo of UDT and functions. Unfortunately developers cannot resist adding new bells and whistles to this simple concept.

That's what i want to know.
Thanks Charles on simple to understand explanation and the way how this OOP work in Oxygen
is excellent ..if you ask me... :)

Yes Frank..it looks that my example work fine and in first place i don't know that will be easy... ;D
' _hwnd ' is a just name of returned hendler that is different from 'hwnd'.
And Frank , on the same way as is window created you can create any control...
look into awinh.inc  and you will find how controls are created , of course you can
change the names of functions and add is to the method,
then after is window created add control , and don't forget add parent parameter on the
end of method define ( same as in functions) , and of course create control with WS_CHILD
style that belong to main window.
HUH...to much to typing....

BUT still we need to somehow simplify WndProc...that things makes me crazy all the time.
Do we can put adress of function or method into CreateWindow() that point to our new
function or procedure ???
I have search many times trough C/C++ examples and i still don't find proper way
how to do that in oxygen ...
Any ideas again....???????

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4326
    • Oxygen Basic
Re: qt about: OxyWindowClass
« Reply #11 on: March 16, 2013, 07:00:40 AM »
Here a basic example of OOPifying Child window controls.

It belongs in examples/GUI


X

Frankolinox

  • Full Member
  • ***
  • Posts: 230
Re: qt about: OxyWindowClass
« Reply #12 on: March 16, 2013, 09:30:29 AM »
many thanks for your little example charles, I will check it after I am at home again on my pc :-)

@aurel: I know since over one and a half year how to make controls (createWindowEx) for oxygen. I meant how to store "class controls" in that way, that they are working correct. I show this demo in my last example but the button class couldn't be shown.

frank

Aurel

  • Guest
Re: qt about: OxyWindowClass
« Reply #13 on: March 16, 2013, 11:37:52 AM »
I will show you soon...
Ok i do this ...
Code: [Select]
Method Control(sys wParent,string ClassName,sys style,Wx,Wy,Ww,Wh,string _text) as sys
sys cWnd
cWnd = CreateWindowEx 0, ClassName, _text, style, Wx, Wy, Ww, Wh, wParent, 0, 0, 0
ShowWindow cWnd, SW_SHOW
Method = cWnd
End Method
'-------------------------------------------------------
END CLASS


'################################
' TEST
'################################
Dim w as cWindow
Dim hw as Int

w.Init()
hw=w.CreateWindow("newWindow",WS_SYSMENU,100,100,400,300,0)
'SetButton (w,10,10,100,24,"buto",0,0,100)
w.Control(hw,"BUTTON",0x50000000,10,10,80,24,"NewButton")
« Last Edit: March 16, 2013, 01:20:29 PM by Aurel »

Aurel

  • Sr. Member
  • ****
  • Posts: 489
Re: qt about: OxyWindowClass
« Reply #14 on: May 17, 2020, 08:30:08 AM »
Strange...i just tried this old OOP code and compile oK
but program just stuck in memory and not execute:

Code: [Select]
'test OOP window
$ filename "cWindow.exe"
include "rtl32.inc"
include "awinh.inc"
#lookahead

CLASS cWindow
'------------------------------------------------------
Method Init()
int inst = GetModuleHandle 0
wcx.style = CS_DBLCLKS |CS_OWNDC
wcx.lpfnWndProc = &WndProc
wcx.cbClsExtra =0
wcx.cbWndExtra =0
wcx.hInstance  = inst
wcx.hIcon=LoadIcon 0,IDI_APPLICATION         
wcx.hCursor=LoadCursor 0,IDC_ARROW       
wcx.hbrBackground = CreateSolidBrush(GetSysColor(15))
wcx.lpszMenuName  = ?0
wcx.lpszClassName = strptr "Oxygen"
RegisterClass &wcx
End Method
'-------------------------------------------------------
Method CreateWindow (string caption,sys style,Wx,Wy,Ww,Wh,wParent) as sys
sys _hwnd
_hwnd = CreateWindowEx 0, wcx.lpszClassName, caption, style, Wx, Wy, Ww, Wh, wParent, 0, 0, 0
ShowWindow _hwnd, SW_SHOW
Method = _hwnd
End Method
'-------------------------------------------------------
END CLASS


'################################
' TEST
'################################
Dim w as cWindow

w.Init()
w.CreateWindow("newWindow",WS_SYSMENU,100,100,400,300,0)

Wait()




function WndProc(sys hWnd, wMsg, wParam, lParam ) as sys callback

select @wMsg
case WM_DESTROY
PostQuitMessage 0
end select

function = Default

end function
my site:BLOG and FORUM
https://aurelsoft.ucoz.com/