Page 1 of 3
Posted: Tue Aug 08, 2006 11:28 pm
by netmaestro
Dammit Srod!! where you buying your holster oil? [edit] Ha - tweaked my code to be 4 lines shorter than yours!
Code: Select all
Procedure Callback(hwnd, msg, wparam, lparam)
result = #PB_ProcessPureBasicEvents
If msg=#WM_COMMAND
If IsGadget(1)
If lparam = GadgetID(1)
If wparam >> 16 = 1024 ; EN_UPDATE
SendMessage_(GadgetID(1), #EM_GETSCROLLPOS, 0, @pt.point)
SendMessage_(GadgetID(0), #EM_SETSCROLLPOS, 0, @pt)
EndIf
EndIf
EndIf
result = 0
EndIf
ProcedureReturn result
EndProcedure
If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
SetWindowCallback(@Callback())
ContainerGadget(2,5,5,50,133)
EditorGadget(0, 5, 5, 65, 133)
CloseGadgetList()
EditorGadget(1, 60, 10, 250, 133)
For a = 0 To 20
AddGadgetItem(0, a, Str(a))
AddGadgetItem(1, a, "Line "+Str(a))
Next
Repeat : Until WaitWindowEvent()=#WM_CLOSE
EndIf
End
Posted: Tue Aug 08, 2006 11:33 pm
by Xombie
chen wrote:Ok...
Im testing your code and I see this:
If you scroll down line by line the line number are sincronized with the data
But?
If you advance by page there are no one-one relation.... for example
65 point to line 66
DO I need to consider something else...?
Anyway Im going to try by myself.... thanks indeed...
It's checking the first visible line item and including anything that's even partially visible. Using a callback and checking for the scroll message rather than watching the line number of the edit control is much better - a la srod's code. That way they match exactly and you aren't constrained by PB's limitation of not providing events while moving the little scrollbar itself.
Posted: Tue Aug 08, 2006 11:37 pm
by srod
I like your code netmaestro. Pretty slick!
Which notification message corresponds to 1024?
Posted: Tue Aug 08, 2006 11:37 pm
by netmaestro
Posted: Tue Aug 08, 2006 11:40 pm
by srod
Pah, who needs a mousewheel?

Posted: Tue Aug 08, 2006 11:51 pm
by netmaestro
1024 is #EN_UPDATE:
MSDN wrote:The EN_UPDATE notification message is sent when an edit control is about to redraw itself.
Sorry, I really should have used the constant instead of the value, it would've been easier to read. I'm bad for that.

Posted: Tue Aug 08, 2006 11:58 pm
by srod
Yep, your's is definitely the best way. Very nice.
Posted: Wed Aug 09, 2006 12:57 am
by chen
Battle at the top
Help a lot thanks.....
Posted: Fri Oct 20, 2006 3:09 pm
by RegisLG
In my program i have the EnableExplicit activated.
I wanted to use netmastro's code, but i need to know the variable declation i must write in the procedure.
Can someone help me please ?
Posted: Fri Oct 20, 2006 3:32 pm
by Tranquil
In my program i have the EnableExplicit activated.
I wanted to use netmastro's code, but i need to know the variable declation i must write in the procedure.
Can someone help me please ?
Code: Select all
EnableExplicit
Procedure Callback(hwnd, msg, wparam, lparam)
Protected result.l
Protected pt.point
result = #PB_ProcessPureBasicEvents
If msg=#WM_COMMAND
If IsGadget(1)
If lparam = GadgetID(1)
If wparam >> 16 = 1024 ; EN_UPDATE
SendMessage_(GadgetID(1), #EM_GETSCROLLPOS, 0, @pt.point)
SendMessage_(GadgetID(0), #EM_SETSCROLLPOS, 0, @pt)
EndIf
EndIf
EndIf
result = 0
EndIf
ProcedureReturn result
EndProcedure
Global a.b
If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
SetWindowCallback(@Callback())
ContainerGadget(2,5,5,50,133)
EditorGadget(0, 5, 5, 65, 133)
CloseGadgetList()
EditorGadget(1, 60, 10, 250, 133)
For a = 0 To 20
AddGadgetItem(0, a, Str(a))
AddGadgetItem(1, a, "Line "+Str(a))
Next
Repeat : Until WaitWindowEvent()=#WM_CLOSE
EndIf
End
Posted: Fri Oct 20, 2006 3:49 pm
by RegisLG

seems so easy ! Thank you !
Where is the "point" type declared ? is it a structure, part of the API, that we don't have to declare ?
Posted: Fri Oct 20, 2006 4:23 pm
by Tranquil
.point is a structure predefined in the PB-residents. Most common structures of Windows are defined in there.
Posted: Fri Oct 20, 2006 5:18 pm
by RegisLG
I finally finished my little tool (had to synchronize/translate 2 subtitles) with your help. I only had to modify the callback to manage 2 editor gadgets and to move the setwindowcallback after the lines that create the editor gadgets, cause i had a "#gadget not initialised" error instead.
Thanks tranquil for the explanations and coders for sharing their hints

Posted: Tue Nov 07, 2006 4:51 pm
by omit59
Hello!
I've been trying to use this and had strange problem when using many lines. When POINT structure from #EM_GETSCROLLPOS reaches value of 65535, #EM_SETSCROLLPOS doesn't give right value to the other editor any more! Mayby someone could explain what is happening?
Code: Select all
Procedure Callback(hwnd, msg, wparam, lparam)
result = #PB_ProcessPureBasicEvents
If msg=#WM_COMMAND
If IsGadget(1)
If lparam = GadgetID(1)
If wparam >> 16 = 1024 ; EN_UPDATE
SendMessage_(GadgetID(1), #EM_GETSCROLLPOS, 0, @pt.point)
SendMessage_(GadgetID(0), #EM_SETSCROLLPOS, 0, @pt)
EndIf
EndIf
EndIf
result = 0
EndIf
ProcedureReturn result
EndProcedure
If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
SetWindowCallback(@Callback())
ContainerGadget(2,5,5,50,133)
EditorGadget(0, 5, 5, 65, 133)
CloseGadgetList()
EditorGadget(1, 60, 10, 250, 133)
For a = 0 To 10000
AddGadgetItem(0, a, Str(a))
AddGadgetItem(1, a, "Line "+Str(a))
Next
Repeat : Until WaitWindowEvent()=#WM_CLOSE
EndIf
End
Timo
Posted: Tue Nov 07, 2006 5:20 pm
by srod
I will have a guess that the #WM_SETSCROLL message is using (internally) #WM_VSCROLL and #WM_HSCROLL messages etc. Now both of these only use 16 bit scroll positions (hence the 65535) max range etc.
To use 32 bit scroll ranges you will perhaps need to adopt a different method.
I am not certain that this is the root cause of your problem, but it sounds a likely candidate!
