View Full Version : Canvas: How to retrieve scroll bar thumb positions when in virtual mode?
EmbeddedMan
26-06-2017, 18:43
So I have a very large canvas, which I'm using in virtual mode. This allows me to draw very long graphs, and have the user scroll left and right using the thumb of the virtual canvas horizontal scroll bar.
But I need to be able to retrieve the value of that scroll thumb - i.e., I need to know to which point in the graph they've scrolled.
How can I read that value out?
*Brian
Here is the code that demonstrates what I'm talking about :
Uses "UI"
Begin ControlID
%ID_Canvas
End ControlID
Function TBMain() As Long
Local hDlg As DWord '---Used to store window handle of main dialog
hDlg = Dialog_New Pixels, 0, "ABC ", -1, -1, 1200, 775,
%WS_DLGFRAME |
%DS_CENTER |
%WS_CAPTION |
%WS_SYSMENU |
%WS_OVERLAPPEDWINDOW
Dialog Show Modal hDlg, Call cbDialog
End Function
CallBack Function cbDialog() As Long
Select Case CBMSG
Case %WM_INITDIALOG
Control Add Canvas, CBHNDL, %ID_Canvas, "", 200, 10,1000, 400, %WS_BORDER | %WS_CHILD | %WS_VISIBLE
Canvas_Attach(CBHNDL, %ID_Canvas, %FALSE)
Canvas_SetVirtual(100000, 380)
Canvas_SetView(0,0)
Canvas_Width(2)
End Select
End Function
ErosOlmi
26-06-2017, 19:08
To get the hor/vert position of the virtual view inside the physical view you can use Canvas_GetView (http://www.thinbasic.com/public/products/thinBasic/help/html/index.html?canvas_getview.htm) (and counterpart Canvas_SetView (http://www.thinbasic.com/public/products/thinBasic/help/html/index.html?canvas_setview.htm)) like the following:
local WidthVar as Long
local HeightVar as Long
...
Canvas_GetView WidthVar, HeightVar
Not sure which events are triggered when user move scrollbars
I need to make some search, anyway here an example: as you can see there are many events.
Uses "UI"
uses "console"
Begin ControlID
%ID_Canvas
End ControlID
Function TBMain() As Long
Local hDlg As DWord '---Used to store window handle of main dialog
hDlg = Dialog_New Pixels, 0, "ABC ", -1, -1, 1200, 775,
%WS_DLGFRAME |
%DS_CENTER |
%WS_CAPTION |
%WS_SYSMENU |
%WS_OVERLAPPEDWINDOW
Dialog Show Modal hDlg, Call cbDialog
End Function
CallBack Function cbDialog() As Long
local WidthVar as Long
local HeightVar as Long
Select Case CBMSG
Case %WM_INITDIALOG
Control Add Canvas, CBHNDL, %ID_Canvas, "", 200, 10,1000, 400, %WS_BORDER | %WS_CHILD | %WS_VISIBLE
Canvas_Attach(CBHNDL, %ID_Canvas, %FALSE)
Canvas_SetVirtual(100000, 380)
Canvas_SetView(0,0)
Canvas_Width(2)
case %WM_MOUSEMOVE
case Else
printl " Msg", cbmsg, CBCTL, CBLPARAM, CBLPARAM
Canvas_GetView WidthVar, HeightVar
printl "GetView", WidthVar, HeightVar
End Select
End Function
EmbeddedMan
26-06-2017, 19:18
Ahh, yes! Canvas_GetView() looks like the ticket for me. Thanks so much for the fast answer.
*Brian
ErosOlmi
26-06-2017, 19:35
You can use %WM_CTLCOLORSTATIC message that is fired every time a child control must be drawn
https://msdn.microsoft.com/en-us/library/windows/desktop/bb787524(v=vs.85).aspx
Here example
Uses "UI"uses "console"
Begin ControlID
%ID_Canvas
End ControlID
Function TBMain() As Long
Local hDlg As DWord '---Used to store window handle of main dialog
hDlg = Dialog_New Pixels, 0, "ABC ", -1, -1, 1200, 775,
%WS_DLGFRAME |
%DS_CENTER |
%WS_CAPTION |
%WS_SYSMENU |
%WS_OVERLAPPEDWINDOW
Dialog Show Modal hDlg, Call cbDialog
End Function
CallBack Function cbDialog() As Long
local WidthVar as Long
local HeightVar as Long
Select Case CBMSG
Case %WM_INITDIALOG
Control Add Canvas, CBHNDL, %ID_Canvas, "", 200, 10,1000, 400, %WS_BORDER | %WS_CHILD | %WS_VISIBLE '| %SS_Notify
Canvas_Attach(CBHNDL, %ID_Canvas, %FALSE)
Canvas_SetVirtual(100000, 380)
Canvas_SetView(0,0)
Canvas_Width(2)
case %WM_MOUSEMOVE
case %WM_SETCURSOR
case %WM_NCHITTEST
case %WM_PARENTNOTIFY
case %WM_NCMOUSEMOVE
case %WM_GETDLGCODE
case %WM_MEASUREITEM
case %WM_DRAWITEM
case %WM_MOUSEACTIVATE
case %WM_WINDOWPOSCHANGING
'---Do nothing
case %WM_CTLCOLORSTATIC '---https://msdn.microsoft.com/en-us/library/windows/desktop/bb787524(v=vs.85).aspx
printl " Msg", cbmsg, CBCTL, CBLPARAM, CBLPARAM
Canvas_GetView WidthVar, HeightVar
printl "GetView", WidthVar, HeightVar
'sleep 200
End Select
End Function