Solved

Problem with GetScrollInfo

Posted on 2008-06-18
26
1,608 Views
Last Modified: 2013-12-03
Hi,

I want to scroll a window and get the position of the scrollbar. Here is my code:

var
  H: THandle;
  SInfo: TScrollInfo;
  I: Integer;
begin
  H := $10D6E;
  for I := 0 to 100 do
  begin
    SendMessage(H, WM_VSCROLL, SB_LINEDOWN, 0);
    SInfo.cbSize := SizeOf(SInfo);
    SInfo.fMask := SIF_TRACKPOS;
    GetScrollInfo(H, SB_THUMBPOSITION, SInfo);
    ListBox1.Items.Add(IntToStr(SInfo.nTrackPos));
  end;

But everytime I get still number (4509807) in the nTrackPos. How could GetScrollInfo used to get the current scroll position? The code is written in Delphi. I need to know how to get current wnidow position from GetScrollInfo function. The window that I'm trying this code is Internet Explorer.
0
Comment
Question by:Mamouri
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 14
  • 5
  • 4
26 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 21817530
The problem IMHO is the 2nd parameter - 'GetScrollInfo()' (http://msdn.microsoft.com/en-us/library/bb787583(VS.85).aspx) only takes the follwing values:

fnBar
[in] Specifies the type of scroll bar for which to retrieve parameters. This parameter can be one of the following values.
SB_CTL
Retrieves the parameters for a scroll bar control. The hwnd parameter must be the handle to the scroll bar control.
SB_HORZ
Retrieves the parameters for the window's standard horizontal scroll bar.
SB_VERT
Retrieves the parameters for the window's standard vertical scroll bar.

'SB_THUMBPOSITION' seems to be incorrect here.
0
 
LVL 3

Author Comment

by:Mamouri
ID: 21822770
Still the same problem. Here is my new code:

var
  H: THandle;
  SInfo: TScrollInfo;
  I: Integer;
begin
  H := $20684;
  for I := 0 to 100 do
  begin
    SendMessage(H, WM_VSCROLL, SB_LINEDOWN, 0);
    SInfo.cbSize := SizeOf(SInfo);
    SInfo.fMask := SB_THUMBTRACK;
    GetScrollInfo(H, SB_VERT, SInfo);
    ListBox1.Items.Add(IntToStr(SInfo.nTrackPos));
  end;
0
 
LVL 86

Expert Comment

by:jkr
ID: 21823335
What is the return value of the call and if it is not TRUE, what does 'GetLastError()' report?
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 3

Author Comment

by:Mamouri
ID: 21823873
Hi,

The function always return 4509671. The GetLastError always return 1447.
It's weired that 4509671 is the same for all Internet Explorer Windows.
0
 
LVL 86

Expert Comment

by:jkr
ID: 21823899
1447 is ERROR_NO_SCROLLBARS aka "The window does not have scroll bars" - are you sure the window handle is correct?
0
 
LVL 3

Author Comment

by:Mamouri
ID: 21823903
jkr, I actually want to reproduce Automatic Scrolling feature of a Screen Capture program called SnagIT.

Better solution or any comment is welcomed
0
 
LVL 3

Author Comment

by:Mamouri
ID: 21823917
Yes, I'm sure that the Internet Explorer has Scrollbars. When I send WM_VSCROLL message, Internet Explorer window, Scroll
0
 
LVL 86

Expert Comment

by:jkr
ID: 21823948
But is the handle the one of IE's top level window or one of its child windows? The error code is pretty distinct.
0
 
LVL 3

Author Comment

by:Mamouri
ID: 21824014
Hi,

It's handle of the Browser itself. The class of this window is "Internet Explorer_Server". The Internet Explorer itself has "IEFrame" class.

But it's weired that the scrollbar itself has not handle. I get the handle of the object using a tiny utility named WinID (winid.com) and as I see the scrollbar has not separate handle.
0
 
LVL 3

Author Comment

by:Mamouri
ID: 21824027
0
 
LVL 3

Author Comment

by:Mamouri
ID: 21824061
I used WinSpy (http://www.catch22.net/software/winspy.asp) to get list of child windows of "Internet Explorer_Server" window. the only child is "Internet Explorer_ObjectOverlay" class.

As you said, there is not any Scrollbar, But I'm sure that it's possible to get the current scrollbar position of the window and SnagIt do this very well. If you Auto Scroll a page a tiny window appear and show the current position of the scrollbar.
0
 
LVL 86

Expert Comment

by:jkr
ID: 21824135
BTW, why are you hard-coding the windows handle? Just use 'FindWindow()' to obtain the correct one.
0
 
LVL 3

Author Comment

by:Mamouri
ID: 21824221
It's just for testing purpose.
0
 
LVL 3

Author Comment

by:Mamouri
ID: 21832025
Listening ...
Points increased to 600
0
 
LVL 3

Author Comment

by:Mamouri
ID: 21832636
Grrr... It's impossible to increase question points more than 500
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 500 total points
ID: 21860796
As I understand it, IE similates scrollbars -- in the same way it does not create "real" windows for text input boxes and checkboxes, etc.

I think that your technique will work for programs such as NotePad, but not for IE.  For IE, I think the only method will be to access the browser's DOM.  Once a page is loaded, you can use methods such as
    get_pageYOffset
to obtain the current position and
    set_scrollTop( nPixels )
to scroll the page.
0
 
LVL 3

Author Comment

by:Mamouri
ID: 21864783
Hi DanRollins
Thank you very much for the answer. So it is not possible to get the Scrollbar position with windows standard API for IE Windows? What can I do for windows like Firefox or similar windows that didn't response to windows messages and also didn't provide DOM? There is not another solution than using DOM for solving this problem?

BTW how it's possible to get the DOM instance of the IE Window that I have it's Handle? I mean something like GetDom(H: THandle): IDOM
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 21869795
See
   How to get IHTMLDocument2 from a HWND
   http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q249232&
and
  How to connect to a running instance of Internet Explorer
  http://support.microsoft.com/kb/176792/
0
 
LVL 3

Author Comment

by:Mamouri
ID: 21893570
Hi DanRollins

Thank you for the links. I wondering how programs like SnagIt (http://www.techsmith.com/) and CaptureWizPro (http://www.pixelmetrics.com/CapWizPro/) could get the current position of the scroll bar. If you start a scrolling capture with Snagit you could see a small window showing the current position of the scrolling window.

What are their trick for getting current position of a scrolling window?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 21896954
Quite possibly, they do exactly that -- they see if it is browser window and take special action if so.
0
 
LVL 3

Author Comment

by:Mamouri
ID: 21897381
So what they do for other window? Snagit is able to handle all windows not only IE
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 21898164
Again guessing, but...
When it sees that a window has a scrollbar, it probably just uses the standard scrollbar manipulation API functions.
0
 
LVL 3

Author Comment

by:Mamouri
ID: 21898595
I don't think so. SnagIt could handle windows that did not support standard windows scrolling messages (i.e Mozilla Firefox window)

I think that use a special image comparison algorithm.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VS2015 compilation and missing DLLs 9 181
debug as  junit test 4 88
Slow process to read Excel 15 149
Error E2158 compiling with Delphi XE10 Seattle 2 127
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question