I want to use the attached code to get the X position of a trackbar pointer on the form, not its position on the trackbar. The code keeps producing the number 329 regardless of the actual position of the pointer. Can anyone see what I'm doing wrong?
uses Windows, CommCtrl, etc.
procedure TForm1.Button16Click(Sender: TObject);
var
ThumbRect: TRect;
ScreenPos: TPoint;
xpos,ypos:integer;
Result:TPoint;
tempstr:string;
begin
ZeroMemory(@ThumbRect, SizeOf(ThumbRect));
// Send message to get the thumb's rectangle relative to the TrackBar
SendMessage(TrackBar1.Handle, TBM_GETTHUMBRECT, 0, LPARAM(@ThumbRect));
// Get the center top point of the thumb relative to the TrackBar
ScreenPos := TrackBar1.ClientToScreen(Point(ThumbRect.Left + (ThumbRect.Width div 2), ThumbRect.Top));
// Convert the screen coordinates to client coordinates of the Form
Result := Form1.ScreenToClient(ScreenPos);
xpos := Result.X;
str(xpos,tempstr);
edit5.text := tempstr;
end;