ScrollBar position on MdiGadget [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

ScrollBar position on MdiGadget [Resolved]

Post by Kwai chang caine »

Hello at all :D

Have you a way for knowing the position of MdiGadget scrollbar ? I have not found a native function :(
I have also try with "GetScrollPos_()" but that not works :oops:

Code: Select all

#FenetrePrincipale = 0
#FenetreFille = 1

If OpenWindow(#FenetrePrincipale, 0, 0, 400, 300, "MDIGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget)
 
 MDIGadget(0, 0, 0, 0, 0, 1, 2, #PB_MDI_AutoSize)
 AddGadgetItem(0, #FenetreFille, "Fenêtre fille")
 UseGadgetList(WindowID(#FenetrePrincipale))
 
 MoveWindow_(WindowID(1), 1000, 100, 800, 100, #SWP_SHOWWINDOW)
  
 Repeat 
 
  Debug GetScrollPos_(GadgetID(0), #SB_HORZ) 
  Debug GetScrollPos_(GadgetID(0), #SB_VERT)
  
 Until WaitWindowEvent()=#PB_Event_CloseWindow
 
EndIf
Have a good day
Last edited by Kwai chang caine on Thu Apr 18, 2019 4:58 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: ScrollBar position on MdiGadget

Post by Kwai chang caine »

Thanks to a ArticFox code,
http://www.purebasic.fr/english/viewtop ... 00#p305500
I found how detect the moving of ScrollBar, with subclassing 8)
Apparently MDI is like ScrollArea
But always not real good values :oops:

Code: Select all

Global OldSubclass

Procedure ScrollCallback(Handle, Message, wParam, lParam)

Select Message
 
 Case #WM_HSCROLL
   
  Debug "#WM_HSCROLL"
  h = GetScrollPos_(Handle, #SB_HORZ)
  Debug h

 Case #WM_VSCROLL
  
  Debug "#WM_VSCROLL"
  v = GetScrollPos_(Handle, #SB_VERT)
  Debug v
  
EndSelect

ProcedureReturn CallWindowProc_(OldSubclass, Handle, Message, wParam, lParam)
EndProcedure

#FenetrePrincipale = 0
#FenetreFille = 1
#Mdi = 3

If OpenWindow(#FenetrePrincipale, 0, 0, 400, 300, "MDIGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget)
 
 MDIGadget(#Mdi, 0, 0, 0, 0, 1, 2, #PB_MDI_AutoSize)
 AddGadgetItem(#Mdi, #FenetreFille, "Fenêtre fille")
 UseGadgetList(WindowID(#FenetrePrincipale))
 
 MoveWindow_(WindowID(1), 1000, 1000, 800, 100, #SWP_SHOWWINDOW)
 
 OldSubclass = SetWindowLong_(GadgetID(#Mdi), #GWL_WNDPROC, @ScrollCallback())
 
 Repeat
 
 Until WaitWindowEvent()=#PB_Event_CloseWindow
 
EndIf
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: ScrollBar position on MdiGadget [Resolved]

Post by Kwai chang caine »

Thanks to SROD i can adapting a solution 8)
viewtopic.php?p=435746#p435746

Code: Select all


#MAIN = 1
Global gOldProc

Procedure Callback(hWnd,uMsg,wParam,lParam)
 
 Protected Result, SifMainH.SCROLLINFO, SifMainV.SCROLLINFO
 Static PosH, PosV
 
 Result = CallWindowProc_(gOldProc, hWnd, uMsg, wParam, lParam)
 
 If uMsg = #WM_HSCROLL Or uMsg = #WM_VSCROLL
 
  Select uMsg 
  
   Case #WM_HSCROLL
 
    With SifMainH
     \cbSize = SizeOf(SCROLLINFO)
     \fMask = #SIF_ALL
    EndWith
      
    GetScrollInfo_(hWnd, #SB_HORZ, SifMainH)
    PosH = SifMainH\nTrackPos
    
   Case #WM_VSCROLL 
   
    With SifMainV
     \cbSize = SizeOf(SCROLLINFO)
     \fMask = #SIF_ALL
    EndWith
    
    GetScrollInfo_(hWnd, #SB_VERT, SifMainV)
    PosV = SifMainV\nTrackPos
           
  EndSelect
  
  Debug "PosH = " + Trim(Str(PosH))
  Debug "PosV = " + Trim(Str(PosV))
  Debug ""
  
 EndIf 
   
 ProcedureReturn Result
 
EndProcedure

#FenetrePrincipale = 0
#FenetreFille = 2
OpenWindow(0,0,0,1000,320,"HORZ",#PB_Window_SystemMenu | #PB_Window_ScreenCentered|#PB_Window_SizeGadget)
MDIGadget(1, 0, 0, 0, 0, 1, 2, #PB_MDI_AutoSize)
AddGadgetItem(1, #FenetreFille, "Fenêtre fille")
UseGadgetList(WindowID(#FenetrePrincipale))
MoveWindow_(WindowID(#FenetreFille), 1000, 1000, 800, 100, #SWP_SHOWWINDOW)

gOldProc = SetWindowLongPtr_(GadgetID(#main), #GWL_WNDPROC, @Callback())

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend


ImageThe happiness is a road...
Not a destination
SeregaZ
Enthusiast
Enthusiast
Posts: 617
Joined: Fri Feb 20, 2009 9:24 am
Location: Almaty (Kazakhstan. not Borat, but Triple G)
Contact:

Re: ScrollBar position on MdiGadget [Resolved]

Post by SeregaZ »

can you a little help? i have another gadget - ListIcon. how to know wich one row from all list now is first after scroll in gadget? as i can understand i need 78 event - it will capture change scroll bar... probably... and then i need to make... ? i mean no selected item, but first row in a visible area of this list icon after scrolling.

Code: Select all

Enumeration
  #Window
  #List
  #NUMGad
EndEnumeration

Procedure WinCallback(hWnd, uMsg, WParam, LParam) 
  
  ;Debug uMsg
  
  Select uMsg
    Case 522        ; mousewheel
      ;Debug "522"
    Case 78
      Debug "78"
      ; some get first row number in a gadget
    Default
      ;Debug uMsg
  EndSelect
  
  ProcedureReturn #PB_ProcessPureBasicEvents 
EndProcedure 

If OpenWindow(#Window, 100, 100, 220, 360, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget)
  
  ListIconGadget(#List, 10, 10, 200, 250, "command", 88, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
    AddGadgetColumn(#List, 1, "comment", 90)
  
;{
AddGadgetItem(#List, -1, "metka1:" + Chr(10) + "")
AddGadgetItem(#List, -1, "db 0AEh" + Chr(10) + " instr 14")
AddGadgetItem(#List, -1, "db 84h, 07Dh" + Chr(10) + " volume 125")
AddGadgetItem(#List, -1, "db 0E5h" + Chr(10) + " duration 6")
AddGadgetItem(#List, -1, "db 017h" + Chr(10) + " note 23  17")
AddGadgetItem(#List, -1, "db 0F9h" + Chr(10) + " duration 26")
AddGadgetItem(#List, -1, "db 01Eh" + Chr(10) + " note 30  1E")
AddGadgetItem(#List, -1, "db 0E5h" + Chr(10) + " duration 6")
AddGadgetItem(#List, -1, "db 017h" + Chr(10) + " note 23  17")
AddGadgetItem(#List, -1, "db 0A7h" + Chr(10) + " instr 7")
AddGadgetItem(#List, -1, "db 84h, 001h" + Chr(10) + " volume 1")
AddGadgetItem(#List, -1, "db 0F9h" + Chr(10) + " duration 26")
AddGadgetItem(#List, -1, "db 01Eh" + Chr(10) + " note 30  1E")
AddGadgetItem(#List, -1, "db 0E9h" + Chr(10) + " duration 10")
AddGadgetItem(#List, -1, "db 02Ah" + Chr(10) + " note 42  2A")
AddGadgetItem(#List, -1, "db 0ADh" + Chr(10) + " instr 13")
AddGadgetItem(#List, -1, "db 84h, 07Fh" + Chr(10) + " volume 127")
AddGadgetItem(#List, -1, "db 0E1h" + Chr(10) + " duration 2")
AddGadgetItem(#List, -1, "db 081h" + Chr(10) + " note 129  81")
AddGadgetItem(#List, -1, "db 0E0h" + Chr(10) + " duration 1")
AddGadgetItem(#List, -1, "db 03Dh" + Chr(10) + " note 61  3D")
AddGadgetItem(#List, -1, "db 081h" + Chr(10) + " note 129  81")
AddGadgetItem(#List, -1, "db 03Bh" + Chr(10) + " note 59  3B")
AddGadgetItem(#List, -1, "db 081h" + Chr(10) + " note 129  81")
AddGadgetItem(#List, -1, "db 0E5h" + Chr(10) + " duration 6")
AddGadgetItem(#List, -1, "db 03Dh" + Chr(10) + " note 61  3D")
AddGadgetItem(#List, -1, "db 0E1h" + Chr(10) + " duration 2")
AddGadgetItem(#List, -1, "db 081h" + Chr(10) + " note 129  81")
AddGadgetItem(#List, -1, "db 0E7h" + Chr(10) + " duration 8")
AddGadgetItem(#List, -1, "db 036h" + Chr(10) + " note 54  36")
AddGadgetItem(#List, -1, "db 0EBh" + Chr(10) + " duration 12")
AddGadgetItem(#List, -1, "db 081h" + Chr(10) + " note 129  81")
AddGadgetItem(#List, -1, "db 0E0h" + Chr(10) + " duration 1")
AddGadgetItem(#List, -1, "db 03Eh" + Chr(10) + " note 62  3E")
;}

  StringGadget(#NUMGad, 10, 280, 50, 20, "0")
  
  SetWindowCallback(@WinCallback(), #Window)
  
  Repeat
     Select WaitWindowEvent()

       Case #PB_Event_Gadget

         Select EventGadget()
           Case #List

         EndSelect

       Case #PB_Event_CloseWindow
         qiut = 1
   
     EndSelect
   Until qiut = 1

  End

EndIf
SeregaZ
Enthusiast
Enthusiast
Posts: 617
Joined: Fri Feb 20, 2009 9:24 am
Location: Almaty (Kazakhstan. not Borat, but Triple G)
Contact:

Re: ScrollBar position on MdiGadget [Resolved]

Post by SeregaZ »

sorry :) find it :)

Code: Select all

EnableExplicit

Define EventID
Define a

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(1, 0, 0, WindowWidth(0), WindowHeight(0)-40, "Spalte", 450, 0)
  For a=1 To 100
    AddGadgetItem(1, -1, "Item " + Str(a), 0, 0)
  Next
  
  ButtonGadget(2, WindowWidth(0)-210, WindowHeight(0)-30, 200, 20, "Erste sichtbare Zeile ermitteln", 0)
  
  Repeat
    EventID = WaitWindowEvent()
    If EventID = #PB_Event_Gadget
      Select EventGadget()
        Case 2
          Debug SendMessage_(GadgetID(1), #LVM_GETTOPINDEX, 0, 0)
      EndSelect
    EndIf
    If EventID = #PB_Event_CloseWindow
      End
    EndIf
  ForEver
EndIf
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: ScrollBar position on MdiGadget [Resolved]

Post by Shardik »

It would have been nice to also post the link to the posted example and give credit to its author:
RSBasic: https://www.rsbasic.de/aktualisierung/w ... mitteln.pb
Post Reply