where i need to make it work when mouse scroll event happen.
But the problem is while using PureBasic 6.20 it only working when you use OpenScreen https://www.purebasic.com/documentation ... se.pb.html)
But i need to make the scroll work while using OpenWindow method,
Can anyone check the code please?
How to apply mouse wheel scrolling, on that white area here with my existing lines for example:

Code:
====
Code: Select all
Global MainWindow
Global scrollOffset1 = 0, scrollOffset2 = 0 ; Scroll offsets
Global contentHeight1 = 180, contentHeight2 = 140
Global activeScrollArea = 0
Global mouseX, mouseY, mouseDown = #False
Enumeration FormFont
#Font_Person_Big
EndEnumeration
; Win32 constants
#WS_EX_LAYERED = $00080000
#GWL_EXSTYLE = -20
#AC_SRC_OVER = 0
#AC_SRC_ALPHA = 1
Declare HandleMouseWheel(scrollArea, delta)
; --- Draw layered window ---
Procedure OpenMainWindow(x = 0, y = 0, width = 330, height = 340)
ExamineDesktops()
x = DesktopWidth(0) - width - 200
y = DesktopHeight(0) - height - 200
LoadFont(#Font_Person_Big, "Tahoma", 12, #PB_Font_Bold)
If IsWindow(MainWindow) = 0
MainWindow = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_BorderLess)
Protected hWnd = WindowID(MainWindow)
Protected style = GetWindowLong_(hWnd, #GWL_EXSTYLE)
SetWindowLong_(hWnd, #GWL_EXSTYLE, style | #WS_EX_LAYERED)
EndIf
Protected img = CreateImage(#PB_Any, width, height, 32, #PB_Image_Transparent)
If StartDrawing(ImageOutput(img))
DrawingMode(#PB_2DDrawing_AlphaBlend)
Box(0, 0, width, height, RGBA(110,110,110,128)) ; gray background
Protected margin = 10
Box(margin, margin, width - margin*2, height - margin*2, RGBA(200,200,200,255))
; --- Scroll Area 1 ---
DrawingMode(#PB_2DDrawing_Default)
Box(margin+5, margin+5, 300, 65, RGB(240,240,240))
ClipOutput(margin+5, margin+5, 300, 65)
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(FontID(#Font_Person_Big))
DrawText(margin+10, margin+10 - scrollOffset1, "1. Elon Monk", RGB(0,0,0))
DrawText(margin+10, margin+60 - scrollOffset1, "2. Bill Plate", RGB(0,0,0))
DrawText(margin+10, margin+110 - scrollOffset1, "3. Steve Work", RGB(0,0,0))
DrawText(margin+10, margin+160 - scrollOffset1, "4. Byran Eve", RGB(0,0,0))
UnclipOutput()
StopDrawing()
EndIf
Dim pt.POINT(1) : pt(0)\x = x : pt(0)\y = y
Dim sz.SIZE(1) : sz(0)\cx = width : sz(0)\cy = height
Dim srcPt.POINT(1)
Define blend.BLENDFUNCTION
blend\BlendOp = #AC_SRC_OVER
blend\BlendFlags = 0
blend\SourceConstantAlpha = 255
blend\AlphaFormat = #AC_SRC_ALPHA
Protected screenDC = GetDC_(0)
Protected memDC = CreateCompatibleDC_(screenDC)
Protected oldObj = SelectObject_(memDC, ImageID(img))
UpdateLayeredWindow_(hWnd, screenDC, @pt(0), @sz(0), memDC, @srcPt(0), 0, @blend, 2)
SelectObject_(memDC, oldObj)
DeleteDC_(memDC)
ReleaseDC_(0, screenDC)
FreeImage(img)
EndProcedure
; --- Scroll logic ---
Procedure HandleMouseWheel(scrollArea, delta)
If scrollArea = 1
scrollOffset1 - delta*20
If scrollOffset1 < 0 : scrollOffset1 = 0 : EndIf
If scrollOffset1 > contentHeight1 - 65 : scrollOffset1 = contentHeight1 - 65 : EndIf
ElseIf scrollArea = 2
scrollOffset2 - delta*20
If scrollOffset2 < 0 : scrollOffset2 = 0 : EndIf
If scrollOffset2 > contentHeight2 - 90 : scrollOffset2 = contentHeight2 - 90 : EndIf
EndIf
OpenMainWindow()
EndProcedure
; --- Mouse events ---
Procedure HandleMouseEvents()
Protected Event = WindowEvent()
If Event = #PB_Event_CloseWindow : End : EndIf
Protected mx = WindowMouseX(MainWindow)
Protected my = WindowMouseY(MainWindow)
If mx>=15 And mx<=315 And my>=125 And my<=190
activeScrollArea = 1
ElseIf mx>=20 And mx<=310 And my>=220 And my<=310
activeScrollArea = 2
Else
activeScrollArea = 0
EndIf
If GetAsyncKeyState_(#VK_MBUTTON) & $8000
Static lastWheelTime
If ElapsedMilliseconds()-lastWheelTime > 100
If my < WindowHeight(MainWindow)/2
HandleMouseWheel(activeScrollArea, 1)
Else
HandleMouseWheel(activeScrollArea, -1)
EndIf
lastWheelTime = ElapsedMilliseconds()
EndIf
EndIf
Delay(10)
EndProcedure
OpenMainWindow()
Repeat
HandleMouseEvents()
ForEver