Jump to content

Gui dragbar


step887
 Share

Recommended Posts

I tried to use Melba23's GuiFrames, but I could not get it to work with richtext edit..

So coded my own version, and it works, but the issue is when I moved the dragbar, it flickers sometimes when there is a gui bkcolor specify...not a major issue, but an annoyance..

So I am looking for some feedback on how I might be able to do improve this

Thanks in advance

#include <WindowsConstants.au3>
#include <Guirichedit.au3>
#include <GUIConstantsEx.au3>
Global $width = 300;of gui
Global $height = 600;of gui
Global $border = 6;around edit boxes
Global $percent_height = .5;percentage of per each box
Global $max_upper_height_percent = .2;set the upper limit that dragbox can be move too
Global $max_lower_height_percent = .8;set the lower limit that dragbox can move too
global $edit1_width, $edit1_height, $edit2_top, $edit2_height, $dragbar = False
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
GUIRegisterMsg($WM_SIZE, 'my_Resize')
$bgcolor = _random_color();got bored and wanted varity
_Update_values();I used this because when the height and width changed, the values did not update
$GUI = GUICreate("My GUI", $width, $height, Default, Default, BitOr($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
GUISetBkColor($bgcolor)
$Edit1 = _GUICtrlRichEdit_Create($GUI, "", $border, $border, $edit1_width, $edit1_height, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
$edit2 = GUICtrlCreateEdit("", $border, $edit2_top, $edit1_width, $edit2_height, BitOr("Ox503310C4", $WS_VSCROLL))
GUICtrlSetResizing(-1, $GUI_DOCKALL);did not want the gui to control resizing
$label = GUICtrlCreateLabel("", 0, $border + $edit1_height, $width, $border, 0x0100)
GUICtrlSetBkColor(-1, _random_color());set the dragbar to different color
GUICtrlSetCursor(-1, 11);set to show up/down arrow
GUICtrlSetResizing(-1, $GUI_DOCKALL);did not want the gui to control resizing
GUISetState()
Do
If $dragbar = True Then; set by my_wm_command
  While _IsPressed("01");while left mouse button is pressed
   $arr = GUIGetCursorInfo($GUI)
   If _mousemove($arr[1]) Then;did not want to do anything unless mouse is moved
    If $arr[1] > $height * $max_upper_height_percent = .2 And $arr[1] < $height * $max_lower_height_percent Then;; limit the dragbar
     _WinAPI_MoveWindow($Edit1, $border, $border, $edit1_width, $arr[1] - $border); move rich edit box
     GUICtrlSetPos($label, 0, $arr[1], $width);move label --ie dragbar
     GUICtrlSetPos($edit2, $border, $arr[1] + $border, $edit1_width, $height - ($arr[1] - $border) - $border * 3);move regular edit box
    EndIf
   EndIf
  Wend
  $arr = GUIGetCursorInfo($GUI);get final postion of mouse
  $percent_height = ($arr[1] - $border) / $height;update the new percent height
  _Update_values()
  $dragbar = False
EndIf
until GUIGetMsg() = -3
Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
local $STN_CLICKED = 0
Local $nID = BitAND($wParam, 0xFFFF)
Local $nNotifyCode = BitShift($wParam, 16)
If $nNotifyCode = $STN_CLICKED Then $dragbar = True
Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_COMMAND
Func my_Resize($hWnd, $iMsg, $iwParam, $lParam)
$height = BitShift($lParam, 16)
$width = BitAND($lParam, 0xFFFF)
_Update_values()
_WinAPI_MoveWindow($Edit1, $border, $border, $edit1_width, $edit1_height)
GUICtrlSetPos($edit2, $border, $edit2_top, $edit1_width, $edit2_height)
GUICtrlSetPos($label, 0, $border + $edit1_height, $width, $border)
Return 'GUI_RUNDEFMSG'
EndFunc   ;==>my_Resize
Func _Update_values()
$edit1_width = $width - $border * 2
$edit1_height = ($height - $border * 3) * $percent_height
$edit2_top = $edit1_height + $border * 2
$edit2_height = $height - $edit1_height - $border * 3
EndFunc   ;==>_Update_values
Func _mousemove($orig)
local $ret = GUIGetCursorInfo($GUI)
If $orig = $ret[1] Then Return False
Return True
EndFunc   ;==>_mousemove
Func _random_color()
local $i = "0x", $data = "1234567890abcdef"
$data = StringSplit($data, "")
for $c = 1 to 6
  $i &= $data[Random(0, $data[0], 1)]
Next
Return $i
EndFunc   ;==>_random_color
Link to comment
Share on other sites

  • Moderators

step887,

I have no problem using my UDF with a RichEdit if I do it like this: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GUIRichEdit.au3>

#include <GUIFrame.au3>

Global $fChanged = False

$hGUI = GUICreate("Test", 300, 600)

; Create a 1st level frame
$iFrame_A = _GUIFrame_Create($hGUI, 1)

GUISetState()

; Create the 2 edits
_GUIFrame_Switch($iFrame_A, 1)
$hTopFrame = _GUIFrame_GetHandle($iFrame_A, 1)
$aWinSize = WinGetClientSize($hTopFrame)
$hEdit1 = _GUICtrlRichEdit_Create($hTopFrame, "", 5, 5, $aWinsize[0] - 10, $aWinsize[1] - 10, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
_GUIFrame_Switch($iFrame_A, 2)
$hBottomFrame = _GUIFrame_GetHandle($iFrame_A, 2)
$aWinSize = WinGetClientSize($hBottomFrame)
$cEdit2 = GUICtrlCreateEdit("", 5, 5, $aWinsize[0] - 10, $aWinsize[1] - 10, BitOR("Ox503310C4", $WS_VSCROLL))

_GUIFrame_ResizeSet(0)

; Register the SIZE message to look for the seperator bar moving
GUIRegisterMsg($WM_SIZE, "_WM_SIZE")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    ; See if the frame has been resized
    If $fChanged = True Then
        ; Clear the flag
        $fChanged = False
        ; Resize the RichEdit
        $aWinSize = WinGetClientSize($hTopFrame)
        WinMove($hEdit1, "", 5, 5, $aWinsize[0] - 10, $aWinsize[1] - 10)
    EndIf
WEnd

Func _WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    ; Do the normal resizing frame resizing
    _GUIFrame_SIZE_Handler($hWnd, $iMsg, $wParam, $lParam)
    ; Set the flag if the top frame has been resized
    If $hWnd = $hTopFrame Then
        $fChanged = True
    EndIf
EndFunc

Does that help? :)

As to the flickering, I have been trying to solve that problem for ages without success. Please let me know if you ever find a solution. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Melba,

So I think I found the answer.. I stumbled on to this

http://www.catch22.net/tuts/flicker-free-drawing

Basically, when you set the gui background and then you put a control on top, each time you resize, windows has to redraw the background color, which causes the flicker

So what I did in previous example, I did not set GUISetBkColor, instead I created labels for the borders and now I do not see the flicker..

#include <WindowsConstants.au3>
#include <Guirichedit.au3>
#include <GUIConstantsEx.au3>
Global $width = 300;of gui
Global $height = 600;of gui
Global $border = 6;around edit boxes
Global $percent_height = .5;percentage of per each box
Global $max_upper_height_percent = .2;set the upper limit that dragbox can be move too
Global $max_lower_height_percent = .8;set the lower limit that dragbox can move too
Global $edit1_width, $edit1_height, $edit2_top, $edit2_height, $dragbar = False
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
GUIRegisterMsg($WM_SIZE, 'my_Resize')
$bgcolor = _random_color();got bored and wanted varity
_Update_values();I used this because when the height and width changed, the values did not update
$GUI = GUICreate("My GUI", $width, $height, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX,$WS_POPUPWINDOW))
;>>>added borders and did not set the gui color
$top_border = GUICtrlCreateLabel("",0,0,$width,$border)
GUICtrlSetBkColor(-1,$bgcolor)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$left_border =  GUICtrlCreateLabel("",0,0,$border,$height)
GUICtrlSetBkColor(-1,$bgcolor)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$bottom_border = GUICtrlCreateLabel("",0,$height-($border),$width,$border)
GUICtrlSetBkColor(-1,$bgcolor)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$right_border =  GUICtrlCreateLabel("",$width - ($border),0,$border,$height)
GUICtrlSetBkColor(-1,$bgcolor)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
;end adding borders
$Edit1 = _GUICtrlRichEdit_Create($GUI, "", $border, $border, $edit1_width, $edit1_height, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
_GUICtrlRichEdit_SetBkColor($edit1, _random_color())
$edit2 = GUICtrlCreateEdit("", $border, $edit2_top, $edit1_width, $edit2_height, BitOR("Ox503310C4", $WS_VSCROLL))
GUICtrlSetBkColor(-1,_random_color())
GUICtrlSetResizing(-1, $GUI_DOCKALL);did not want the gui to control resizing
$label = GUICtrlCreateLabel("", 0, $border + $edit1_height, $width, $border, 0x0100)
GUICtrlSetBkColor(-1, _random_color());set the dragbar to different color
GUICtrlSetCursor(-1, 11);set to show up/down arrow
GUICtrlSetResizing(-1, $GUI_DOCKALL);did not want the gui to control resizing
GUISetState()
Do
If $dragbar = True Then; set by my_wm_command
  While _IsPressed("01");while left mouse button is pressed
   $arr = GUIGetCursorInfo($GUI)
   If _mousemove($arr[1]) Then;did not want to do anything unless mouse is moved
    If $arr[1] > $height * $max_upper_height_percent = .2 And $arr[1] < $height * $max_lower_height_percent Then;; limit the dragbar
     _WinAPI_MoveWindow($Edit1, $border, $border, $edit1_width, $arr[1] - $border); move rich edit box
     GUICtrlSetPos($label, 0, $arr[1], $width);move label --ie dragbar
     GUICtrlSetPos($edit2, $border, $arr[1] + $border, $edit1_width, $height - ($arr[1] - $border) - $border * 3);move regular edit box
    EndIf
   EndIf
  WEnd
  $arr = GUIGetCursorInfo($GUI);get final postion of mouse
  $percent_height = ($arr[1] - $border) / $height;update the new percent height
  _Update_values()
  $dragbar = False
EndIf
Until GUIGetMsg() = -3
Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
Local $STN_CLICKED = 0
Local $nID = BitAND($wParam, 0xFFFF)
Local $nNotifyCode = BitShift($wParam, 16)
If $nNotifyCode = $STN_CLICKED Then $dragbar = True
Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_COMMAND
Func my_Resize($hWnd, $iMsg, $iwParam, $lParam)
$height = BitShift($lParam, 16)
$width = BitAND($lParam, 0xFFFF)
_Update_values()
_WinAPI_MoveWindow($Edit1, $border, $border, $edit1_width, $edit1_height)
GUICtrlSetPos($edit2, $border, $edit2_top, $edit1_width, $edit2_height)
GUICtrlSetPos($label, 0, $border + $edit1_height, $width, $border)
GUICtrlSetPos($top_border,0,0,$width,$border)
GUICtrlSetPos($left_border,0,0,$border,$height)
GUICtrlSetPos($bottom_border,0,$height-($border),$width,$border)
GUICtrlSetPos($right_border,$width - ($border),0,$border,$height)
Return 'GUI_RUNDEFMSG'
EndFunc   ;==>my_Resize
Func _Update_values()
$edit1_width = $width - $border * 2
$edit1_height = ($height - $border * 3) * $percent_height
$edit2_top = $edit1_height + $border * 2
$edit2_height = $height - $edit1_height - $border * 3
EndFunc   ;==>_Update_values
Func _mousemove($orig)
Local $ret = GUIGetCursorInfo($GUI)
If $orig = $ret[1] Then Return False
Return True
EndFunc   ;==>_mousemove
Func _random_color()
Local $i = "0x", $data = "1234567890abcdef"
$data = StringSplit($data, "")
For $c = 1 To 6
  $i &= $data[Random(0, $data[0], 1)]
Next
Return $i
EndFunc   ;==>_random_color
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...