Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine position of thumb in a grid scrollbar? 1

Status
Not open for further replies.

awaresoft

Programmer
Joined
Feb 16, 2002
Messages
373
Location
DE
Is it possible to determine the position of the thumb control in a grid scrollbar?

I can trap the Scroll event and get the mouse's position to determine an approximate location. But this only works when the thumb is manually moved via the mouse.

A hack would be to use the Form.Point() function to search the length of a scrollbar looking for the edge of the thumb but this seems terribly inefficient and I'm not sure if there's a consistent thumb edge color across different versions of Windows or even different XP themes. (The mouse cursor may also interfere with this approach as well?)

I checked News2News.com for an API solution and couldn't find anything.

Any other ideas? (SYS, SET command, or a FOXTOOLS API?)

Malcolm
 
Hi Malcom,

Just what is a "thumb" control?

Regards,

Mike
 
Hi Mike,

The thumb is the "do-hickey" that you can click and drag in a scrollbar to change scrollbar position. It is positioned between the scroll arrows. As you page through a list or grid with a vertical scrollbar, the thumb will indicate your relative position within the list of items.

Does this help?

Malcolm
 
Hi Malcom,

Just hadn't heard of the thumb before and Help returned nothing. I'd have called it the Resize.

You should be able to get is's position with a combination of .width .height, .left .top, and _sysmetrics (for scrollbar width/height).

Regards,

Mike
 
Mike,

VFP maintains the position of the "thumb" as you scroll through a list of when you click one of the scrollbar arrows to scroll a list or grid.

I'm trying to determine exactly where VFP has dynamically positioned thumb. By "where" I mean the vertical pixel coordinate on the screen. The .height, .left and .top properties have static values and aren't updated by when a scrollbar thumb is moved. Sysmetric() provides info on the size of the scrollbar arrows (and indirectly the size of the thumb itself), but does not provide info on the current thumb position.

Malcolm
 
Hi malcom,

Doh! Now I understand whtat you mean by the "Thumb". It's height would also be affected by the total % of max visible.

Why do you need to know this?

Regards,

Mike
 
Mike,

A customer has asked if I could place some status information to the right of the thumb - basically a small caption control that would move in parallel (in synch) with the thumb.

I know there's a zillion other ways to provide status info (tooltips, statusbar, stationary caption, dynamiccolor/font effects), but my app is replacing a Flash based front end where the original developer did a nice job implementing a similar interface - an interface that my customers love. My goal is to match the original visual interface as closely as possible.

Confession: Right or wrong, it would kill me to concede that this is one of those things that VFP just can't do. ;)

Malcolm
 
awaresoft,

I believe you were on the right track with your Point idea. API's aren't the answer since the grid and the scrollbar are just images and there aren't any hwnds to be had (throw back to the days of Foxpro being a multi-platform solution... they just rendered images so everything looked the similar on the different platforms - MAC for instance) Doesn't matter what color stuff is, the scroll slider button will be different than the background of the scrollbar, even if it is just it's outline that is different. Here's a working example, though there are a couple of things that will need to be shored up... I'm hard pressed for time today or I would mess with some more. Should give you the basic idea and perhaps a solution to your problem. Cut-N-Paste the code below into a prg and run it from within VFP.
Code:
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN

DEFINE CLASS form1 AS form

	Top = 0
	Left = 0
	Height = 250
	Width = 419
	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"

	ADD OBJECT grid1 AS grid WITH ;
		ColumnCount = 1, ;
		Height = 168, ;
		Left = 24, ;
		Top = 24, ;
		Width = 320, ;
		Name = "Grid1", ;
		Column1.Name = "Column1"

	ADD OBJECT label1 AS label WITH ;
		Caption = "Label1", ;
		Height = 17, ;
		Left = 348, ;
		Top = 96, ;
		Width = 40, ;
		Name = "Label1"

	PROCEDURE placelabel
		LOCAL lnPointColor, lnXCoord, lnYCoord
		lnXCoord = thisform.grid1.Left + thisform.grid1.Width - 5
		lnYCoord = thisform.grid1.Top + thisform.grid1.headerheight + 1

		lnPointColor = thisform.Point(lnXCoord, lnYCoord)
		SET escape on
		DO WHILE .T.
			lnYCoord = lnYCoord + 1
			IF thisform.Point(lnXCoord, lnYCoord) != lnPointColor
				thisform.label1.Top = lnYCoord
				thisform.label1.Caption = "<-- " + TRANSFORM(lnYCoord)
				EXIT
			ENDIF
		ENDDO
	ENDPROC
	
	PROCEDURE Init
		CREATE CURSOR crsNumbers (field1 I)
		FOR lnCounter = 1 TO 100
			INSERT INTO crsNumbers (field1) VALUES (lnCounter)
		ENDFOR
		GO TOP IN ("crsNumbers")
		this.grid1.RecordSource = "crsNumbers"
	ENDPROC

	PROCEDURE grid1.AfterRowColChange
		LPARAMETERS nColIndex
		thisform.placelabel()
	ENDPROC

	PROCEDURE grid1.Scrolled
		LPARAMETERS nDirection
		IF between(m.nDirection, 0, 3)
			thisform.placelabel()
		ENDIF
	ENDPROC

ENDDEFINE

boyd.gif

 
Craig,

AWESOME!!!

I've been experimenting with your code and it works great in 99% of the cases. I'm not sure there's a perfect solution because the way VFP manages its scrollbars is inconsistent and not always particulary accurate.

Thanks again for all your help today - on this thread and on the thread about dockable windows.

Best regards,

Malcolm
 
Mike(s),

I had to lookup the term "thumb" via google before I posted my original question. I've always called it "that do-hickey thing-of-a-bob", which, IMO, sounds like a more accurate description than thumb. :)

BTW: If you have a chance to run Craig's code, it a great example of monitoring the position of the thumb. Good stuff for your personal code toolboxes. Thanks again Craig!

Malcolm
 
Hi Mike,

Elevator sounds like a more apt description.

Hi Malcom,

The only program that I recall with this feature is Acrobat. When you used the mouse with the thumb it would pop up a window to show what page you would be on if you released the mouse.

Regards,

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top