Jump to content

Resizing Tab control with Richedit


Go to solution Solved by Melba23,

Recommended Posts

HI all -

I need some help with resizing my GUI that has many controls on it including a richedit control. I was having it all resize automatically, but found out that rich edits do not work that way. So I searched the forums and found WM_Size so that fixed my richedit. but nothing else resizes any more. I have about 15 items that need to be resized.

Below is a code snippet showing my issue.

Any suggestions for forum searches would be appreciated or a function I should use.

Thanks Again ahead of time.

; Credit for soem of this script comes from :http://www.autoitscript.com/wiki/Tabs
#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <GUIImageList.au3>
#include <WindowsConstants.au3>
#include <GuiTab.au3>

GUIRegisterMsg($WM_SIZE, "WM_SIZE")

    $hGUI = GUICreate("Tabs w/RichEdit To be resized", 500, 500, -1, -1,$WS_SIZEBOX)

    global $TabShtMain = GUICtrlCreateTab(10, 10, 480, 480)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP)
    global $testtab1 = GUICtrlCreateTabItem("Plain CreateEdit Field")
    Global $Input = GUICtrlCreateEdit("", 20, 40, 460, 400, $WS_VSCROLL)
    GUICtrlCreateTabItem("Richtext Field"   )
    $hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 20,40,460,400, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    ControlHide($hGUI, "", $hRichEdit)
    GUICtrlCreateTabItem("")
    GUISetState(@SW_SHOW, $hGUI) ; Makes GUI Visible
 $iLastTab = 0
 While 1
     Switch GUIGetMsg()
         Case $GUI_EVENT_CLOSE
             Exit
         Case $TabShtMain
             ; Check which Tab is active
             $iCurrTab = GUICtrlRead($TabShtMain)
             ; If the Tab has changed
             If $iCurrTab <> $iLastTab Then
                 ; Show/Hide controls as required
                 Switch $iCurrTab
                    Case 0
                        ControlHide($hGUI, "", $hRichEdit)
                    Case 1
                        ControlShow($hGUI, "", $hRichEdit)
                 EndSwitch
                 ; Store the value for future comparisons
                 $iLastTab = $iCurrTab
             EndIf
     EndSwitch
 WEnd

Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    Local $iWidth = _WinAPI_LoWord($lParam)
    Local $iHeight = _WinAPI_HiWord($lParam)
    _WinAPI_MoveWindow($hRichEdit, 20, 40, $iWidth - 40, $iHeight - 100)
    Return 0
EndFunc   ;==>WM_SIZE
Edited by MacScript
Link to comment
Share on other sites

Found this  and have added  GUICtrlSetPos for each control that needs to be resized into the WM_Size function.

1) Is this the correct way to do this or is there a better way? 

2) Seems like my gui is not as responsive as it was prior to adding in WM_size registration. Does WM_Size  add more cpu cycles?

Thanks for all responses, I appreciate the help I get from the Autoit Community.

Link to comment
Share on other sites

  • Moderators
  • Solution

MacScript,

You need to return $GUI_RUNDEFMSG from the original message handler - at present you are returning 0 which tells AutoIt to ignore the message and so it does not honour the size change for its own controls:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiRichEdit.au3>

Opt("GUIResizeMode",$GUI_DOCKAUTO)

$hGUI = GUICreate("Tabs w/RichEdit to be resized", 500, 500, -1, -1, $WS_SIZEBOX)

Global $TabShtMain = GUICtrlCreateTab(10, 10, 480, 460)

GUICtrlCreateTabItem("Plain CreateEdit Field")
Global $Input = GUICtrlCreateEdit("", 20, 40, 460, 420, $WS_VSCROLL)
GUICtrlCreateTabItem("Richtext Field")
GUICtrlCreateTabItem("")

GUISetState(@SW_SHOW, $hGUI) ; Makes GUI Visible

$hRichEdit = _GUICtrlRichEdit_Create($hGUI, "", 20, 40, 460, 420, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
ControlHide($hGUI, "", $hRichEdit)

GUIRegisterMsg($WM_SIZE, "WM_SIZE")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $TabShtMain
            ConsoleWrite("Hit" & @CRLF)

            ; Check which Tab is active
            $iCurrTab = GUICtrlRead($TabShtMain)
            ; Show/Hide controls as required
            Switch $iCurrTab
                Case 0
                    ControlHide($hGUI, "", $hRichEdit)
                Case 1
                    ControlShow($hGUI, "", $hRichEdit)
            EndSwitch
    EndSwitch
WEnd

Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    If $hWnd = $hGUI Then
        Local $iWidth = _WinAPI_LoWord($lParam)
        Local $iHeight = _WinAPI_HiWord($lParam)
        _WinAPI_MoveWindow($hRichEdit, 20, 40, $iWidth - 40, $iHeight - 40)
    EndIf
    Return $GUI_RUNDEFMSG ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
EndFunc   ;==>WM_SIZE
Note that you do not need to track the tab index - the tab control only fires an event when the tab is changed, so the index will always be different. ;)

I have never noticed any slow-down when registering Windows messages. Perhaps if you posted the whole script we might be able to offer some advice on why this might be happening. :)

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

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