Jump to content

What is Wrong in This? Is It a Bug?


Recommended Posts

Hey Everyone............

I triend to Simulate a Scroll Bar Using a Slider..........

However Upon Registering the WM_COMMAND everything just goes wrong (Try to Drag the Slider the text doesnt Come to the Perfect Position)........

On Replacing WM_COMMAND with WM_NOTIFY...........Everything is as usual f9.........

Is it a Bug or WM_COMMAND has much of the Procedures Throughout the Thread

Please Help me Out.................

Thanx

Code:

#include <GUIEdit.au3>
#include <ScrollBarConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <SliderConstants.au3>
#include <GuiSlider.au3>
#include <file.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Local $sGUI=GUICreate('',500,200)
Global $sEdit=GUICtrlCreateEdit(FileRead('Project.au3'),10,10,380,180,64)
$sEdit=GUICtrlGetHandle(-1)
Local $sButton1=GUICtrlCreateButton('Up',400,10,80,20)
Local $sButton2=GUICtrlCreateButton('Down',400,160,80,20)
Local $hVSlider= GUICtrlCreateSlider(400, 30, 20, 120, BitOR($TBS_NOTICKS,$TBS_VERT))
$hVSlider_Handle = GUICtrlGetHandle(-1)
_GUICtrlSlider_SetRangeMax($hVSlider, _GUICtrlEdit_GetLineCount($sEdit))
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
;GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ;Try to Uncomment It Everything Goes Wrong............
ConsoleWrite('Number Of Lines:'&_GUICtrlEdit_GetLineCount($sEdit)&@CRLF)
GUISetState()

Local $sMsg
While $sMsg<>-3
$sMsg=GUIGetMsg()
Switch $sMsg
  Case $sButton1
   _SendMessage($sGUI,$WM_VSCROLL,_MakeLong($SB_LINEUP,GUICtrlRead($hVSlider)-1),$hVSlider_Handle)
   GUICtrlSetData($hVSlider,GUICtrlRead($hVSlider)-1)
  Case $sButton2
   _SendMessage($sGUI,$WM_VSCROLL,_MakeLong($SB_LINEDOWN,GUICtrlRead($hVSlider)+1),$hVSlider_Handle)
   GUICtrlSetData($hVSlider,GUICtrlRead($hVSlider)+1)
EndSwitch
WEnd

Func _GetLineIndex($snEdit)
Return _GUICtrlEdit_GetFirstVisibleLine($snEdit)
EndFunc
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
ConsoleWrite('Handle:'&$hWnd&@CRLF)
ConsoleWrite('Message:'&$iMsg&@CRLF)
ConsoleWrite('Wparam:'&$wParam&@CRLF)
ConsoleWrite('Lo-Wparam:'&_WinAPI_LoWord($wParam)&@CRLF)
ConsoleWrite('Hi-Wparam:'&_WinAPI_HiWord($wParam)&@CRLF)
ConsoleWrite('Lparam:'&$lParam&@CRLF)
ConsoleWrite('Lo-Lparam:'&_WinAPI_LoWord($lParam)&@CRLF)
ConsoleWrite('Hi-Lparam:'&_WinAPI_HiWord($lParam)&@CRLF)
EndFunc

Func WM_VSCROLL($hWnd, $iMsg, $wParam, $lParam)
    If Not $hWnd=$sGUI Then Return 0
    Switch $iMsg
        Case $WM_VSCROLL
            Switch $lParam
                Case $hVSlider_Handle
                    ; Your code goes here
     Local $sRequest=_WinAPI_LoWord($wParam)
     ConsoleWrite('Request:'&$sRequest&@CRLF)
     Local $sindex=_GetLineIndex($sEdit)
     ConsoleWrite('Index:'&$sindex&@CRLF)
     Switch $sRequest
      Case $SB_THUMBTRACK
       $sRequest=_WinAPI_HiWord($wParam)
       $sScroll=$sRequest-$sindex
       If $sScroll<0 Then
        Do
         _SendMessage($sEdit,$EM_SCROLL,$SB_LINEUP)
         $sScroll+=1
        Until $sScroll=0
       ElseIf $sScroll>0 Then
        Do
         _SendMessage($sEdit,$EM_SCROLL,$SB_LINEDOWN)
         $sScroll-=1
        Until $sScroll=0
       EndIf
       ConsoleWrite('SB_THUMBTRACK:'&$sRequest&@CRLF)
       Return 0
      Case $SB_THUMBPOSITION
       $sRequest=_WinAPI_HiWord($wParam)
       $sScroll=$sRequest-$sindex
       If $sScroll<0 Then
        Do
         _SendMessage($sEdit,$EM_SCROLL,$SB_LINEUP)
         $sScroll+=1
        Until $sScroll=0
       ElseIf $sScroll>0 Then
        Do
         _SendMessage($sEdit,$EM_SCROLL,$SB_LINEDOWN)
         $sScroll-=1
        Until $sScroll=0
       EndIf
       ConsoleWrite('SB_THUMBPOSITION:'&$sRequest&@CRLF)
       Return 0
     EndSwitch
     _SendMessage($sEdit,$EM_SCROLL,$sRequest)
     Return 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_HVSCROLL
; Function Name :   _MakeLong
; Description      :   Converts two 16 bit values into on 32 bit value
; Parameter(s)    :   $LoWord     16bit value
;                      :   $HiWord    16bit value
; Return Value(s)   :   Long value
; Note(s)          :
;===============================================================================
Func _MakeLong($LoWord,$HiWord)
  Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc
Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Hi!

Try this:

#include <GUIEdit.au3>
#include <ScrollBarConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <SliderConstants.au3>
#include <GuiSlider.au3>
#include <file.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Local $sGUI = GUICreate('', 500, 200)
Global $sEdit = GUICtrlCreateEdit(FileRead('Project.au3'), 10, 10, 380, 180, 64)
$sEdit = GUICtrlGetHandle(-1)
Local $sButton1 = GUICtrlCreateButton('Up', 400, 10, 80, 20)
Local $sButton2 = GUICtrlCreateButton('Down', 400, 160, 80, 20)
Local $hVSlider = GUICtrlCreateSlider(400, 30, 20, 120, BitOR($TBS_NOTICKS, $TBS_VERT))
$hVSlider_Handle = GUICtrlGetHandle(-1)
_GUICtrlSlider_SetRangeMax($hVSlider, _GUICtrlEdit_GetLineCount($sEdit))
GUISetState()
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")

Local $sMsg
While $sMsg <> -3
    $sMsg = GUIGetMsg()
    Switch $sMsg
        Case $sButton1
            _GUICtrlSlider_SetRangeMax($hVSlider, _GUICtrlEdit_GetLineCount($sEdit))
            _SendMessage($sGUI, $WM_VSCROLL, _MakeLong($SB_LINEUP, GUICtrlRead($hVSlider) - 1), $hVSlider_Handle)
            GUICtrlSetData($hVSlider, GUICtrlRead($hVSlider) - 1)
        Case $sButton2
            _GUICtrlSlider_SetRangeMax($hVSlider, _GUICtrlEdit_GetLineCount($sEdit))
            _SendMessage($sGUI, $WM_VSCROLL, _MakeLong($SB_LINEDOWN, GUICtrlRead($hVSlider) + 1), $hVSlider_Handle)
            GUICtrlSetData($hVSlider, GUICtrlRead($hVSlider) + 1)
    EndSwitch
WEnd

Func _GetLineIndex($snEdit)
    Return _GUICtrlEdit_GetFirstVisibleLine($snEdit)
EndFunc   ;==>_GetLineIndex

Func WM_VSCROLL($hWnd, $iMsg, $wParam, $lParam)
    If Not $hWnd = $sGUI Then Return 0
    Switch $iMsg
        Case $WM_VSCROLL
            Switch $lParam
                Case $hVSlider_Handle
                    ; Your code goes here
                    Local $sRequest = _WinAPI_LoWord($wParam)
                    ConsoleWrite('Request:' & $sRequest & @CRLF)
                    Local $sindex = _GetLineIndex($sEdit)
                    ConsoleWrite('Index:' & $sindex & @CRLF)
                    Switch $sRequest
                        Case $SB_THUMBTRACK
                            $sRequest = _WinAPI_HiWord($wParam)
                            $sScroll = $sRequest - $sindex
                            If $sScroll < 0 Then
                                ;Do
                                _SendMessage($sEdit, $EM_SCROLL, $SB_LINEUP)
                                $sScroll += 1
                                ;Until $sScroll = 0
                            ElseIf $sScroll > 0 Then
                                ;Do
                                _SendMessage($sEdit, $EM_SCROLL, $SB_LINEDOWN)
                                $sScroll -= 1
                                ;Until $sScroll = 0
                            EndIf
                            ConsoleWrite('SB_THUMBTRACK:' & $sRequest & @CRLF)
                            Return 0
                        Case $SB_THUMBPOSITION
                            $sRequest = _WinAPI_HiWord($wParam)
                            $sScroll = $sRequest - $sindex
                            If $sScroll < 0 Then
                                ;Do
                                _SendMessage($sEdit, $EM_SCROLL, $SB_LINEUP)
                                $sScroll += 1
                                ;Until $sScroll = 0
                            ElseIf $sScroll > 0 Then
                                ;Do
                                _SendMessage($sEdit, $EM_SCROLL, $SB_LINEDOWN)
                                $sScroll -= 1
                                ;Until $sScroll = 0
                            EndIf
                            ConsoleWrite('SB_THUMBPOSITION:' & $sRequest & @CRLF)
                            Return 0
                    EndSwitch
                    _SendMessage($sEdit, $EM_SCROLL, $sRequest)
                    Return 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_VSCROLL

; Function Name :   _MakeLong
; Description     :   Converts two 16 bit values into on 32 bit value
; Parameter(s)    :   $LoWord    16bit value
;                     :   $HiWord    16bit value
; Return Value(s)   :   Long value
; Note(s)         :
;===============================================================================
Func _MakeLong($LoWord, $HiWord)
    Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc   ;==>_MakeLong

Regards,

João Carlos.

Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

Thnx for the Reply JScript

But the Script U provided has the Flaws try Scrolling The Slider 10 times Up and Down and See if the Text Scrolled Correctly

Herez the Code which is Works Without any Problem............

But in the Code i have Commented some Parts

Uncomment THem and see What it Does

Working Code:

#include <GUIEdit.au3>
#include <ScrollBarConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <SliderConstants.au3>
#include <GuiSlider.au3>
#include <file.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Local $sGUI=GUICreate('',500,200)
Global $sEdit=GUICtrlCreateEdit(FileRead('Project.au3'),10,10,380,180,64)
$sEdit=GUICtrlGetHandle(-1)
Local $sButton1=GUICtrlCreateButton('Up',400,10,80,20)
Local $sButton2=GUICtrlCreateButton('Down',400,160,80,20)
Local $hVSlider= GUICtrlCreateSlider(400, 30, 20, 120, BitOR($TBS_NOTICKS,$TBS_VERT))
$hVSlider_Handle = GUICtrlGetHandle(-1)
_GUICtrlSlider_SetRangeMax($hVSlider, _GUICtrlEdit_GetLineCount($sEdit))
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
;GUIRegisterMsg($WM_NOTIFY, "WM_COMMAND") ;Try to Uncomment It Everything Goes Wrong............
ConsoleWrite('Number Of Lines:'&_GUICtrlEdit_GetLineCount($sEdit)&@CRLF)
GUISetState()

Local $sMsg
While $sMsg<>-3
$sMsg=GUIGetMsg()
Switch $sMsg
  Case $sButton1
   _SendMessage($sGUI,$WM_VSCROLL,_MakeLong($SB_LINEUP,GUICtrlRead($hVSlider)-1),$hVSlider_Handle)
   GUICtrlSetData($hVSlider,GUICtrlRead($hVSlider)-1)
  Case $sButton2
   _SendMessage($sGUI,$WM_VSCROLL,_MakeLong($SB_LINEDOWN,GUICtrlRead($hVSlider)+1),$hVSlider_Handle)
   GUICtrlSetData($hVSlider,GUICtrlRead($hVSlider)+1)
EndSwitch
WEnd

Func _GetLineIndex($snEdit)
Return _GUICtrlEdit_GetFirstVisibleLine($snEdit)
EndFunc
;Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
;ConsoleWrite('Handle:'&$hWnd&@CRLF)
;ConsoleWrite('Message:'&$iMsg&@CRLF)
;ConsoleWrite('Wparam:'&$wParam&@CRLF)
;ConsoleWrite('Lo-Wparam:'&_WinAPI_LoWord($wParam)&@CRLF)
;ConsoleWrite('Hi-Wparam:'&_WinAPI_HiWord($wParam)&@CRLF)
;ConsoleWrite('Lparam:'&$lParam&@CRLF)
;ConsoleWrite('Lo-Lparam:'&_WinAPI_LoWord($lParam)&@CRLF)
;ConsoleWrite('Hi-Lparam:'&_WinAPI_HiWord($lParam)&@CRLF)
;EndFunc

Func WM_VSCROLL($hWnd, $iMsg, $wParam, $lParam)
    If Not $hWnd=$sGUI Then Return 0
    Switch $iMsg
        Case $WM_VSCROLL
            Switch $lParam
                Case $hVSlider_Handle
                    ; Your code goes here
     Local $sRequest=_WinAPI_LoWord($wParam)
     ConsoleWrite('Request:'&$sRequest&@CRLF)
     Local $sindex=_GetLineIndex($sEdit)
     ConsoleWrite('Index:'&$sindex&@CRLF)
     Switch $sRequest
      Case $SB_THUMBTRACK
       $sRequest=_WinAPI_HiWord($wParam)
       $sScroll=$sRequest-$sindex
       If $sScroll<0 Then
        Do
         _SendMessage($sEdit,$EM_SCROLL,$SB_LINEUP)
         $sScroll+=1
        Until $sScroll=0
       ElseIf $sScroll>0 Then
        Do
         _SendMessage($sEdit,$EM_SCROLL,$SB_LINEDOWN)
         $sScroll-=1
        Until $sScroll=0
       EndIf
       ConsoleWrite('SB_THUMBTRACK:'&$sRequest&@CRLF)
       Return 0
      Case $SB_THUMBPOSITION
       $sRequest=_WinAPI_HiWord($wParam)
       $sScroll=$sRequest-$sindex
       If $sScroll<0 Then
        Do
         _SendMessage($sEdit,$EM_SCROLL,$SB_LINEUP)
         $sScroll+=1
        Until $sScroll=0
       ElseIf $sScroll>0 Then
        Do
         _SendMessage($sEdit,$EM_SCROLL,$SB_LINEDOWN)
         $sScroll-=1
        Until $sScroll=0
       EndIf
       ConsoleWrite('SB_THUMBPOSITION:'&$sRequest&@CRLF)
       Return 0
     EndSwitch
     _SendMessage($sEdit,$EM_SCROLL,$sRequest)
     Return 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_HVSCROLL
; Function Name :   _MakeLong
; Description      :   Converts two 16 bit values into on 32 bit value
; Parameter(s)    :   $LoWord     16bit value
;                      :   $HiWord    16bit value
; Return Value(s)   :   Long value
; Note(s)          :
;===============================================================================
Func _MakeLong($LoWord,$HiWord)
  Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc

Check This Line

Global $sEdit=GUICtrlCreateEdit(FileRead('Project.au3'),10,10,380,180,64)
Replace
FileRead('Project.au3')
with any of your Files having Multiple Lines

Please Reply Me If U find the Solution........

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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...