Solved

Problem with GetScrollInfo

Posted on 2008-06-18
26
1,568 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
  • 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now