Link to home
Start Free TrialLog in
Avatar of Mamouri
Mamouri

asked on

Problem with GetScrollInfo

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.
Avatar of jkr
jkr
Flag of Germany image

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.
Avatar of Mamouri
Mamouri

ASKER

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;
What is the return value of the call and if it is not TRUE, what does 'GetLastError()' report?
Avatar of Mamouri

ASKER

Hi,

The function always return 4509671. The GetLastError always return 1447.
It's weired that 4509671 is the same for all Internet Explorer Windows.
1447 is ERROR_NO_SCROLLBARS aka "The window does not have scroll bars" - are you sure the window handle is correct?
Avatar of Mamouri

ASKER

jkr, I actually want to reproduce Automatic Scrolling feature of a Screen Capture program called SnagIT.

Better solution or any comment is welcomed
Avatar of Mamouri

ASKER

Yes, I'm sure that the Internet Explorer has Scrollbars. When I send WM_VSCROLL message, Internet Explorer window, Scroll
But is the handle the one of IE's top level window or one of its child windows? The error code is pretty distinct.
Avatar of Mamouri

ASKER

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.
Avatar of Mamouri

ASKER

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.
BTW, why are you hard-coding the windows handle? Just use 'FindWindow()' to obtain the correct one.
Avatar of Mamouri

ASKER

It's just for testing purpose.
Avatar of Mamouri

ASKER

Listening ...
Points increased to 600
Avatar of Mamouri

ASKER

Grrr... It's impossible to increase question points more than 500
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mamouri

ASKER

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
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/
Avatar of Mamouri

ASKER

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?
Quite possibly, they do exactly that -- they see if it is browser window and take special action if so.
Avatar of Mamouri

ASKER

So what they do for other window? Snagit is able to handle all windows not only IE
Again guessing, but...
When it sees that a window has a scrollbar, it probably just uses the standard scrollbar manipulation API functions.
Avatar of Mamouri

ASKER

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.