Get scrolling direction of another window/application
I want to detect the scrolling direction of another application. I am able to do so if the user scrolls through Mouse Wheel or Keyboard (Up/Down/Left/Right keys) through hooks. But I am not able to capture the same when the user uses the scrollbars present on the applications like Chrome.
I've tried below native method, but it does not work for many applications like chrome and works for Notepad++, as it is not able to detect scroll bars for chrome. I want something that works for all the applications.
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetScrollInfo(IntPtr hwnd, int fnBar, ref SCROLLINFO lpsi);
I have quite a bit of research but could not find anything that could give me the directions in which the page is scrolling.
Please let me know if any further information is required.
Update:
I am trying to use UI Automation to get the scroll bar information for Chrome.
Here's how?
I have made a collection of windows Gui Rectangles using EnumChildWindows
, which retrieved child controls as well. Based upon the mouse position, have selected the window handle whose Gui Rectangle contains my mouse position. The handle I obtained had the Gui Rectangle = chrome's client area.
Problem:
Below is the code. And it gives me an empty collection in elementCollection
in case of Chrome and successfully returns 2 scroll bar elements in case of Notepad++.
var element = AutomationElement.FromHandle(handle);
if(element != null)
{
Condition condition =
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ScrollBar);
// Find all children that match the specified conditions.
AutomationElementCollection elementCollection =
element.FindAll(TreeScope.SubTree, condition);
}
c# windows winapi ui-automation microsoft-ui-automation
add a comment |
I want to detect the scrolling direction of another application. I am able to do so if the user scrolls through Mouse Wheel or Keyboard (Up/Down/Left/Right keys) through hooks. But I am not able to capture the same when the user uses the scrollbars present on the applications like Chrome.
I've tried below native method, but it does not work for many applications like chrome and works for Notepad++, as it is not able to detect scroll bars for chrome. I want something that works for all the applications.
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetScrollInfo(IntPtr hwnd, int fnBar, ref SCROLLINFO lpsi);
I have quite a bit of research but could not find anything that could give me the directions in which the page is scrolling.
Please let me know if any further information is required.
Update:
I am trying to use UI Automation to get the scroll bar information for Chrome.
Here's how?
I have made a collection of windows Gui Rectangles using EnumChildWindows
, which retrieved child controls as well. Based upon the mouse position, have selected the window handle whose Gui Rectangle contains my mouse position. The handle I obtained had the Gui Rectangle = chrome's client area.
Problem:
Below is the code. And it gives me an empty collection in elementCollection
in case of Chrome and successfully returns 2 scroll bar elements in case of Notepad++.
var element = AutomationElement.FromHandle(handle);
if(element != null)
{
Condition condition =
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ScrollBar);
// Find all children that match the specified conditions.
AutomationElementCollection elementCollection =
element.FindAll(TreeScope.SubTree, condition);
}
c# windows winapi ui-automation microsoft-ui-automation
What would you use this information to do? Are you sure you're thinking about your problem at the right level? E.g. if this is some sort of accessibility tool, there are higher level ways of interacting with other applications that let you work at a more "semantic" level than trying to analyse scroll movements yourself.
– Damien_The_Unbeliever
Nov 14 '18 at 9:45
I want to do a panoramic capture for applications. User can go to the application and scroll, and I would be taking screen shots, and later would be combining all the screenshots to make a single image. The requirement is such that the user has to manually scroll, and I can't useSendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
to simulate scroll bar movements.
– shruti singh
Nov 14 '18 at 10:54
add a comment |
I want to detect the scrolling direction of another application. I am able to do so if the user scrolls through Mouse Wheel or Keyboard (Up/Down/Left/Right keys) through hooks. But I am not able to capture the same when the user uses the scrollbars present on the applications like Chrome.
I've tried below native method, but it does not work for many applications like chrome and works for Notepad++, as it is not able to detect scroll bars for chrome. I want something that works for all the applications.
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetScrollInfo(IntPtr hwnd, int fnBar, ref SCROLLINFO lpsi);
I have quite a bit of research but could not find anything that could give me the directions in which the page is scrolling.
Please let me know if any further information is required.
Update:
I am trying to use UI Automation to get the scroll bar information for Chrome.
Here's how?
I have made a collection of windows Gui Rectangles using EnumChildWindows
, which retrieved child controls as well. Based upon the mouse position, have selected the window handle whose Gui Rectangle contains my mouse position. The handle I obtained had the Gui Rectangle = chrome's client area.
Problem:
Below is the code. And it gives me an empty collection in elementCollection
in case of Chrome and successfully returns 2 scroll bar elements in case of Notepad++.
var element = AutomationElement.FromHandle(handle);
if(element != null)
{
Condition condition =
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ScrollBar);
// Find all children that match the specified conditions.
AutomationElementCollection elementCollection =
element.FindAll(TreeScope.SubTree, condition);
}
c# windows winapi ui-automation microsoft-ui-automation
I want to detect the scrolling direction of another application. I am able to do so if the user scrolls through Mouse Wheel or Keyboard (Up/Down/Left/Right keys) through hooks. But I am not able to capture the same when the user uses the scrollbars present on the applications like Chrome.
I've tried below native method, but it does not work for many applications like chrome and works for Notepad++, as it is not able to detect scroll bars for chrome. I want something that works for all the applications.
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetScrollInfo(IntPtr hwnd, int fnBar, ref SCROLLINFO lpsi);
I have quite a bit of research but could not find anything that could give me the directions in which the page is scrolling.
Please let me know if any further information is required.
Update:
I am trying to use UI Automation to get the scroll bar information for Chrome.
Here's how?
I have made a collection of windows Gui Rectangles using EnumChildWindows
, which retrieved child controls as well. Based upon the mouse position, have selected the window handle whose Gui Rectangle contains my mouse position. The handle I obtained had the Gui Rectangle = chrome's client area.
Problem:
Below is the code. And it gives me an empty collection in elementCollection
in case of Chrome and successfully returns 2 scroll bar elements in case of Notepad++.
var element = AutomationElement.FromHandle(handle);
if(element != null)
{
Condition condition =
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ScrollBar);
// Find all children that match the specified conditions.
AutomationElementCollection elementCollection =
element.FindAll(TreeScope.SubTree, condition);
}
c# windows winapi ui-automation microsoft-ui-automation
c# windows winapi ui-automation microsoft-ui-automation
edited Nov 15 '18 at 6:51
shruti singh
asked Nov 14 '18 at 7:25
shruti singhshruti singh
608
608
What would you use this information to do? Are you sure you're thinking about your problem at the right level? E.g. if this is some sort of accessibility tool, there are higher level ways of interacting with other applications that let you work at a more "semantic" level than trying to analyse scroll movements yourself.
– Damien_The_Unbeliever
Nov 14 '18 at 9:45
I want to do a panoramic capture for applications. User can go to the application and scroll, and I would be taking screen shots, and later would be combining all the screenshots to make a single image. The requirement is such that the user has to manually scroll, and I can't useSendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
to simulate scroll bar movements.
– shruti singh
Nov 14 '18 at 10:54
add a comment |
What would you use this information to do? Are you sure you're thinking about your problem at the right level? E.g. if this is some sort of accessibility tool, there are higher level ways of interacting with other applications that let you work at a more "semantic" level than trying to analyse scroll movements yourself.
– Damien_The_Unbeliever
Nov 14 '18 at 9:45
I want to do a panoramic capture for applications. User can go to the application and scroll, and I would be taking screen shots, and later would be combining all the screenshots to make a single image. The requirement is such that the user has to manually scroll, and I can't useSendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
to simulate scroll bar movements.
– shruti singh
Nov 14 '18 at 10:54
What would you use this information to do? Are you sure you're thinking about your problem at the right level? E.g. if this is some sort of accessibility tool, there are higher level ways of interacting with other applications that let you work at a more "semantic" level than trying to analyse scroll movements yourself.
– Damien_The_Unbeliever
Nov 14 '18 at 9:45
What would you use this information to do? Are you sure you're thinking about your problem at the right level? E.g. if this is some sort of accessibility tool, there are higher level ways of interacting with other applications that let you work at a more "semantic" level than trying to analyse scroll movements yourself.
– Damien_The_Unbeliever
Nov 14 '18 at 9:45
I want to do a panoramic capture for applications. User can go to the application and scroll, and I would be taking screen shots, and later would be combining all the screenshots to make a single image. The requirement is such that the user has to manually scroll, and I can't use
SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
to simulate scroll bar movements.– shruti singh
Nov 14 '18 at 10:54
I want to do a panoramic capture for applications. User can go to the application and scroll, and I would be taking screen shots, and later would be combining all the screenshots to make a single image. The requirement is such that the user has to manually scroll, and I can't use
SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
to simulate scroll bar movements.– shruti singh
Nov 14 '18 at 10:54
add a comment |
1 Answer
1
active
oldest
votes
What you need to do is call the GetScrollInfo
method twice and compare those values to find out; whether the control is being scrolled and to calculate (previous < current) the direction. You need to repeat this process as long as you want to keep monitoring the scrolling direction.
Now you should create some kind of worker class to handle things nicely, for the purpose of this question I've used a simple Console application that polls the SCROLLINFO
structure of the handle using a while-loop:
static void Main(string args)
{
var handle = (IntPtr)0x35087C; // notepad textbox handle
var prevInfo = default(SCROLLINFO);
int iterations = 1000;
while (iterations > 0)
{
var curInfo = new SCROLLINFO();
curInfo.cbSize = Marshal.SizeOf(curInfo);
curInfo.fMask = (int)ScrollInfoMask.SIF_ALL;
if (GetScrollInfo(handle, (int)ScrollBarDirection.SB_VERT, ref curInfo))
{
var dir = curInfo.nPos < prevInfo.nPos ? "Up" : "Down";
dir = curInfo.nPos == prevInfo.nPos ? "Unchanged" : dir;
Console.WriteLine(dir);
prevInfo = curInfo;
}
else
{
Console.WriteLine($"No scrolling.. {Marshal.GetLastWin32Error()}");
}
System.Threading.Thread.Sleep(100);
iterations--;
}
Console.ReadLine();
}
Note that the handle
variable contains the pointer to the textbox of a notepad process (which is NOT the same as the handle to the notepad process). I've used WinSpy++ to retrieve the handle from the notepad process.
I've used the GetScrollInfo MSDN page to read about the API call itself, GetScrollInfo Pinvoke.NET page to obtain all the required structs/enums.
Can you please try for chrome? Your solution gave me 1447 error for chrome. Some application's do not respond to GetScrollInfo and give error 1447 which is ERROR_NO_SCROLLBARS aka "The window does not have scroll bars". experts-exchange.com/questions/23496918/…
– shruti singh
Nov 14 '18 at 10:47
@shrutisingh Jevgeni has already done the heavy lifting of showing you how to do the task. You need to get your specifics yourself. Even if he did it with chrome, you will not get the same result because each process has it's own handle and you having the exact same handle as Jevgeni would be a major coincidence. As for why the method isn't working in chrome's instance the obvious answer would be you've got the wrong instance. My guess would be you're checking the main chrome instance instead of renderer which it's likely happening.
– Maverik
Nov 14 '18 at 11:03
@Maverik My issue is this only that this logic does not work for all the child handles. I am aware that this works for Notepad as I had already tried it. In case of chrome, I replaced the handle with the child handle of chrome, and it is not able to get the scroll info. And I am getting the child handle throughEnumChildWindows
which is correct as I am able to simulateSendMessage(IntPtr hWnd, int Msg, int wParam, int lParam)
using the same handle.
– shruti singh
Nov 14 '18 at 11:08
You should've added that you where targeting chrome, this is crucial information that is missing from your main post. Chrome uses D3D (DirectX 3D) rendering which is a whole lot different in comparison with a simple control, like notepads' textbox. Knowing this I doubt you can use theGetScrollInfo
API. You need to hook chrome and find out where they store the scroll information in-memory and work from there.
– Jevgeni Geurtsen
Nov 14 '18 at 11:12
1
@mav: That all sounds convincing, except, it's wrong. Chrome doesn't use native windows for anything (other than a frame window and a rendering host). Everything you see, however, is done using custom widget implementations. The scrollbars may look like native scrollbars, but they aren't either one of the two types of scrollbars. As such, they will not respond to messages or the regular windowing API. You have to go for a different solution here, e.g. UI Automation.
– IInspectable
Nov 14 '18 at 11:16
|
show 7 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53295018%2fget-scrolling-direction-of-another-window-application%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
What you need to do is call the GetScrollInfo
method twice and compare those values to find out; whether the control is being scrolled and to calculate (previous < current) the direction. You need to repeat this process as long as you want to keep monitoring the scrolling direction.
Now you should create some kind of worker class to handle things nicely, for the purpose of this question I've used a simple Console application that polls the SCROLLINFO
structure of the handle using a while-loop:
static void Main(string args)
{
var handle = (IntPtr)0x35087C; // notepad textbox handle
var prevInfo = default(SCROLLINFO);
int iterations = 1000;
while (iterations > 0)
{
var curInfo = new SCROLLINFO();
curInfo.cbSize = Marshal.SizeOf(curInfo);
curInfo.fMask = (int)ScrollInfoMask.SIF_ALL;
if (GetScrollInfo(handle, (int)ScrollBarDirection.SB_VERT, ref curInfo))
{
var dir = curInfo.nPos < prevInfo.nPos ? "Up" : "Down";
dir = curInfo.nPos == prevInfo.nPos ? "Unchanged" : dir;
Console.WriteLine(dir);
prevInfo = curInfo;
}
else
{
Console.WriteLine($"No scrolling.. {Marshal.GetLastWin32Error()}");
}
System.Threading.Thread.Sleep(100);
iterations--;
}
Console.ReadLine();
}
Note that the handle
variable contains the pointer to the textbox of a notepad process (which is NOT the same as the handle to the notepad process). I've used WinSpy++ to retrieve the handle from the notepad process.
I've used the GetScrollInfo MSDN page to read about the API call itself, GetScrollInfo Pinvoke.NET page to obtain all the required structs/enums.
Can you please try for chrome? Your solution gave me 1447 error for chrome. Some application's do not respond to GetScrollInfo and give error 1447 which is ERROR_NO_SCROLLBARS aka "The window does not have scroll bars". experts-exchange.com/questions/23496918/…
– shruti singh
Nov 14 '18 at 10:47
@shrutisingh Jevgeni has already done the heavy lifting of showing you how to do the task. You need to get your specifics yourself. Even if he did it with chrome, you will not get the same result because each process has it's own handle and you having the exact same handle as Jevgeni would be a major coincidence. As for why the method isn't working in chrome's instance the obvious answer would be you've got the wrong instance. My guess would be you're checking the main chrome instance instead of renderer which it's likely happening.
– Maverik
Nov 14 '18 at 11:03
@Maverik My issue is this only that this logic does not work for all the child handles. I am aware that this works for Notepad as I had already tried it. In case of chrome, I replaced the handle with the child handle of chrome, and it is not able to get the scroll info. And I am getting the child handle throughEnumChildWindows
which is correct as I am able to simulateSendMessage(IntPtr hWnd, int Msg, int wParam, int lParam)
using the same handle.
– shruti singh
Nov 14 '18 at 11:08
You should've added that you where targeting chrome, this is crucial information that is missing from your main post. Chrome uses D3D (DirectX 3D) rendering which is a whole lot different in comparison with a simple control, like notepads' textbox. Knowing this I doubt you can use theGetScrollInfo
API. You need to hook chrome and find out where they store the scroll information in-memory and work from there.
– Jevgeni Geurtsen
Nov 14 '18 at 11:12
1
@mav: That all sounds convincing, except, it's wrong. Chrome doesn't use native windows for anything (other than a frame window and a rendering host). Everything you see, however, is done using custom widget implementations. The scrollbars may look like native scrollbars, but they aren't either one of the two types of scrollbars. As such, they will not respond to messages or the regular windowing API. You have to go for a different solution here, e.g. UI Automation.
– IInspectable
Nov 14 '18 at 11:16
|
show 7 more comments
What you need to do is call the GetScrollInfo
method twice and compare those values to find out; whether the control is being scrolled and to calculate (previous < current) the direction. You need to repeat this process as long as you want to keep monitoring the scrolling direction.
Now you should create some kind of worker class to handle things nicely, for the purpose of this question I've used a simple Console application that polls the SCROLLINFO
structure of the handle using a while-loop:
static void Main(string args)
{
var handle = (IntPtr)0x35087C; // notepad textbox handle
var prevInfo = default(SCROLLINFO);
int iterations = 1000;
while (iterations > 0)
{
var curInfo = new SCROLLINFO();
curInfo.cbSize = Marshal.SizeOf(curInfo);
curInfo.fMask = (int)ScrollInfoMask.SIF_ALL;
if (GetScrollInfo(handle, (int)ScrollBarDirection.SB_VERT, ref curInfo))
{
var dir = curInfo.nPos < prevInfo.nPos ? "Up" : "Down";
dir = curInfo.nPos == prevInfo.nPos ? "Unchanged" : dir;
Console.WriteLine(dir);
prevInfo = curInfo;
}
else
{
Console.WriteLine($"No scrolling.. {Marshal.GetLastWin32Error()}");
}
System.Threading.Thread.Sleep(100);
iterations--;
}
Console.ReadLine();
}
Note that the handle
variable contains the pointer to the textbox of a notepad process (which is NOT the same as the handle to the notepad process). I've used WinSpy++ to retrieve the handle from the notepad process.
I've used the GetScrollInfo MSDN page to read about the API call itself, GetScrollInfo Pinvoke.NET page to obtain all the required structs/enums.
Can you please try for chrome? Your solution gave me 1447 error for chrome. Some application's do not respond to GetScrollInfo and give error 1447 which is ERROR_NO_SCROLLBARS aka "The window does not have scroll bars". experts-exchange.com/questions/23496918/…
– shruti singh
Nov 14 '18 at 10:47
@shrutisingh Jevgeni has already done the heavy lifting of showing you how to do the task. You need to get your specifics yourself. Even if he did it with chrome, you will not get the same result because each process has it's own handle and you having the exact same handle as Jevgeni would be a major coincidence. As for why the method isn't working in chrome's instance the obvious answer would be you've got the wrong instance. My guess would be you're checking the main chrome instance instead of renderer which it's likely happening.
– Maverik
Nov 14 '18 at 11:03
@Maverik My issue is this only that this logic does not work for all the child handles. I am aware that this works for Notepad as I had already tried it. In case of chrome, I replaced the handle with the child handle of chrome, and it is not able to get the scroll info. And I am getting the child handle throughEnumChildWindows
which is correct as I am able to simulateSendMessage(IntPtr hWnd, int Msg, int wParam, int lParam)
using the same handle.
– shruti singh
Nov 14 '18 at 11:08
You should've added that you where targeting chrome, this is crucial information that is missing from your main post. Chrome uses D3D (DirectX 3D) rendering which is a whole lot different in comparison with a simple control, like notepads' textbox. Knowing this I doubt you can use theGetScrollInfo
API. You need to hook chrome and find out where they store the scroll information in-memory and work from there.
– Jevgeni Geurtsen
Nov 14 '18 at 11:12
1
@mav: That all sounds convincing, except, it's wrong. Chrome doesn't use native windows for anything (other than a frame window and a rendering host). Everything you see, however, is done using custom widget implementations. The scrollbars may look like native scrollbars, but they aren't either one of the two types of scrollbars. As such, they will not respond to messages or the regular windowing API. You have to go for a different solution here, e.g. UI Automation.
– IInspectable
Nov 14 '18 at 11:16
|
show 7 more comments
What you need to do is call the GetScrollInfo
method twice and compare those values to find out; whether the control is being scrolled and to calculate (previous < current) the direction. You need to repeat this process as long as you want to keep monitoring the scrolling direction.
Now you should create some kind of worker class to handle things nicely, for the purpose of this question I've used a simple Console application that polls the SCROLLINFO
structure of the handle using a while-loop:
static void Main(string args)
{
var handle = (IntPtr)0x35087C; // notepad textbox handle
var prevInfo = default(SCROLLINFO);
int iterations = 1000;
while (iterations > 0)
{
var curInfo = new SCROLLINFO();
curInfo.cbSize = Marshal.SizeOf(curInfo);
curInfo.fMask = (int)ScrollInfoMask.SIF_ALL;
if (GetScrollInfo(handle, (int)ScrollBarDirection.SB_VERT, ref curInfo))
{
var dir = curInfo.nPos < prevInfo.nPos ? "Up" : "Down";
dir = curInfo.nPos == prevInfo.nPos ? "Unchanged" : dir;
Console.WriteLine(dir);
prevInfo = curInfo;
}
else
{
Console.WriteLine($"No scrolling.. {Marshal.GetLastWin32Error()}");
}
System.Threading.Thread.Sleep(100);
iterations--;
}
Console.ReadLine();
}
Note that the handle
variable contains the pointer to the textbox of a notepad process (which is NOT the same as the handle to the notepad process). I've used WinSpy++ to retrieve the handle from the notepad process.
I've used the GetScrollInfo MSDN page to read about the API call itself, GetScrollInfo Pinvoke.NET page to obtain all the required structs/enums.
What you need to do is call the GetScrollInfo
method twice and compare those values to find out; whether the control is being scrolled and to calculate (previous < current) the direction. You need to repeat this process as long as you want to keep monitoring the scrolling direction.
Now you should create some kind of worker class to handle things nicely, for the purpose of this question I've used a simple Console application that polls the SCROLLINFO
structure of the handle using a while-loop:
static void Main(string args)
{
var handle = (IntPtr)0x35087C; // notepad textbox handle
var prevInfo = default(SCROLLINFO);
int iterations = 1000;
while (iterations > 0)
{
var curInfo = new SCROLLINFO();
curInfo.cbSize = Marshal.SizeOf(curInfo);
curInfo.fMask = (int)ScrollInfoMask.SIF_ALL;
if (GetScrollInfo(handle, (int)ScrollBarDirection.SB_VERT, ref curInfo))
{
var dir = curInfo.nPos < prevInfo.nPos ? "Up" : "Down";
dir = curInfo.nPos == prevInfo.nPos ? "Unchanged" : dir;
Console.WriteLine(dir);
prevInfo = curInfo;
}
else
{
Console.WriteLine($"No scrolling.. {Marshal.GetLastWin32Error()}");
}
System.Threading.Thread.Sleep(100);
iterations--;
}
Console.ReadLine();
}
Note that the handle
variable contains the pointer to the textbox of a notepad process (which is NOT the same as the handle to the notepad process). I've used WinSpy++ to retrieve the handle from the notepad process.
I've used the GetScrollInfo MSDN page to read about the API call itself, GetScrollInfo Pinvoke.NET page to obtain all the required structs/enums.
edited Nov 15 '18 at 7:56
Ashish Kamble
632519
632519
answered Nov 14 '18 at 10:17
Jevgeni GeurtsenJevgeni Geurtsen
2,61141232
2,61141232
Can you please try for chrome? Your solution gave me 1447 error for chrome. Some application's do not respond to GetScrollInfo and give error 1447 which is ERROR_NO_SCROLLBARS aka "The window does not have scroll bars". experts-exchange.com/questions/23496918/…
– shruti singh
Nov 14 '18 at 10:47
@shrutisingh Jevgeni has already done the heavy lifting of showing you how to do the task. You need to get your specifics yourself. Even if he did it with chrome, you will not get the same result because each process has it's own handle and you having the exact same handle as Jevgeni would be a major coincidence. As for why the method isn't working in chrome's instance the obvious answer would be you've got the wrong instance. My guess would be you're checking the main chrome instance instead of renderer which it's likely happening.
– Maverik
Nov 14 '18 at 11:03
@Maverik My issue is this only that this logic does not work for all the child handles. I am aware that this works for Notepad as I had already tried it. In case of chrome, I replaced the handle with the child handle of chrome, and it is not able to get the scroll info. And I am getting the child handle throughEnumChildWindows
which is correct as I am able to simulateSendMessage(IntPtr hWnd, int Msg, int wParam, int lParam)
using the same handle.
– shruti singh
Nov 14 '18 at 11:08
You should've added that you where targeting chrome, this is crucial information that is missing from your main post. Chrome uses D3D (DirectX 3D) rendering which is a whole lot different in comparison with a simple control, like notepads' textbox. Knowing this I doubt you can use theGetScrollInfo
API. You need to hook chrome and find out where they store the scroll information in-memory and work from there.
– Jevgeni Geurtsen
Nov 14 '18 at 11:12
1
@mav: That all sounds convincing, except, it's wrong. Chrome doesn't use native windows for anything (other than a frame window and a rendering host). Everything you see, however, is done using custom widget implementations. The scrollbars may look like native scrollbars, but they aren't either one of the two types of scrollbars. As such, they will not respond to messages or the regular windowing API. You have to go for a different solution here, e.g. UI Automation.
– IInspectable
Nov 14 '18 at 11:16
|
show 7 more comments
Can you please try for chrome? Your solution gave me 1447 error for chrome. Some application's do not respond to GetScrollInfo and give error 1447 which is ERROR_NO_SCROLLBARS aka "The window does not have scroll bars". experts-exchange.com/questions/23496918/…
– shruti singh
Nov 14 '18 at 10:47
@shrutisingh Jevgeni has already done the heavy lifting of showing you how to do the task. You need to get your specifics yourself. Even if he did it with chrome, you will not get the same result because each process has it's own handle and you having the exact same handle as Jevgeni would be a major coincidence. As for why the method isn't working in chrome's instance the obvious answer would be you've got the wrong instance. My guess would be you're checking the main chrome instance instead of renderer which it's likely happening.
– Maverik
Nov 14 '18 at 11:03
@Maverik My issue is this only that this logic does not work for all the child handles. I am aware that this works for Notepad as I had already tried it. In case of chrome, I replaced the handle with the child handle of chrome, and it is not able to get the scroll info. And I am getting the child handle throughEnumChildWindows
which is correct as I am able to simulateSendMessage(IntPtr hWnd, int Msg, int wParam, int lParam)
using the same handle.
– shruti singh
Nov 14 '18 at 11:08
You should've added that you where targeting chrome, this is crucial information that is missing from your main post. Chrome uses D3D (DirectX 3D) rendering which is a whole lot different in comparison with a simple control, like notepads' textbox. Knowing this I doubt you can use theGetScrollInfo
API. You need to hook chrome and find out where they store the scroll information in-memory and work from there.
– Jevgeni Geurtsen
Nov 14 '18 at 11:12
1
@mav: That all sounds convincing, except, it's wrong. Chrome doesn't use native windows for anything (other than a frame window and a rendering host). Everything you see, however, is done using custom widget implementations. The scrollbars may look like native scrollbars, but they aren't either one of the two types of scrollbars. As such, they will not respond to messages or the regular windowing API. You have to go for a different solution here, e.g. UI Automation.
– IInspectable
Nov 14 '18 at 11:16
Can you please try for chrome? Your solution gave me 1447 error for chrome. Some application's do not respond to GetScrollInfo and give error 1447 which is ERROR_NO_SCROLLBARS aka "The window does not have scroll bars". experts-exchange.com/questions/23496918/…
– shruti singh
Nov 14 '18 at 10:47
Can you please try for chrome? Your solution gave me 1447 error for chrome. Some application's do not respond to GetScrollInfo and give error 1447 which is ERROR_NO_SCROLLBARS aka "The window does not have scroll bars". experts-exchange.com/questions/23496918/…
– shruti singh
Nov 14 '18 at 10:47
@shrutisingh Jevgeni has already done the heavy lifting of showing you how to do the task. You need to get your specifics yourself. Even if he did it with chrome, you will not get the same result because each process has it's own handle and you having the exact same handle as Jevgeni would be a major coincidence. As for why the method isn't working in chrome's instance the obvious answer would be you've got the wrong instance. My guess would be you're checking the main chrome instance instead of renderer which it's likely happening.
– Maverik
Nov 14 '18 at 11:03
@shrutisingh Jevgeni has already done the heavy lifting of showing you how to do the task. You need to get your specifics yourself. Even if he did it with chrome, you will not get the same result because each process has it's own handle and you having the exact same handle as Jevgeni would be a major coincidence. As for why the method isn't working in chrome's instance the obvious answer would be you've got the wrong instance. My guess would be you're checking the main chrome instance instead of renderer which it's likely happening.
– Maverik
Nov 14 '18 at 11:03
@Maverik My issue is this only that this logic does not work for all the child handles. I am aware that this works for Notepad as I had already tried it. In case of chrome, I replaced the handle with the child handle of chrome, and it is not able to get the scroll info. And I am getting the child handle through
EnumChildWindows
which is correct as I am able to simulate SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam)
using the same handle.– shruti singh
Nov 14 '18 at 11:08
@Maverik My issue is this only that this logic does not work for all the child handles. I am aware that this works for Notepad as I had already tried it. In case of chrome, I replaced the handle with the child handle of chrome, and it is not able to get the scroll info. And I am getting the child handle through
EnumChildWindows
which is correct as I am able to simulate SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam)
using the same handle.– shruti singh
Nov 14 '18 at 11:08
You should've added that you where targeting chrome, this is crucial information that is missing from your main post. Chrome uses D3D (DirectX 3D) rendering which is a whole lot different in comparison with a simple control, like notepads' textbox. Knowing this I doubt you can use the
GetScrollInfo
API. You need to hook chrome and find out where they store the scroll information in-memory and work from there.– Jevgeni Geurtsen
Nov 14 '18 at 11:12
You should've added that you where targeting chrome, this is crucial information that is missing from your main post. Chrome uses D3D (DirectX 3D) rendering which is a whole lot different in comparison with a simple control, like notepads' textbox. Knowing this I doubt you can use the
GetScrollInfo
API. You need to hook chrome and find out where they store the scroll information in-memory and work from there.– Jevgeni Geurtsen
Nov 14 '18 at 11:12
1
1
@mav: That all sounds convincing, except, it's wrong. Chrome doesn't use native windows for anything (other than a frame window and a rendering host). Everything you see, however, is done using custom widget implementations. The scrollbars may look like native scrollbars, but they aren't either one of the two types of scrollbars. As such, they will not respond to messages or the regular windowing API. You have to go for a different solution here, e.g. UI Automation.
– IInspectable
Nov 14 '18 at 11:16
@mav: That all sounds convincing, except, it's wrong. Chrome doesn't use native windows for anything (other than a frame window and a rendering host). Everything you see, however, is done using custom widget implementations. The scrollbars may look like native scrollbars, but they aren't either one of the two types of scrollbars. As such, they will not respond to messages or the regular windowing API. You have to go for a different solution here, e.g. UI Automation.
– IInspectable
Nov 14 '18 at 11:16
|
show 7 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53295018%2fget-scrolling-direction-of-another-window-application%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What would you use this information to do? Are you sure you're thinking about your problem at the right level? E.g. if this is some sort of accessibility tool, there are higher level ways of interacting with other applications that let you work at a more "semantic" level than trying to analyse scroll movements yourself.
– Damien_The_Unbeliever
Nov 14 '18 at 9:45
I want to do a panoramic capture for applications. User can go to the application and scroll, and I would be taking screen shots, and later would be combining all the screenshots to make a single image. The requirement is such that the user has to manually scroll, and I can't use
SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
to simulate scroll bar movements.– shruti singh
Nov 14 '18 at 10:54