Results 1 to 4 of 4

Thread: Canvas: How to retrieve scroll bar thumb positions when in virtual mode?

  1. #1

    Canvas: How to retrieve scroll bar thumb positions when in virtual mode?

    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
    

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,133
    Blog Entries
    2
    Rep Power
    10
    To get the hor/vert position of the virtual view inside the physical view you can use Canvas_GetView (and counterpart Canvas_SetView) 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
    
    Last edited by ErosOlmi; 26-06-2017 at 19:10.
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  3. #3
    Ahh, yes! Canvas_GetView() looks like the ticket for me. Thanks so much for the fast answer.

    *Brian

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,133
    Blog Entries
    2
    Rep Power
    10
    You can use %WM_CTLCOLORSTATIC message that is fired every time a child control must be drawn
    https://msdn.microsoft.com/en-us/lib...(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
    
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Similar Threads

  1. Yet another question, Scroll bars
    By RobbeK in forum TBGL General
    Replies: 2
    Last Post: 19-12-2013, 11:02
  2. picture transpaence in canvas mode?
    By largo_winch in forum thinAir General
    Replies: 8
    Last Post: 30-05-2012, 16:16
  3. How to retrieve a return value from thinBasic_FunctionSimpleCall?
    By Michael Hartlef in forum Module SDK (Freebasic version)
    Replies: 6
    Last Post: 10-09-2010, 22:44
  4. Replies: 6
    Last Post: 16-06-2010, 06:40
  5. Replies: 8
    Last Post: 14-01-2010, 04:56

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •