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

0 Members and 1 Guest are viewing this topic.

Aurel

  • Guest
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...

Aurel

  • Guest
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  ::)

Charles Pegge

  • Guest
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

  • Guest
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

  • Guest
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: OxygenBasic
  1. 'Custom Control demonstrating the double buffering
  2. 'https://www.codeproject.com/Articles/617212/Custom-Controls-in-Win32-API-The-Painting
  3.  
  4. $ filename "dblbuf.exe"
  5.  
  6. 'uses rtl32
  7. 'uses rtl64
  8.  
  9. uses winutil
  10.  
  11.  
  12. % DT_CENTER=1
  13. % DT_VCENTER=4
  14. % DT_SINGLELINE=32
  15. % SWP_NOZORDER=4
  16. % GCL_HBRBACKGROUND = -10
  17. % SRCCOPY=0xCC0020
  18. % WM_NCCREATE=129
  19. % WM_NCDESTROY=130
  20. % WM_PRINTCLIENT=792
  21. % WM_STYLECHANGED=125
  22. % SIZE_RESTORED=0
  23. % SIZE_MAXIMIZED=2
  24.  
  25.  
  26. function RGB(int r, g, b) as int
  27.     return (r + g*256 + b*65536)
  28. end Function
  29.  
  30.  
  31. '=======================
  32. 'MAIN CODE
  33. '=======================
  34.  
  35. dim nCmdline as asciiz ptr, hInstance as sys
  36. &nCmdline = GetCommandLine
  37. hInstance = GetModuleHandle(0)
  38.  
  39. MainWindow 350,250,WS_OVERLAPPEDWINDOW
  40.  
  41. '-----------------------------------------------------------------------------
  42.  
  43. ' Window class
  44. % CUSTOM_WC = "CustomControl"
  45.  
  46. /* Style to request using double buffering. */
  47. % XXS_DOUBLEBUFFER   0x0001
  48.  
  49. % CUSTOM_ID     100
  50. % MARGIN          7
  51.  
  52.  
  53. % CELLSIZE        48
  54. % DARKCOLOR       RGB(0,47,127)
  55. % LIGHTCOLOR      RGB(241,179,0)
  56.  
  57.  
  58. type CustomData
  59.     sys   hwnd
  60.     dword style
  61.     sys   hbrLight
  62.     sys   hbrDark
  63. end type
  64.  
  65. 'Register the window class
  66. sub CustomRegister()
  67.     WNDCLASSEX wc
  68.  
  69.     ' Note we do not use CS_HREDRAW and CS_VREDRAW.
  70.    ' This means when the control is resized, WM_SIZE (as handled by DefWindowProc())
  71.    ' invalidates only the newly uncovered area.
  72.    ' With those class styles, it would invalidate complete client rectangle.
  73.    wc.cbSize        = sizeof(WNDCLASSEX)
  74.     wc.lpszClassName = &CUSTOM_WC           'strptr "CustomControl"
  75.    wc.style         = CS_GLOBALCLASS    
  76.     wc.lpfnWndProc   = @CustomProc
  77.     wc.cbWndExtra    = sizeof(sys) 'pointer to CustomData    
  78.    wc.hCursor       = LoadCursor(null, IDC_ARROW)
  79.    
  80.     if RegisterClassEx(&wc) = 0 then mbox "Error: Cannot Register CustomControl"
  81. end sub
  82.  
  83. 'Unregister the window class
  84. sub CustomUnregister()
  85.    if UnregisterClass(CUSTOM_WC, null) = 0 then mbox "Error: Cannot Unregister CustomControl"
  86. end sub
  87.  
  88.  
  89. function WndProc(sys hwnd, uint uMsg, sys wParam, lParam) as sys callback
  90.     static sys hwndCustom
  91.    
  92.     select uMsg
  93.  
  94.         case WM_CREATE
  95.            SetWindowText(hwnd, "Double Buffering Example")
  96.  
  97.            CustomRegister()        
  98.            hwndCustom = CreateWindowEx(0,CUSTOM_WC, null, WS_CHILD or WS_VISIBLE or 0,
  99.                                  0, 0, 0, 0, hwnd, CUSTOM_ID, hInstance, null)
  100.            if hwndCustom = 0 then mbox "Error: Cannot create hwndCustom"
  101.        
  102.         case WM_SIZE
  103.            if wParam = SIZE_MAXIMIZED or wParam = SIZE_RESTORED then
  104.              word cx = loword(lParam)
  105.              word cy = hiword(lParam)
  106.              SetWindowPos(hwndCustom, null, MARGIN, MARGIN,
  107.                          (cx-2*MARGIN), (cy-2*MARGIN), SWP_NOZORDER)
  108.            end if
  109.  
  110.         case WM_CLOSE
  111.            DestroyWindow(hwnd)
  112.  
  113.         case WM_DESTROY
  114.            PostQuitMessage(0)
  115.                    
  116.         case else
  117.            return DefWindowProc(hwnd, uMsg, wParam, lParam)
  118.  
  119.     end select
  120.    
  121. end function
  122.  
  123. sub CustomPaint(sys *pDat, sys hDC, sys *rcDirt, bool bErase)
  124.     int x, y
  125.     RECT r
  126.     sys hBrush
  127.    
  128.     RECT rcDirty at &rcDirt
  129.     CustomData pData at pDat
  130.    
  131.     ' Note we paint only the cells overlaping with the dirty rectangle.
  132.    for y = (rcDirty.top / CELLSIZE) to (rcDirty.bottom / CELLSIZE)
  133.         for x = (rcDirty.left / CELLSIZE) to (rcDirty.right / CELLSIZE)
  134.             if mod((x+y),2)=0 then hBrush=pData.hbrLight else hBrush=pData.hbrDark
  135.             SetRect(&r, x * CELLSIZE, y * CELLSIZE, (x+1) * CELLSIZE, (y+1) * CELLSIZE)
  136.             FillRect(hDC, &r, hBrush)
  137.         next x
  138.     next y
  139. end sub
  140.  
  141. sub CustomDoubleBuffer(sys *pDat, sys *pPaintStruc)    
  142.     CustomData pData : &pData = &pDat
  143.     PAINTSTRUCT pPaintStruct : &pPaintStruct = &pPaintStruc
  144.  
  145.     int cx = pPaintStruct.rcPaint.right - pPaintStruct.rcPaint.left
  146.     int cy = pPaintStruct.rcPaint.bottom - pPaintStruct.rcPaint.top
  147.  
  148.     sys hMemDC
  149.     sys hBmp
  150.     sys hOldBmp
  151.     POINT ptOldOrigin
  152.  
  153.  
  154.     ' Create new bitmap-back device context, large as the dirty rectangle.
  155.    hMemDC = CreateCompatibleDC(pPaintStruct.hdc)
  156.     hBmp = CreateCompatibleBitmap(pPaintStruct.hdc, cx, cy)
  157.     hOldBmp = SelectObject(hMemDC, hBmp)
  158.  
  159.     ' Do the painting into the memory bitmap.
  160.    OffsetViewportOrgEx(hMemDC, -(pPaintStruct.rcPaint.left),
  161.                         -(pPaintStruct.rcPaint.top), &ptOldOrigin)
  162.     CustomPaint(&pData, hMemDC, &pPaintStruct.rcPaint, true)
  163.     SetViewportOrgEx(hMemDC, ptOldOrigin.x, ptOldOrigin.y, null)
  164.  
  165.     ' Blit the bitmap into the screen. This is really fast operation and altough
  166.    ' the CustomPaint() can be complex and slow there will be no flicker any more.
  167.    BitBlt(pPaintStruct.hdc, pPaintStruct.rcPaint.left, pPaintStruct.rcPaint.top,
  168.            cx, cy, hMemDC, 0, 0, SRCCOPY)
  169.  
  170.     ' Clean up.
  171.    SelectObject(hMemDC, hOldBmp)
  172.     DeleteObject(hBmp)
  173.     DeleteDC(hMemDC)
  174. end sub
  175.  
  176. function CustomProc(sys hwnd, uint uMsg, sys wParam, lParam) as sys callback
  177.  
  178.     CustomData *pData               'Pointer to CustomData structure
  179.  
  180.     if uMsg != WM_CREATE then
  181.        &pData=GetWindowLongPtr(hwnd, 0)
  182.     end if
  183.  
  184.     select case uMsg
  185.         case WM_NCCREATE
  186.             sys pdat=getmemory sizeof(CustomData)
  187.             if pDat then
  188.               SetWindowLongPtr(hwnd, 0, pdat)  'Store the pointer for later use
  189.            else
  190.                 return false
  191.             end if
  192.  
  193.             &pData=pdat                        'address of pData stucture
  194.  
  195.             pData.hwnd = hwnd
  196.  
  197.             CREATESTRUCT cstr at lParam
  198.             pData.style=cstr.style
  199.            
  200.             pData.hbrDark = CreateSolidBrush(DARKCOLOR)
  201.             pData.hbrLight = CreateSolidBrush(LIGHTCOLOR)            
  202.             return true
  203.  
  204.         case WM_ERASEBKGND
  205.             return false  ' Defer erasing into WM_PAINT
  206.  
  207.         case WM_PAINT
  208.             PAINTSTRUCT ps
  209.             BeginPaint(hwnd, &ps)
  210.            
  211.             ' We let application to choose whether to use double buffering or not by using the style XXS_DOUBLEBUFFER.
  212.            if(pData.style and XXS_DOUBLEBUFFER) then                        
  213.                 CustomDoubleBuffer(&pData, &ps)
  214.             else          
  215.                 CustomPaint(&pData, ps.hdc, &ps.rcPaint, ps.fErase)
  216.             end if
  217.             EndPaint(hwnd, &ps)
  218.             return 0
  219.  
  220.         case WM_PRINTCLIENT
  221.             RECT rc
  222.             GetClientRect(hwnd, &rc)
  223.             CustomPaint(&pData, wParam, &rc, true)
  224.             return 0
  225.  
  226.         case WM_STYLECHANGED
  227.             if wParam = GWL_STYLE then                      
  228.                 pData.style = lParam
  229.             end if
  230.             break
  231.  
  232.         case WM_NCDESTROY      
  233.             if &pData then
  234.                 DeleteObject(pData.hbrDark)
  235.                 DeleteObject(pData.hbrLight)
  236.                 freememory(&pData)
  237.             end if
  238.             CustomUnregister()
  239.             return 0
  240.  
  241.     end select
  242.    
  243.     return DefWindowProc(hwnd, uMsg, wParam, lParam)
  244. end function
  245.  

Aurel

  • Guest
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  ::)

Arnold

  • Guest
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

  • Guest
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 . >:(

Arnold

  • Guest
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

  • Guest
Re: Custom Controls in OxygenBasic
« Reply #24 on: June 23, 2019, 05:57:06 AM »
Got it. I can't see any more.