Sign in to follow this  
Followers 0
Rawox

Scrolling window using DllCall

18 posts in this topic

#1 ·  Posted (edited)

Hi there,

I tried:

HotKeySet ( "{F8}", "_MouseClickPlus")

While 1
    Sleep ( 100 )
WEnd

Func _MouseClickPlus ( )
    Local $Window           = "Naamloos - Kladblok"
    Local $MK_SCROLL        = 0x020A

    DllCall("user32.dll", "int", "SendMessage", _
        "hwnd",  WinGetHandle( $Window ), _
        "int",   $MK_SCROLL, _
        "int",   0, _
        "long",  0 )

    ConsoleWrite ( @Error & " " )
EndFunc

And the Error returned = 0. Because this is the first time I use a DllCall I don't know how to fix this...

Why won't my notepad document scroll? I would love to have this working!

Thanks in advance,

Rawox

//Edit: added links:

MSDN Link to MW_MOUSEWHEEL

Edited by Rawox

Share this post


Link to post
Share on other sites



Im not sure "0x020A" is an int, but @error 0 == success.

The hex value 0x020A is certainly an INT, but "0x020A" (with the quotes around it) would be a string.

An @error = 0 only tells you DllCall() didn't fail, not the result of the DLL function itself, which would be in the return value. Note the return value from a DLL call is always an array, so you should do something like:

$aRET = DllCall("user32.dll", "int", "SendMessage", _
        "hwnd",  WinGetHandle( $Window ), _
        "int",   $MK_SCROLL, _
        "int",   0, _
        "long",  0 )
    MsgBox(64, "Result", "Return value = " & $aRET[0])

In the particular case of User32.dll SendMessage, the return value depends on which message you send and 0 is not always success. How do you know what "MK_SCROLL" is, and what the return value should be?

:graduated:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Ok,

- 0x020A (without quotes) is an Int...

- Both DllCall and Return value (from PsaltyDS) return 0

I don't know what the return value of $aRET should so how can I find that out?

And I'm not sure of I used DllCall corrent, I just used two 0's for the last arguments because I didn't know what I had to put there...

And PsaltyDS:

In the particular case of User32.dll SendMessage, the return value depends on which message you send and 0 is not always success. How do you know what "MK_SCROLL" is, and what the return value should be?

MSDN about WM_MOUSEWHEEL Message

Can any of you guys help me out?

//Edit:

Found this on MSDN but it just doesn't scroll...

Return Value:

If an application processes this message, it should return zero.

Edited by Rawox

Share this post


Link to post
Share on other sites

Same question: What is MK_SCROLL? Where did you get that message ID, and what is it supposed to do?

Wherever MK_SCROLL is documented it should say what the expected return value is.

:graduated:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I don't think I get your question...

Isn't this enough? Link

Ow, wait... you mean MK_SCROLL itself? I think I made it up myself. But it's a variable which is 0x020A so it wouldn't bother which variable it has?

Edited by Rawox

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I don't think I get your question...

Isn't this enough? Link

Ow, wait... you mean MK_SCROLL itself? I think I made it up myself. But it's a variable which is 0x020A so it wouldn't bother which variable it has?

Yes, I mean MK_SCROLL, which is not listed anywhere on the MSDN page you keep referring to.

So where did you pull the value 0x020A from? Where is it documented?

:graduated:

Edit: I missed WM_MOUSEWHEEL = 0x020A near the top of the page. That variable is already globally declared in the WindowsConstants.au3 include file, so just use $WM_MOUSEWHEEL.

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I found 0x020A at the top of this page: Link

#define WM_MOUSEWHEEL 0x020A

Why can't I delete my own posts...?

Edited by Rawox

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Edit: I missed WM_MOUSEWHEEL = 0x020A near the top of the page. That variable is already globally declared in the WindowsConstants.au3 include file, so just use $WM_MOUSEWHEEL.

Is this what you're trying to use?

That's what I tried, but I think I missed that post... :graduated:

//Edit:

HotKeySet ( "{F8}", "_MouseWheelPlusTest")

Opt ( "WinTitleMatchMode", 2 )

While 1
    Sleep ( 100 )
WEnd

Func _MouseWheelPlusTest ( )
    _MouseWheelPlus ( "Firefox", "up", 1 )
EndFunc

Func _MouseWheelPlus($Window, $direction, $clicks)
    MsgBox ( 0,0,0 )
    Local $WM_MOUSEWHEEL    =  0x020A
    $MouseCoord = MouseGetPos()
        $X = $MouseCoord[0]
        $Y = $MouseCoord[1]
    If $direction = "up" then
        $WheelDelta = 120
    Else
        $WheelDelta = -120
    Endif
    For $i = 0 to $clicks
    $aRET = DllCall("user32.dll", "int", "SendMessage", _
            "hwnd",  WinGetHandle( $Window ), _
            "int",   $WM_MOUSEWHEEL, _
            "long",   _MakeLong(0,$WheelDelta), _
            "long",  _MakeLong($X, $Y))
    MsgBox ( 0, @error, $aRET[0] )
    Next
EndFunc

Func _MakeLong($LoWord,$HiWord)
  Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc

I tried this, but it still doesn't scroll...? Anything to do with my OS? (Windows 7 Ultimate 64Bit)

- When running this, 2 msgboxes pop up... (Both returning 0 for @error and $aRET[0])?

- The WinGetHandle works ok.

Edited by Rawox

Share this post


Link to post
Share on other sites

OK, the MSDN page says:

Return Value

If an application processes this message, it should return zero.

So zero is good. And this version works fine (scrolls Firefox up/down alternately):
#include <WindowsConstants.au3>

HotKeySet("{ESC}", "_Quit")
HotKeySet("{F8}", "_MouseWheelPlusTest")

Opt("WinTitleMatchMode", 2)

Global $f_Dir = False

While 1
    Sleep(100)
WEnd

Func _MouseWheelPlusTest()
    $f_Dir = Not $f_Dir
    If $f_Dir Then
        _MouseWheelPlus("Firefox", "up", 1)
    Else
        _MouseWheelPlus("Firefox", "down", 1)
    EndIf
EndFunc   ;==>_MouseWheelPlusTest

Func _MouseWheelPlus($Window, $direction, $clicks)
    $MouseCoord = MouseGetPos()
    $X = $MouseCoord[0]
    $Y = $MouseCoord[1]
    If $direction = "up" Then
        $WheelDelta = 120
    Else
        $WheelDelta = -120
    EndIf
    For $i = 0 To $clicks
        $aRET = DllCall("user32.dll", "int", "SendMessage", _
                "hwnd", WinGetHandle($Window), _
                "int", $WM_MOUSEWHEEL, _
                "long", _MakeLong(0, $WheelDelta), _
                "long", _MakeLong($X, $Y))
        ;MsgBox(0, @error, $aRET[0])
    Next
EndFunc   ;==>_MouseWheelPlus

Func _MakeLong($LoWord, $HiWord)
    Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc   ;==>_MakeLong

Func _Quit()
    Exit
EndFunc

:graduated:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

HotKeySet("{ESC}", "_Quit")
HotKeySet("{F8}", "_MouseWheelPlusTest")

Opt("WinTitleMatchMode", 2)

Global $f_Dir = False

While 1
    Sleep(100)
WEnd

Func _MouseWheelPlusTest()
    $f_Dir = Not $f_Dir
    If $f_Dir Then
        _MouseWheelPlus("Firefox", "up", 1)
    Else
        _MouseWheelPlus("Firefox", "down", 1)
    EndIf
EndFunc   ;==>_MouseWheelPlusTest

Func _MouseWheelPlus($Window, $direction, $clicks)
    $MouseCoord = MouseGetPos()
    $X = $MouseCoord[0]
    $Y = $MouseCoord[1]
    If $direction = "up" Then
        $WheelDelta = 120
    Else
        $WheelDelta = -120
    EndIf
    For $i = 0 To $clicks
        $aRET = DllCall("user32.dll", "int", "SendMessage", _
                "hwnd", WinGetHandle($Window), _
                "int", $WM_MOUSEWHEEL, _
                "long", _MakeLong(0, $WheelDelta), _
                "long", _MakeLong($X, $Y))
        ;MsgBox(0, @error, $aRET[0])
    Next
EndFunc   ;==>_MouseWheelPlus

Func _MakeLong($LoWord, $HiWord)
    Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc   ;==>_MakeLong

Func _Quit()
    Exit
EndFunc

:graduated:

I don't know why, but it isn't working for me...

I think you should look at WM_VSCROLL message

http://msdn.microsoft.com/en-us/library/bb787577%28VS.85%29.aspx

Zedna, i'm trying this right now. How to implement it? I don't see an int. Edited by Rawox

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Zedna, i'm trying this right now. How to implement it? I don't see an int.

changed one of examples from this forum

left commented lines so you can see other variants there

tested and working fine

edit:

_GUIScrollBars_GetScrollInfo is not needed here

#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>
#include <SendMessage.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

;~ Run('notepad.exe')
;~ WinWait('[CLASS:Notepad]')
WinActivate('[CLASS:Notepad]')
WinWaitActive('[CLASS:Notepad]')
$hEdit = ControlGetHandle('[CLASS:Notepad]', '', 'Edit1')
$tSBI = DllStructCreate($tagSCROLLINFO)
DllStructSetData($tSBI, 'cbSize', DllStructGetSize($tSBI))
DllStructSetData($tSBI, 'fMask', $SIF_ALL)

If _GUIScrollBars_GetScrollInfo($hEdit, $SB_VERT, $tSBI) Then
;   Local $iMax = DllStructGetData($tSBI, 'nMax')
;   $value = Round($iMax*0.2)
;~  _SendMessage($hEdit, $WM_VSCROLL, _WinAPI_MakeDWord($SB_THUMBPOSITION, $value), 0)
;~  _SendMessage($hEdit, $WM_VSCROLL, _WinAPI_MakeDWord($SB_LINEDOWN, 0), 0)
    _SendMessage($hEdit, $WM_VSCROLL, $SB_LINEDOWN, 0)
;~      DllStructSetData($tSBI, 'nPos', $value)
;~      _GUIScrollBars_SetScrollInfo($hEdit, $SB_VERT, $tSBI)
Else
    ConsoleWrite('Error' & @LF)
EndIf
Edited by Zedna

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

changed one of examples from this forum

left commented lines so you can see other variants there

tested and working fine

edit:

_GUIScrollBars_GetScrollInfo is not needed here

#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>
#include <SendMessage.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

;~ Run('notepad.exe')
;~ WinWait('[CLASS:Notepad]')
WinActivate('[CLASS:Notepad]')
WinWaitActive('[CLASS:Notepad]')
$hEdit = ControlGetHandle('[CLASS:Notepad]', '', 'Edit1')
$tSBI = DllStructCreate($tagSCROLLINFO)
DllStructSetData($tSBI, 'cbSize', DllStructGetSize($tSBI))
DllStructSetData($tSBI, 'fMask', $SIF_ALL)

If _GUIScrollBars_GetScrollInfo($hEdit, $SB_VERT, $tSBI) Then
;   Local $iMax = DllStructGetData($tSBI, 'nMax')
;   $value = Round($iMax*0.2)
;~  _SendMessage($hEdit, $WM_VSCROLL, _WinAPI_MakeDWord($SB_THUMBPOSITION, $value), 0)
;~  _SendMessage($hEdit, $WM_VSCROLL, _WinAPI_MakeDWord($SB_LINEDOWN, 0), 0)
    _SendMessage($hEdit, $WM_VSCROLL, $SB_LINEDOWN, 0)
;~      DllStructSetData($tSBI, 'nPos', $value)
;~      _GUIScrollBars_SetScrollInfo($hEdit, $SB_VERT, $tSBI)
Else
    ConsoleWrite('Error' & @LF)
EndIf

As I see this will have to activate the window, I want to scroll inactive windows...

And not just notepad, but for any window.

Edited by Rawox

Share this post


Link to post
Share on other sites

I don't know why, but it isn't working for me...

Ah, you want to do it without the Firefox window having focus. In that case it doesn't work for me either, just works when Firefox is active.

:graduated:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

As I see this will have to activate the window, I want to scroll inactive windows...

And not just notepad, but for any window.

It's working fine also without activating of window (tested)

and it can be used for all windows/controls that have got associated scrollbar

$hEdit = ControlGetHandle('[CLASS:Notepad]', '', 'Edit1')
_SendMessage($hEdit, $WM_VSCROLL, $SB_LINEDOWN, 0)
Edited by Zedna

Share this post


Link to post
Share on other sites

Haha, do you know how to do it when it's not active?

Share this post


Link to post
Share on other sites

It's working fine also without activating of window (tested)

and it can be used for all windows/controls that have got associated scrollbar

$hEdit = ControlGetHandle('[CLASS:Notepad]', '', 'Edit1')
_SendMessage($hEdit, $WM_VSCROLL, $SB_LINEDOWN, 0)

The problem is that I not always know the control, so is there a way to get the scrollbar class?

Most of the windows have just 1 vertical scrollbar right?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0