Digisoul Posted April 28, 2010 Share Posted April 28, 2010 Hello there, I am trying to make a table like entry form, and totally stuck at scrolling. here is my code: expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIScrollBars.au3> #include <ScrollBarConstants.au3> #include <WinAPI.au3> Global $input_controlls[1][4], $iCnt = 0, $hEntryGUI, $entry_scroll = False, $NumOfInputs = 1, $LineIndex = 0, $EntryIndex = 0, $OPEN_INDEX, $checkNextEntry = False, $Y = 2, $hEGUI Global $Entry_Height = 175 Global $user32 = DllOpen("user32.dll") #region ### START Koda GUI section ### Form= $hGUI = GUICreate("Form2", 625, 298, 193, 222) $bUp = GUICtrlCreateButton(Chr("0xE1"), 555, 0, 20) GUICtrlSetFont($bUp, Default, Default, Default, "Wingdings") $bDown = GUICtrlCreateButton(Chr("0xE2"), 555, $Entry_Height - 23, 20) GUICtrlSetFont($bDown, Default, Default, Default, "Wingdings") $NEXT = GUICtrlCreateDummy() $DOWN = GUICtrlCreateDummy() $UP = GUICtrlCreateDummy() $UP = GUICtrlCreateDummy() $hEGUI = GUICreate("Entry Parrent Gui", 555, $Entry_Height, 0, 0, $WS_CHILD, -1, $hGUI) GUISetState() $hEntryGUI = GUICreate("Entry Gui", 555, $Entry_Height, 0, 0, $WS_CHILD, -1, $hEGUI) GUISetBkColor(0X006400) $yPos = _WinGetposIn($hEGUI, "", $hEntryGUI) Global $default_pos = $yPos[1] For $i = 0 To 6 $input_controlls[$i][0] = GUICtrlCreateInput("LINE" & $i + 1, 0, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $input_controlls[$i][1] = GUICtrlCreateInput("", 128, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $input_controlls[$i][2] = GUICtrlCreateInput("", 256, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $input_controlls[$i][3] = GUICtrlCreateInput("", 384, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) UpdateIndex($input_controlls) $Y += 25 Next ConsoleWrite("Default Y Position: "&$default_pos&@CRLF) GUISetState() GUISwitch($hGUI) GUISetState() Dim $keys[3][2] = [["{ENTER}", $NEXT],["{DOWN}", $DOWN],["{UP}", $UP]] GUISetAccelerators($keys, $hGUI) #endregion ### END Koda GUI section ### GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ;GUIRegisterMsg($WM_SIZE, "WM_SIZE") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $NEXT If $checkNextEntry = True Then ;ConsoleWrite("Entry On: " & ($LineIndex + 1) & "==" & ($NumOfInputs - 1) & @CRLF) ;ConsoleWrite("Y:: " & $Y & "NEW y: " & ($Y + 30) & @CRLF) If ($LineIndex + 1) == ($NumOfInputs - 1) Then ; Last Line ; New Line Entry AddEntry(True, True) Else ; Focus On The Next Line GUISwitch($hEntryGUI) GUICtrlSetState($input_controlls[$LineIndex + 1][0], $GUI_FOCUS) ;_SetFocus(GUICtrlGetHandle($input_controlls[$LineIndex + 1][0])) GUISwitch($hGUI) EndIf Else ;Focus on The Next Cell GUISwitch($hEntryGUI) ;_SetFocus(GUICtrlGetHandle($input_controlls[$LineIndex][$EntryIndex + 1])) GUICtrlSetState($input_controlls[$LineIndex][$EntryIndex + 1], $GUI_FOCUS) GUISwitch($hGUI) EndIf Case $DOWN ConsoleWrite("Down: " & $LineIndex & " " & $NumOfInputs - 1 & @CRLF) ConsoleWrite("Down: " & ($LineIndex <> ($NumOfInputs)) & @CRLF) If $LineIndex <> ($NumOfInputs) Then ; LAST lINE ConsoleWrite("+ Down" & @CRLF) GUISwitch($hEntryGUI) GUICtrlSetState($input_controlls[$LineIndex + 1][$EntryIndex], $GUI_FOCUS) GUISwitch($hGUI) EndIf Case $UP If $LineIndex <> 0 Then ;1st line GUISwitch($hEntryGUI) GUICtrlSetState($input_controlls[$LineIndex - 1][$EntryIndex], $GUI_FOCUS) GUISwitch($hGUI) EndIf Case $bDown scroll("down") EndSwitch WEnd Func UpdateIndex(ByRef $A, $DIM = 4) $p = UBound($A) ReDim $A[$p + 1][$DIM] $NumOfInputs = $p + 1 ConsoleWrite("+ UPDATE Index: " & $NumOfInputs & @CRLF) Return $p - 1 EndFunc ;==>UpdateIndex Func AddEntry($Switch = True, $Focus = True) If $Switch Then GUISwitch($hEntryGUI) $uI = UpdateIndex($input_controlls) $OPEN_INDEX = $uI $input_controlls[$uI][0] = GUICtrlCreateInput("LINE:" & $uI + 1, 0, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $input_controlls[$uI][1] = GUICtrlCreateInput("", 128, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $input_controlls[$uI][2] = GUICtrlCreateInput("", 256, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $input_controlls[$uI][3] = GUICtrlCreateInput("", 384, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $Y += 25 If Check_Space($hEntryGUI) = True Then $Entry_Height += 35 Local $lP = _WinGetposIn($hEGUI, "", $hEntryGUI) WinMove($hEntryGUI, "", $lP[0],$lP[1], Default, $Entry_Height) ; Resize Local $wPos = WinGetPos($hEntryGUI) ConsoleWrite("! After ReSize :: Win Height: " & $wPos[3] &" WinY: " & $wPos[1]& " CtrlY: " & $Y & " Result: " & ($Y > $wPos[3]) & @CRLF) EndIf If $Focus Then GUICtrlSetState($input_controlls[$LineIndex + 1][0], $GUI_FOCUS) ; fOCUS ON NEW LINE If $Switch Then GUISwitch($hGUI) EndFunc ;==>AddEntry Func Check_Space($hWnd) Local $wPos = ControlGetPos($hEGUI,"",$hWnd) ConsoleWrite("! Before ReSize :: Win Height: " & $wPos[3] &" WinY: " & $wPos[1]& " CtrlY: " & $Y & " Result: " & ($Y > $wPos[3]) & @CRLF) If ($Y > $wPos[3]) Then Return True Else Return False EndIf EndFunc ;==>Check_Space Func scroll($mode) Switch $mode Case "up" Case "down" Local $wPos = WinGetPos($hEntryGUI) Local $cP = _WinGetposIn($hEGUI, "", $hEntryGUI) ConsoleWrite("- Scrolling:: win x: " & $cP[0] & " win y:" & $cP[1] & " scroll:"& $cP[1] - 22 & @CRLF) WinMove($hEntryGUI, "", $cP[0], $cP[1] - 21) Local $cPos = ControlGetPos($hEntryGUI, "", $input_controlls[$OPEN_INDEX][0]) ConsoleWrite("- Calculated Possition : Win Y: " & $wPos[2] & " $Y:" & $Y & @CRLF) EndSwitch EndFunc ;==>scroll Func _WinGetposIn($parentW, $parentText, $childW, $childText = "") Local $Result, $offset If Not WinExists($childW) Then Return SetError(1, 1, 0) If Not WinExists($parentW) Then Return SetError(1, 2, 0) If BitAND(WinGetState($childW), 16) Or BitAND(WinGetState($parentW), 16) Then Return SetError(1, 3, 0) $offset = DllStructCreate("int;int") DllCall("User32.dll", "int", "ClientToScreen", "hwnd", WinGetHandle($parentW, $parentText), "ptr", DllStructGetPtr($offset)) If @error Then Return SetError(1, 4, 0) ;ConsoleWrite(DllStructGetData($offset, 1) & ', ' & DllStructGetData($offset, 2) & @CRLF) $Result = WinGetPos($childW, $childText) $Result[0] -= DllStructGetData($offset, 1) $Result[1] -= DllStructGetData($offset, 2) Return $Result EndFunc ;==>_WinGetposIn Func ClientToScreen($hWnd, $x, $Y) Local $stPoint = DllStructCreate("int;int"), $Result[2] DllStructSetData($stPoint, 1, $x) DllStructSetData($stPoint, 2, $Y) DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint)) $x = DllStructGetData($stPoint, 1) $Result[0] = $x $Y = DllStructGetData($stPoint, 2) $Result[1] = $Y ; release Struct not really needed as it is a local $stPoint = 0 Return $Result EndFunc ;==>ClientToScreen Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit ;If Not IsHWnd($hEdit) Then $hWndEdit = GUICtrlGetHandle($hEdit) $hWndFrom = $ilParam $iIDFrom = _WinAPI_LoWord($iwParam) $iCode = _WinAPI_HiWord($iwParam) Switch $hWnd Case $hEntryGUI Switch $iCode Case $EN_SETFOCUS For $i = 0 To $NumOfInputs - 1 $handle1 = GUICtrlGetHandle($input_controlls[$i][0]) $handle2 = GUICtrlGetHandle($input_controlls[$i][1]) $handle3 = GUICtrlGetHandle($input_controlls[$i][2]) $handle4 = GUICtrlGetHandle($input_controlls[$i][3]) If $handle1 = $hWndFrom Then ConsoleWrite("> In Focus Line # " & $i & " entry number: 1" & @CRLF & @CRLF) $LineIndex = $i $EntryIndex = 0 $checkNextEntry = False ExitLoop EndIf If $handle2 = $hWndFrom Then ConsoleWrite("> In Focus Line # " & $i & " entry number: 2" & @CRLF & @CRLF) $LineIndex = $i $EntryIndex = 1 $checkNextEntry = False ExitLoop EndIf If $handle3 = $hWndFrom Then ConsoleWrite("> In Focus Line # " & $i & " entry number: 3" & @CRLF & @CRLF) $LineIndex = $i $EntryIndex = 2 $checkNextEntry = False ExitLoop EndIf If $handle4 = $hWndFrom Then ConsoleWrite("> In Focus Line # " & $i & " entry number: 4" & @CRLF & @CRLF) $LineIndex = $i $EntryIndex = 3 $checkNextEntry = True EndIf Next EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func _DebugPrint($s_text, $line = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @LF & _ "+======================================================" & @LF & _ "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _ "+======================================================" & @LF)EndFunc ;==>_DebugPrint here is a example preview: when the user press enter at last Entry of Line 7 it will genrate a new line, but i am unable to controll its scroll position. because if i press DOWN button twice it will show result like this: Thanks in Advance. 73 108 111 118 101 65 117 116 111 105 116 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 28, 2010 Moderators Share Posted April 28, 2010 Digisoul,That was fun! You were using several different values (21, 22, 25, 35) to vary the scroll distance and the GUI height when you added lines. Once those were standardised at 25, life became a bit easier. The scrolling now works as it should, and you cannot go past the beginning or end of the available lines. All you need to do when adding a line is call a "down" scroll - simple, eh :expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIScrollBars.au3> #include <ScrollBarConstants.au3> #include <WinAPI.au3> Global $input_controlls[1][4], $iCnt = 0, $hEntryGUI, $entry_scroll = False, $NumOfInputs = 1, $LineIndex = 0, $EntryIndex = 0, $OPEN_INDEX, $checkNextEntry = False, $Y = 2, $hEGUI Global $Entry_Height = 175 Global $user32 = DllOpen("user32.dll") #region ### START Koda GUI section ### Form= $hGUI = GUICreate("Form2", 625, 298, 193, 222) $bUp = GUICtrlCreateButton(Chr("0xE1"), 555, 0, 20) GUICtrlSetFont($bUp, Default, Default, Default, "Wingdings") $bDown = GUICtrlCreateButton(Chr("0xE2"), 555, $Entry_Height - 23, 20) GUICtrlSetFont($bDown, Default, Default, Default, "Wingdings") $NEXT = GUICtrlCreateDummy() $DOWN = GUICtrlCreateDummy() $UP = GUICtrlCreateDummy() $UP = GUICtrlCreateDummy() $hEGUI = GUICreate("Entry Parrent Gui", 555, $Entry_Height, 0, 0, $WS_CHILD, -1, $hGUI) GUISetState() $hEntryGUI = GUICreate("Entry Gui", 555, $Entry_Height, 0, 0, $WS_CHILD, -1, $hEGUI) GUISetBkColor(0X006400) $yPos = _WinGetposIn($hEGUI, "", $hEntryGUI) Global $default_pos = $yPos[1] For $i = 0 To 6 $input_controlls[$i][0] = GUICtrlCreateInput("LINE" & $i + 1, 0, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $input_controlls[$i][1] = GUICtrlCreateInput("", 128, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $input_controlls[$i][2] = GUICtrlCreateInput("", 256, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $input_controlls[$i][3] = GUICtrlCreateInput("", 384, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) UpdateIndex($input_controlls) $Y += 25 Next ConsoleWrite("Default Y Position: "&$default_pos&@CRLF) GUISetState() GUISwitch($hGUI) GUISetState() Dim $keys[3][2] = [["{ENTER}", $NEXT],["{DOWN}", $DOWN],["{UP}", $UP]] GUISetAccelerators($keys, $hGUI) #endregion ### END Koda GUI section ### GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ;GUIRegisterMsg($WM_SIZE, "WM_SIZE") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $NEXT If $checkNextEntry = True Then ;ConsoleWrite("Entry On: " & ($LineIndex + 1) & "==" & ($NumOfInputs - 1) & @CRLF) ;ConsoleWrite("Y:: " & $Y & "NEW y: " & ($Y + 30) & @CRLF) If ($LineIndex + 1) == ($NumOfInputs - 1) Then ; Last Line ; New Line Entry AddEntry(True, True) scroll("down") Else ; Focus On The Next Line GUISwitch($hEntryGUI) GUICtrlSetState($input_controlls[$LineIndex + 1][0], $GUI_FOCUS) ;_SetFocus(GUICtrlGetHandle($input_controlls[$LineIndex + 1][0])) GUISwitch($hGUI) EndIf Else ;Focus on The Next Cell GUISwitch($hEntryGUI) ;_SetFocus(GUICtrlGetHandle($input_controlls[$LineIndex][$EntryIndex + 1])) GUICtrlSetState($input_controlls[$LineIndex][$EntryIndex + 1], $GUI_FOCUS) GUISwitch($hGUI) EndIf Case $DOWN ConsoleWrite("Down: " & $LineIndex & " " & $NumOfInputs - 1 & @CRLF) ConsoleWrite("Down: " & ($LineIndex <> ($NumOfInputs)) & @CRLF) If $LineIndex <> ($NumOfInputs) Then ; LAST lINE ConsoleWrite("+ Down" & @CRLF) GUISwitch($hEntryGUI) GUICtrlSetState($input_controlls[$LineIndex + 1][$EntryIndex], $GUI_FOCUS) GUISwitch($hGUI) EndIf Case $bUP scroll("up") Case $bDown scroll("down") EndSwitch WEnd Func UpdateIndex(ByRef $A, $DIM = 4) $p = UBound($A) ReDim $A[$p + 1][$DIM] $NumOfInputs = $p + 1 ConsoleWrite("+ UPDATE Index: " & $NumOfInputs & @CRLF) Return $p - 1 EndFunc ;==>UpdateIndex Func AddEntry($Switch = True, $Focus = True) If $Switch Then GUISwitch($hEntryGUI) $uI = UpdateIndex($input_controlls) $OPEN_INDEX = $uI $input_controlls[$uI][0] = GUICtrlCreateInput("LINE:" & $uI + 1, 0, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $input_controlls[$uI][1] = GUICtrlCreateInput("", 128, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $input_controlls[$uI][2] = GUICtrlCreateInput("", 256, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $input_controlls[$uI][3] = GUICtrlCreateInput("", 384, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $Y += 25 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If Check_Space($hEntryGUI) = True Then $Entry_Height += 25 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Local $lP = _WinGetposIn($hEGUI, "", $hEntryGUI) WinMove($hEntryGUI, "", $lP[0],$lP[1], Default, $Entry_Height) ; Resize Local $wPos = WinGetPos($hEntryGUI) ConsoleWrite("! After ReSize :: Win Height: " & $wPos[3] &" WinY: " & $wPos[1]& " CtrlY: " & $Y & " Result: " & ($Y > $wPos[3]) & @CRLF) EndIf If $Focus Then GUICtrlSetState($input_controlls[$LineIndex + 1][0], $GUI_FOCUS) ; fOCUS ON NEW LINE If $Switch Then GUISwitch($hGUI) EndFunc ;==>AddEntry Func Check_Space($hWnd) Local $wPos = ControlGetPos($hEGUI,"",$hWnd) ConsoleWrite("! Before ReSize :: Win Height: " & $wPos[3] &" WinY: " & $wPos[1]& " CtrlY: " & $Y & " Result: " & ($Y > $wPos[3]) & @CRLF) If ($Y > $wPos[3]) Then Return True Else Return False EndIf EndFunc ;==>Check_Space Func scroll($mode) Local $wPos = WinGetPos($hEntryGUI) Local $cP = _WinGetposIn($hEGUI, "", $hEntryGUI) Switch $mode Case "up" ; Check if the first line is at the top and scroll if not (GUI y posn is not 0) If $cP[1] <> 0 Then ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ConsoleWrite("- Scrolling:: win x: " & $cP[0] & " win y:" & $cP[1] & " scroll:"& $cP[1] + 25 & @CRLF) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< WinMove($hEntryGUI, "", $cP[0], $cP[1] + 25) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndIf Local $cPos = ControlGetPos($hEntryGUI, "", $input_controlls[$OPEN_INDEX][0]) ConsoleWrite("- Calculated Possition : Win Y: " & $wPos[2] & " $Y:" & $Y & @CRLF) Case "down" ; Check if bottom line is at the bottom and scroll if not (GUI y posn is not higher than actual GUI ht - window ht) If $cp[1] > 175 - $wPos[3] Then ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ConsoleWrite("- Scrolling:: win x: " & $cP[0] & " win y:" & $cP[1] & " scroll:"& $cP[1] - 25 & @CRLF) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< WinMove($hEntryGUI, "", $cP[0], $cP[1] - 25) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndIf Local $cPos = ControlGetPos($hEntryGUI, "", $input_controlls[$OPEN_INDEX][0]) ConsoleWrite("- Calculated Possition : Win Y: " & $wPos[2] & " $Y:" & $Y & @CRLF) EndSwitch EndFunc ;==>scroll Func _WinGetposIn($parentW, $parentText, $childW, $childText = "") Local $Result, $offset If Not WinExists($childW) Then Return SetError(1, 1, 0) If Not WinExists($parentW) Then Return SetError(1, 2, 0) If BitAND(WinGetState($childW), 16) Or BitAND(WinGetState($parentW), 16) Then Return SetError(1, 3, 0) $offset = DllStructCreate("int;int") DllCall("User32.dll", "int", "ClientToScreen", "hwnd", WinGetHandle($parentW, $parentText), "ptr", DllStructGetPtr($offset)) If @error Then Return SetError(1, 4, 0) ;ConsoleWrite(DllStructGetData($offset, 1) & ', ' & DllStructGetData($offset, 2) & @CRLF) $Result = WinGetPos($childW, $childText) $Result[0] -= DllStructGetData($offset, 1) $Result[1] -= DllStructGetData($offset, 2) Return $Result EndFunc ;==>_WinGetposIn Func ClientToScreen($hWnd, $x, $Y) Local $stPoint = DllStructCreate("int;int"), $Result[2] DllStructSetData($stPoint, 1, $x) DllStructSetData($stPoint, 2, $Y) DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint)) $x = DllStructGetData($stPoint, 1) $Result[0] = $x $Y = DllStructGetData($stPoint, 2) $Result[1] = $Y ; release Struct not really needed as it is a local $stPoint = 0 Return $Result EndFunc ;==>ClientToScreen Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit ;If Not IsHWnd($hEdit) Then $hWndEdit = GUICtrlGetHandle($hEdit) $hWndFrom = $ilParam $iIDFrom = _WinAPI_LoWord($iwParam) $iCode = _WinAPI_HiWord($iwParam) Switch $hWnd Case $hEntryGUI Switch $iCode Case $EN_SETFOCUS For $i = 0 To $NumOfInputs - 1 $handle1 = GUICtrlGetHandle($input_controlls[$i][0]) $handle2 = GUICtrlGetHandle($input_controlls[$i][1]) $handle3 = GUICtrlGetHandle($input_controlls[$i][2]) $handle4 = GUICtrlGetHandle($input_controlls[$i][3]) If $handle1 = $hWndFrom Then ConsoleWrite("> In Focus Line # " & $i & " entry number: 1" & @CRLF & @CRLF) $LineIndex = $i $EntryIndex = 0 $checkNextEntry = False ExitLoop EndIf If $handle2 = $hWndFrom Then ConsoleWrite("> In Focus Line # " & $i & " entry number: 2" & @CRLF & @CRLF) $LineIndex = $i $EntryIndex = 1 $checkNextEntry = False ExitLoop EndIf If $handle3 = $hWndFrom Then ConsoleWrite("> In Focus Line # " & $i & " entry number: 3" & @CRLF & @CRLF) $LineIndex = $i $EntryIndex = 2 $checkNextEntry = False ExitLoop EndIf If $handle4 = $hWndFrom Then ConsoleWrite("> In Focus Line # " & $i & " entry number: 4" & @CRLF & @CRLF) $LineIndex = $i $EntryIndex = 3 $checkNextEntry = True EndIf Next EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func _DebugPrint($s_text, $line = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @LF & _ "+======================================================" & @LF & _ "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _ "+======================================================" & @LF) EndFunc ;==>_DebugPrintLook for the <<<<<<<<<<<<<<< lines. As always, please ask if anything is unclear. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Digisoul Posted April 28, 2010 Author Share Posted April 28, 2010 Digisoul, That was fun! You were using several different values (21, 22, 25, 35) to vary the scroll distance and the GUI height when you added lines. Once those were standardised at 25, life became a bit easier. The scrolling now works as it should, and you cannot go past the beginning or end of the available lines. All you need to do when adding a line is call a "down" scroll - simple, eh : expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIScrollBars.au3> #include <ScrollBarConstants.au3> #include <WinAPI.au3> Global $input_controlls[1][4], $iCnt = 0, $hEntryGUI, $entry_scroll = False, $NumOfInputs = 1, $LineIndex = 0, $EntryIndex = 0, $OPEN_INDEX, $checkNextEntry = False, $Y = 2, $hEGUI Global $Entry_Height = 175 Global $user32 = DllOpen("user32.dll") #region ### START Koda GUI section ### Form= $hGUI = GUICreate("Form2", 625, 298, 193, 222) $bUp = GUICtrlCreateButton(Chr("0xE1"), 555, 0, 20) GUICtrlSetFont($bUp, Default, Default, Default, "Wingdings") $bDown = GUICtrlCreateButton(Chr("0xE2"), 555, $Entry_Height - 23, 20) GUICtrlSetFont($bDown, Default, Default, Default, "Wingdings") $NEXT = GUICtrlCreateDummy() $DOWN = GUICtrlCreateDummy() $UP = GUICtrlCreateDummy() $UP = GUICtrlCreateDummy() $hEGUI = GUICreate("Entry Parrent Gui", 555, $Entry_Height, 0, 0, $WS_CHILD, -1, $hGUI) GUISetState() $hEntryGUI = GUICreate("Entry Gui", 555, $Entry_Height, 0, 0, $WS_CHILD, -1, $hEGUI) GUISetBkColor(0X006400) $yPos = _WinGetposIn($hEGUI, "", $hEntryGUI) Global $default_pos = $yPos[1] For $i = 0 To 6 $input_controlls[$i][0] = GUICtrlCreateInput("LINE" & $i + 1, 0, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $input_controlls[$i][1] = GUICtrlCreateInput("", 128, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $input_controlls[$i][2] = GUICtrlCreateInput("", 256, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $input_controlls[$i][3] = GUICtrlCreateInput("", 384, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) UpdateIndex($input_controlls) $Y += 25 Next ConsoleWrite("Default Y Position: "&$default_pos&@CRLF) GUISetState() GUISwitch($hGUI) GUISetState() Dim $keys[3][2] = [["{ENTER}", $NEXT],["{DOWN}", $DOWN],["{UP}", $UP]] GUISetAccelerators($keys, $hGUI) #endregion ### END Koda GUI section ### GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ;GUIRegisterMsg($WM_SIZE, "WM_SIZE") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $NEXT If $checkNextEntry = True Then ;ConsoleWrite("Entry On: " & ($LineIndex + 1) & "==" & ($NumOfInputs - 1) & @CRLF) ;ConsoleWrite("Y:: " & $Y & "NEW y: " & ($Y + 30) & @CRLF) If ($LineIndex + 1) == ($NumOfInputs - 1) Then ; Last Line ; New Line Entry AddEntry(True, True) scroll("down") Else ; Focus On The Next Line GUISwitch($hEntryGUI) GUICtrlSetState($input_controlls[$LineIndex + 1][0], $GUI_FOCUS) ;_SetFocus(GUICtrlGetHandle($input_controlls[$LineIndex + 1][0])) GUISwitch($hGUI) EndIf Else ;Focus on The Next Cell GUISwitch($hEntryGUI) ;_SetFocus(GUICtrlGetHandle($input_controlls[$LineIndex][$EntryIndex + 1])) GUICtrlSetState($input_controlls[$LineIndex][$EntryIndex + 1], $GUI_FOCUS) GUISwitch($hGUI) EndIf Case $DOWN ConsoleWrite("Down: " & $LineIndex & " " & $NumOfInputs - 1 & @CRLF) ConsoleWrite("Down: " & ($LineIndex <> ($NumOfInputs)) & @CRLF) If $LineIndex <> ($NumOfInputs) Then ; LAST lINE ConsoleWrite("+ Down" & @CRLF) GUISwitch($hEntryGUI) GUICtrlSetState($input_controlls[$LineIndex + 1][$EntryIndex], $GUI_FOCUS) GUISwitch($hGUI) EndIf Case $bUP scroll("up") Case $bDown scroll("down") EndSwitch WEnd Func UpdateIndex(ByRef $A, $DIM = 4) $p = UBound($A) ReDim $A[$p + 1][$DIM] $NumOfInputs = $p + 1 ConsoleWrite("+ UPDATE Index: " & $NumOfInputs & @CRLF) Return $p - 1 EndFunc ;==>UpdateIndex Func AddEntry($Switch = True, $Focus = True) If $Switch Then GUISwitch($hEntryGUI) $uI = UpdateIndex($input_controlls) $OPEN_INDEX = $uI $input_controlls[$uI][0] = GUICtrlCreateInput("LINE:" & $uI + 1, 0, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $input_controlls[$uI][1] = GUICtrlCreateInput("", 128, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $input_controlls[$uI][2] = GUICtrlCreateInput("", 256, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $input_controlls[$uI][3] = GUICtrlCreateInput("", 384, $Y, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $Y += 25 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If Check_Space($hEntryGUI) = True Then $Entry_Height += 25 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Local $lP = _WinGetposIn($hEGUI, "", $hEntryGUI) WinMove($hEntryGUI, "", $lP[0],$lP[1], Default, $Entry_Height) ; Resize Local $wPos = WinGetPos($hEntryGUI) ConsoleWrite("! After ReSize :: Win Height: " & $wPos[3] &" WinY: " & $wPos[1]& " CtrlY: " & $Y & " Result: " & ($Y > $wPos[3]) & @CRLF) EndIf If $Focus Then GUICtrlSetState($input_controlls[$LineIndex + 1][0], $GUI_FOCUS) ; fOCUS ON NEW LINE If $Switch Then GUISwitch($hGUI) EndFunc ;==>AddEntry Func Check_Space($hWnd) Local $wPos = ControlGetPos($hEGUI,"",$hWnd) ConsoleWrite("! Before ReSize :: Win Height: " & $wPos[3] &" WinY: " & $wPos[1]& " CtrlY: " & $Y & " Result: " & ($Y > $wPos[3]) & @CRLF) If ($Y > $wPos[3]) Then Return True Else Return False EndIf EndFunc ;==>Check_Space Func scroll($mode) Local $wPos = WinGetPos($hEntryGUI) Local $cP = _WinGetposIn($hEGUI, "", $hEntryGUI) Switch $mode Case "up" ; Check if the first line is at the top and scroll if not (GUI y posn is not 0) If $cP[1] <> 0 Then ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ConsoleWrite("- Scrolling:: win x: " & $cP[0] & " win y:" & $cP[1] & " scroll:"& $cP[1] + 25 & @CRLF) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< WinMove($hEntryGUI, "", $cP[0], $cP[1] + 25) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndIf Local $cPos = ControlGetPos($hEntryGUI, "", $input_controlls[$OPEN_INDEX][0]) ConsoleWrite("- Calculated Possition : Win Y: " & $wPos[2] & " $Y:" & $Y & @CRLF) Case "down" ; Check if bottom line is at the bottom and scroll if not (GUI y posn is not higher than actual GUI ht - window ht) If $cp[1] > 175 - $wPos[3] Then ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ConsoleWrite("- Scrolling:: win x: " & $cP[0] & " win y:" & $cP[1] & " scroll:"& $cP[1] - 25 & @CRLF) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< WinMove($hEntryGUI, "", $cP[0], $cP[1] - 25) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndIf Local $cPos = ControlGetPos($hEntryGUI, "", $input_controlls[$OPEN_INDEX][0]) ConsoleWrite("- Calculated Possition : Win Y: " & $wPos[2] & " $Y:" & $Y & @CRLF) EndSwitch EndFunc ;==>scroll Func _WinGetposIn($parentW, $parentText, $childW, $childText = "") Local $Result, $offset If Not WinExists($childW) Then Return SetError(1, 1, 0) If Not WinExists($parentW) Then Return SetError(1, 2, 0) If BitAND(WinGetState($childW), 16) Or BitAND(WinGetState($parentW), 16) Then Return SetError(1, 3, 0) $offset = DllStructCreate("int;int") DllCall("User32.dll", "int", "ClientToScreen", "hwnd", WinGetHandle($parentW, $parentText), "ptr", DllStructGetPtr($offset)) If @error Then Return SetError(1, 4, 0) ;ConsoleWrite(DllStructGetData($offset, 1) & ', ' & DllStructGetData($offset, 2) & @CRLF) $Result = WinGetPos($childW, $childText) $Result[0] -= DllStructGetData($offset, 1) $Result[1] -= DllStructGetData($offset, 2) Return $Result EndFunc ;==>_WinGetposIn Func ClientToScreen($hWnd, $x, $Y) Local $stPoint = DllStructCreate("int;int"), $Result[2] DllStructSetData($stPoint, 1, $x) DllStructSetData($stPoint, 2, $Y) DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint)) $x = DllStructGetData($stPoint, 1) $Result[0] = $x $Y = DllStructGetData($stPoint, 2) $Result[1] = $Y ; release Struct not really needed as it is a local $stPoint = 0 Return $Result EndFunc ;==>ClientToScreen Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit ;If Not IsHWnd($hEdit) Then $hWndEdit = GUICtrlGetHandle($hEdit) $hWndFrom = $ilParam $iIDFrom = _WinAPI_LoWord($iwParam) $iCode = _WinAPI_HiWord($iwParam) Switch $hWnd Case $hEntryGUI Switch $iCode Case $EN_SETFOCUS For $i = 0 To $NumOfInputs - 1 $handle1 = GUICtrlGetHandle($input_controlls[$i][0]) $handle2 = GUICtrlGetHandle($input_controlls[$i][1]) $handle3 = GUICtrlGetHandle($input_controlls[$i][2]) $handle4 = GUICtrlGetHandle($input_controlls[$i][3]) If $handle1 = $hWndFrom Then ConsoleWrite("> In Focus Line # " & $i & " entry number: 1" & @CRLF & @CRLF) $LineIndex = $i $EntryIndex = 0 $checkNextEntry = False ExitLoop EndIf If $handle2 = $hWndFrom Then ConsoleWrite("> In Focus Line # " & $i & " entry number: 2" & @CRLF & @CRLF) $LineIndex = $i $EntryIndex = 1 $checkNextEntry = False ExitLoop EndIf If $handle3 = $hWndFrom Then ConsoleWrite("> In Focus Line # " & $i & " entry number: 3" & @CRLF & @CRLF) $LineIndex = $i $EntryIndex = 2 $checkNextEntry = False ExitLoop EndIf If $handle4 = $hWndFrom Then ConsoleWrite("> In Focus Line # " & $i & " entry number: 4" & @CRLF & @CRLF) $LineIndex = $i $EntryIndex = 3 $checkNextEntry = True EndIf Next EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func _DebugPrint($s_text, $line = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @LF & _ "+======================================================" & @LF & _ "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _ "+======================================================" & @LF) EndFunc ;==>_DebugPrint Look for the <<<<<<<<<<<<<<< lines. As always, please ask if anything is unclear. M23 You are GENIUS, Thank you very much, i was totally stuck! you really save my day I already watch your example on scroll bars http://www.autoitscript.com/forum/index.php?showtopic=112865&st=0&p=790676&hl=scroll&fromsearch=1&#entry790676 but i was unable to understand the concept for Max & Page Size settings also how to rearrange the scrolls dynamically , thats why i come to the button controls, anyways Thank You very much for your kind help. Just 1 last question, if i am on Line#1 and want to jump on last line ? 73 108 111 118 101 65 117 116 111 105 116 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 28, 2010 Moderators Share Posted April 28, 2010 Digisoul,Add these lines in the appropriate places (I have done a jump to both beginning and end - I knew you would only ask again ):$bBegin = GUICtrlCreateButton("B", 555, 24, 20) $bEnd = GUICtrlCreateButton("E", 555, $Entry_Height - 47, 20) ; ---------- Case $bBegin begin() Case $bEnd end() ; ---------- Func begin() Local $cP Do $cP = _WinGetposIn($hEGUI, "", $hEntryGUI) scroll("up") Until $cP[1] = 0 EndFunc Func end() Local $wPos = WinGetPos($hEntryGUI) For $i = 1 To ($wPos[3] - 175) / 25 Scroll("down") Next EndFuncKeep your eye on the Examples section over the next few days, I think I have cracked the Page/Max formulae for scrollbars! M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Digisoul Posted April 28, 2010 Author Share Posted April 28, 2010 Again Thank you very much! for jump on 1st line i try this & its worked If $cP[1] <> 0 Then WinMove($hEntryGUI, "", $cP[0], 0) ; To Jump on the 1st entry EndIf Keep your eye on the Examples section over the next few days, I think I have cracked the Page/Max formulae for scrollbars! I will wait for your example! 73 108 111 118 101 65 117 116 111 105 116 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now