Author Topic: Custom Controls in OxygenBasic  (Read 6543 times)

0 Members and 1 Guest are viewing this topic.

Aurel

  • Sr. Member
  • ****
  • Posts: 443
Re: Custom Controls in OxygenBasic
« Reply #15 on: November 11, 2018, 02:31:26 PM »
OH man...
Stupid chromium based browser refuse to open http linked file..geee
I can with my old KMeleon  :D
work...
my site:BLOG and FORUM
https://aurelsoft.ucoz.com/

Aurel

  • Sr. Member
  • ****
  • Posts: 443
Re: Custom Controls in OxygenBasic
« Reply #16 on: November 11, 2018, 02:42:22 PM »
Hmmm this control is really nice and fast but require lot of work  ::)
my site:BLOG and FORUM
https://aurelsoft.ucoz.com/

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4276
    • Oxygen Basic
Re: Custom Controls in OxygenBasic
« Reply #17 on: November 12, 2018, 07:48:51 PM »

Many thanks, Roland :)

Is it safe to use this dialogs.inc with previous examples (September 2018) ?

Arnold

  • Hero Member
  • *****
  • Posts: 941
Re: Custom Controls in OxygenBasic
« Reply #18 on: November 13, 2018, 04:14:32 AM »
Hi Charles,

actually I intended to use the same file (of September 2018). I noticed that I have added the line 234:

  int e = int(title) : if e != 0 or title=0 then mbox "Warning: title in Dialog probably not a string"

which should give a warning if using wrong parameters, but I am not sure if this will really help.
« Last Edit: November 13, 2018, 08:26:54 AM by Arnold »

Arnold

  • Hero Member
  • *****
  • Posts: 941
Re: Custom Controls in OxygenBasic
« Reply #19 on: November 13, 2018, 04:19:35 AM »
Hello,

this is another interesting example of a customized control which I found in this tutorial by Martin Mitáš:

Custom Controls in Win32 API
https://www.codeproject.com/Articles/559385/Custom-Controls-in-Win32-API-The-Basics

The demo is the second example of the tutorial demonstrating double buffering. It uses a slightly different approach. I think if anyone is willing to examine the examples shown in my first message, the replies 8-11 and this example, and is willing to work through the mentioned tutorial (the complete set of course), he/she will be able to understand, create and use own customized controls, independent of the used programming language. I myself am happy that the Internet is such a great source of information these days, and I am grateful that there are people who share their knowledge.

Roland

Code: (o2) [Select]
'Custom Control demonstrating the double buffering
'https://www.codeproject.com/Articles/617212/Custom-Controls-in-Win32-API-The-Painting

$ filename "dblbuf.exe"

'uses rtl32
'uses rtl64

uses winutil


% DT_CENTER=1
% DT_VCENTER=4
% DT_SINGLELINE=32
% SWP_NOZORDER=4
% GCL_HBRBACKGROUND = -10
% SRCCOPY=0xCC0020
% WM_NCCREATE=129
% WM_NCDESTROY=130
% WM_PRINTCLIENT=792
% WM_STYLECHANGED=125
% SIZE_RESTORED=0
% SIZE_MAXIMIZED=2


function RGB(int r, g, b) as int
    return (r + g*256 + b*65536)
end Function


'=======================
'MAIN CODE
'=======================

dim nCmdline as asciiz ptr, hInstance as sys
&nCmdline = GetCommandLine
hInstance = GetModuleHandle(0)

MainWindow 350,250,WS_OVERLAPPEDWINDOW

'-----------------------------------------------------------------------------

' Window class
% CUSTOM_WC = "CustomControl"

/* Style to request using double buffering. */
% XXS_DOUBLEBUFFER   0x0001

% CUSTOM_ID     100
% MARGIN          7


% CELLSIZE        48
% DARKCOLOR       RGB(0,47,127)
% LIGHTCOLOR      RGB(241,179,0)


type CustomData
    sys   hwnd
    dword style
    sys   hbrLight
    sys   hbrDark
end type

'Register the window class
sub CustomRegister()
    WNDCLASSEX wc

    ' Note we do not use CS_HREDRAW and CS_VREDRAW.
    ' This means when the control is resized, WM_SIZE (as handled by DefWindowProc())
    ' invalidates only the newly uncovered area.
    ' With those class styles, it would invalidate complete client rectangle.
    wc.cbSize        = sizeof(WNDCLASSEX)
    wc.lpszClassName = &CUSTOM_WC           'strptr "CustomControl"
    wc.style         = CS_GLOBALCLASS   
    wc.lpfnWndProc   = @CustomProc
    wc.cbWndExtra    = sizeof(sys) 'pointer to CustomData   
    wc.hCursor       = LoadCursor(null, IDC_ARROW)
   
    if RegisterClassEx(&wc) = 0 then mbox "Error: Cannot Register CustomControl"
end sub

'Unregister the window class
sub CustomUnregister()
   if UnregisterClass(CUSTOM_WC, null) = 0 then mbox "Error: Cannot Unregister CustomControl"
end sub


function WndProc(sys hwnd, uint uMsg, sys wParam, lParam) as sys callback
    static sys hwndCustom
   
    select uMsg

        case WM_CREATE
           SetWindowText(hwnd, "Double Buffering Example")

           CustomRegister()       
           hwndCustom = CreateWindowEx(0,CUSTOM_WC, null, WS_CHILD or WS_VISIBLE or 0,
                                 0, 0, 0, 0, hwnd, CUSTOM_ID, hInstance, null)
           if hwndCustom = 0 then mbox "Error: Cannot create hwndCustom"
       
        case WM_SIZE
           if wParam = SIZE_MAXIMIZED or wParam = SIZE_RESTORED then
             word cx = loword(lParam)
             word cy = hiword(lParam)
             SetWindowPos(hwndCustom, null, MARGIN, MARGIN,
                         (cx-2*MARGIN), (cy-2*MARGIN), SWP_NOZORDER)
           end if

        case WM_CLOSE
           DestroyWindow(hwnd)

        case WM_DESTROY
           PostQuitMessage(0)
                   
        case else
           return DefWindowProc(hwnd, uMsg, wParam, lParam)

    end select
   
end function

sub CustomPaint(sys *pDat, sys hDC, sys *rcDirt, bool bErase)
    int x, y
    RECT r
    sys hBrush
   
    RECT rcDirty at &rcDirt
    CustomData pData at pDat
   
    ' Note we paint only the cells overlaping with the dirty rectangle.
    for y = (rcDirty.top / CELLSIZE) to (rcDirty.bottom / CELLSIZE)
        for x = (rcDirty.left / CELLSIZE) to (rcDirty.right / CELLSIZE)
            if mod((x+y),2)=0 then hBrush=pData.hbrLight else hBrush=pData.hbrDark
            SetRect(&r, x * CELLSIZE, y * CELLSIZE, (x+1) * CELLSIZE, (y+1) * CELLSIZE)
            FillRect(hDC, &r, hBrush)
        next x
    next y
end sub

sub CustomDoubleBuffer(sys *pDat, sys *pPaintStruc)   
    CustomData pData : &pData = &pDat
    PAINTSTRUCT pPaintStruct : &pPaintStruct = &pPaintStruc

    int cx = pPaintStruct.rcPaint.right - pPaintStruct.rcPaint.left
    int cy = pPaintStruct.rcPaint.bottom - pPaintStruct.rcPaint.top

    sys hMemDC
    sys hBmp
    sys hOldBmp
    POINT ptOldOrigin


    ' Create new bitmap-back device context, large as the dirty rectangle.
    hMemDC = CreateCompatibleDC(pPaintStruct.hdc)
    hBmp = CreateCompatibleBitmap(pPaintStruct.hdc, cx, cy)
    hOldBmp = SelectObject(hMemDC, hBmp)

    ' Do the painting into the memory bitmap.
    OffsetViewportOrgEx(hMemDC, -(pPaintStruct.rcPaint.left),
                        -(pPaintStruct.rcPaint.top), &ptOldOrigin)
    CustomPaint(&pData, hMemDC, &pPaintStruct.rcPaint, true)
    SetViewportOrgEx(hMemDC, ptOldOrigin.x, ptOldOrigin.y, null)

    ' Blit the bitmap into the screen. This is really fast operation and altough
    ' the CustomPaint() can be complex and slow there will be no flicker any more.
    BitBlt(pPaintStruct.hdc, pPaintStruct.rcPaint.left, pPaintStruct.rcPaint.top,
           cx, cy, hMemDC, 0, 0, SRCCOPY)

    ' Clean up.
    SelectObject(hMemDC, hOldBmp)
    DeleteObject(hBmp)
    DeleteDC(hMemDC)
end sub

function CustomProc(sys hwnd, uint uMsg, sys wParam, lParam) as sys callback

    CustomData *pData               'Pointer to CustomData structure

    if uMsg != WM_CREATE then
       &pData=GetWindowLongPtr(hwnd, 0)
    end if

    select case uMsg
        case WM_NCCREATE
            sys pdat=getmemory sizeof(CustomData)
            if pDat then
              SetWindowLongPtr(hwnd, 0, pdat)  'Store the pointer for later use
            else
                return false
            end if

            &pData=pdat                        'address of pData stucture

            pData.hwnd = hwnd

            CREATESTRUCT cstr at lParam
            pData.style=cstr.style
           
            pData.hbrDark = CreateSolidBrush(DARKCOLOR)
            pData.hbrLight = CreateSolidBrush(LIGHTCOLOR)           
            return true

        case WM_ERASEBKGND
            return false  ' Defer erasing into WM_PAINT

        case WM_PAINT
            PAINTSTRUCT ps
            BeginPaint(hwnd, &ps)
           
            ' We let application to choose whether to use double buffering or not by using the style XXS_DOUBLEBUFFER.
            if(pData.style and XXS_DOUBLEBUFFER) then                       
                CustomDoubleBuffer(&pData, &ps)
            else           
                CustomPaint(&pData, ps.hdc, &ps.rcPaint, ps.fErase)
            end if
            EndPaint(hwnd, &ps)
            return 0

        case WM_PRINTCLIENT
            RECT rc
            GetClientRect(hwnd, &rc)
            CustomPaint(&pData, wParam, &rc, true)
            return 0

        case WM_STYLECHANGED
            if wParam = GWL_STYLE then                       
                pData.style = lParam
            end if
            break

        case WM_NCDESTROY     
            if &pData then
                DeleteObject(pData.hbrDark)
                DeleteObject(pData.hbrLight)
                freememory(&pData)
            end if
            CustomUnregister()
            return 0

    end select
   
    return DefWindowProc(hwnd, uMsg, wParam, lParam)
end function

Aurel

  • Sr. Member
  • ****
  • Posts: 443
Re: Custom Controls in OxygenBasic
« Reply #20 on: November 14, 2018, 04:01:06 AM »
That should be useful:
l demonstrating double buffering
to see how work with resizing without flickering...

Arnold
Is there any flickering in this example because i cannot compile this program  ::)
my site:BLOG and FORUM
https://aurelsoft.ucoz.com/

Arnold

  • Hero Member
  • *****
  • Posts: 941
Re: Custom Controls in OxygenBasic
« Reply #21 on: November 14, 2018, 04:13:43 AM »
Hi Aurel,

there is no flickering. But I do not understand why you insist to use version A43. This is like using Windows 95 with an app for Windows 10.

Roland

Aurel

  • Sr. Member
  • ****
  • Posts: 443
Re: Custom Controls in OxygenBasic
« Reply #22 on: November 14, 2018, 04:47:39 AM »
Quote
But I do not understand why you insist to use version A43

Hi Arnold

It is simple why i 'insist'...
there are lot of changes and then i must fix every changes in my programs
and that is why i hate to do that it becomes like nightmare to me
every time something not work or not work properly....
sorry but i must say that I am not happy about that . >:(
my site:BLOG and FORUM
https://aurelsoft.ucoz.com/

Arnold

  • Hero Member
  • *****
  • Posts: 941
Re: Custom Controls in OxygenBasic
« Reply #23 on: June 23, 2019, 01:51:26 AM »
Hi Charles,

with the new release you dropped the notation like:

as zstring * 64

http://www.jose.it-berater.org/smfforum/index.php?topic=5474.msg23928#msg23928

this is not a real problem, but probably has some impact with some files in the latest Oxygenbasic distribution. At the moment I had to modify in Pgbar3d.inc in folder \examples\WinDynDialogs the type in about line 30:

Code: [Select]
TYPE PGB3DDATA             'for storing control specific data in memory block
  pStep       AS LONG         'for tracking what step we are on
  pMax        AS LONG         'for storing max number of steps, usually 100 (%)
  hbBack      AS DWORD        'handle for background brush
  barDC       AS DWORD        'memCD for Progressbar
  barBit      AS DWORD        'handle to Progressbar bitmap
  barDC2      AS DWORD        'memCD for Progressbar buffer
  barBit2     AS DWORD        'handle to Progressbar buffer bitmap
  memDc       AS DWORD        'memCD for main buffer
  hBit        AS DWORD        'handle to main buffer bitmap
  hRotateFont AS DWORD        'handle to rotated font style
  hImageBar   AS DWORD        'bar image handle
  hImageBkg   AS DWORD        'background image handle
  direction   AS LONG         'bar direction - left to right, or right to left?
  gradientDir AS LONG         'gradient direction - left to right, or right to left?
  txtAngle    AS LONG         'store given text angle
  bkgColor    AS LONG         'background color
  barCol      AS LONG         'bar color scheme
  txtColBar   AS LONG         'custom text color in bar
  txtColBkg   AS LONG         'custom text color on background
  txtOnOff    AS LONG         '0 = no text, 1 = auto text (%), 2 = custom text
  txtPos      AS LONG         'text position in control, see DrawText API..
'  txtBkg      AS ASCIIZ * 255 'text to be painted on background, increase/decrease size to suit your needs
'  txtBar      AS ASCIIZ * 255 'text to be painted on bar, increase/decrease size to suit your needs
  txtBkg[255] AS ASCIIZ        'text to be painted on background, increase/decrease size to suit your needs
  txtBar[255] AS ASCIIZ       'text to be painted on bar, increase/decrease size to suit your needs
  PalClr(192) AS LONG         'array for color sceme used by the control
end TYPE

I need to check some other files if they contain a notation similar to this one.

Roland


Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4276
    • Oxygen Basic
Re: Custom Controls in OxygenBasic
« Reply #24 on: June 23, 2019, 05:57:06 AM »
Got it. I can't see any more.