Jump to content

DLLCall with Null


Recommended Posts

I'm trying to scroll a control or window programmatically using the Win32 API, specifically ScrollWindow or ScrollWindowEx. I've had some success with getting the scrollbar to move, but the client area seems to scroll and immediately jump back. The ScrollWindow call returns 0, indicating it failed.

The goal is to be able to state what % of the way down to scroll a window. I can get a scrollbar position with no problem, but I want to be able to set it and have the associated control respond to the new position. I've tried using ints, shorts, and longs to no avail, so I'm thinking the problem lies in being able to pass a null parameter.

How do you pass a null value through DLLCall? Or could someone tell me what I'm doing wrong?

$WM_HSCROLL = 276
    $WM_VSCROLL = 277
    $SB_THUMBPOSITION = 4
    $SBS_HORZ = 0
    $SBS_VERT = 1
    $NULL = ""; null-terminated string
    $SW_SCROLLCHILDREN = 1
    $SW_INVALIDATE = 2
    $SW_ERASE = 4
    $SW_SMOOTHSCROLL = 16; might be 8

    $bVal = DllCall("user32.dll", "int", "SetScrollPos", "hwnd", $ctrlHandle, "int", $SBS_VERT, "int", $relPos, "int", 1)
    $xVal = DllCall("user32.dll", "int", "PostMessageA", "hwnd", $ctrlHandle, "int", $WM_VSCROLL, "int", $SB_THUMBPOSITION + 65536 * $relPos, "int", 0)

    
    $RECT = DllStructCreate("int;int;int;int")
    $aryCtrlPos = ControlGetPos("C:\Document", "", "Scintilla1")
    DllStructSetData($RECT, 1, $aryCtrlPos[0])
    DllStructSetData($RECT, 2, $aryCtrlPos[1])
    DllStructSetData($RECT, 3, $aryCtrlPos[2])
    DllStructSetData($RECT, 4, $aryCtrlPos[3])
    $ptrRECT = DllStructGetPtr($RECT)
    
    
    $mVal = DllCall("user32.dll", "int", "ScrollWindow", "hwnd", $ctrlHandle, "short", $horzDiff, "short", $vertDiff, "ptr", "", "ptr", $ptrRECT); returns 0 = FAIL
    $mVal = DllCall("user32.dll", "int", "ScrollWindowEx", "hwnd", $ctrlHandle,  "short", $horzDiff, "short", $vertDiff, "ptr", $NULL, "ptr", $NULL, "hwnd", $NULL, "ptr", $NULL, "short",  $SW_ERASE + $SW_INVALIDATE + $SW_SCROLLCHILDREN); returns 0 = FAIL
    
    $nVal = DllCall("user32.dll", "int", "UpdateWindow", "hwnd", $ctrlHandle)

    

    $scrollInfo = 0;Release the memory
    $RECT = 0
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...