Jump to content

Find out the size of the scrollbars


Angel
 Share

Recommended Posts

Hi,

I made a window that inside has an mutli-line editbox which I want to completelly fill the window. I want the editbox to have both vertical and horizontal scrollbars. I want the window (and the editbox inside it) to be resizable.

My problem is that it seems that the size of the editbox does not include the scrollbars. So when I resize the window the scrollbars end up "outside" of the window.

I've tried to compensate for this by making the editbox smaller than the window, but it seems that the actual size of the scrollbars depends on the operating system (windows2000 or xp) and probably also on the selected theme.

Is there a simple way to set the editbox size including the scrollbars or at least a way to get the size (in pixels) of the scrollbars?

And, for bonus points, is there some way to make the horizontal scrollbar only appear when the text actually is bigger than the size of the editbox? (I know that scrollbars get automatically is disabled/enabled but I'd rather have them disappear when not needed).

Thanks!

Angel

Link to comment
Share on other sites

To answer your second question, scrollbars don't disappear when they aren't needed (yet), they simply show up disabled. Look around at virtually every Windows application using an edit control and you'll see that behavior.

To answer your first question, that behavior sounds wrong. The scrollbar should be drawn in the client area, not the non-client area. In fact, I have a GUI with a vertical scrollbar and it looks fine so you'll need to post an example of that problem. What you describe should not be happening.

Link to comment
Share on other sites

To answer your second question, scrollbars don't disappear when they aren't needed (yet), they simply show up disabled. Look around at virtually every Windows application using an edit control and you'll see that behavior.

To answer your first question, that behavior sounds wrong. The scrollbar should be drawn in the client area, not the non-client area. In fact, I have a GUI with a vertical scrollbar and it looks fine so you'll need to post an example of that problem. What you describe should not be happening.

Thanks for the answer Valik. Before posting any code I just wanted to know if there was some obvious reason for this problem.

This is my current code. It is in a separate autoit file that I include from my main gui file. This is actually not my code, originally. One colleague wrote it and I am updating it:

#include-once
Opt("MustDeclareVars",1)

#Include <GuiEdit.au3>

Global $LogLibDebugShowLineNumbers = False

global $logVar
global $logWindowId
global $logCtrlId
global $logFileName = @scriptdir & "\log_results.log"
global $logFileHandle = -1 ; This default value means that the log has not been open yet
global $EM_SETLIMITTEXT = 0x00C5
global $EditBufSize = 20000000
global $baseLowWindowTitle

;- State variables
Global $vLastLogWindowSize
Global $bIslogWindowMaximized = False


;******************************************
; Function to print new line to output log
;******************************************
func CreateLogWindow($title, $width="", $height="", $left="", $top="", $style="", $exStyle="", $parent="")
  ;dim $logWindowId

  ; Create GUI window
  Switch @NUMPARAMS
    Case 1
      $width = 501
      $height = 401
      $logWindowId = GUICreate($title, $width, $height)
    Case 2
      $height = 401
      $logWindowId = GUICreate($title, $width, $height)
    Case 3
      $logWindowId = GUICreate($title, $width, $height)
    Case 4
      $logWindowId = GUICreate($title, $width, $height, $left)
    Case 5
      $logWindowId = GUICreate($title, $width, $height, $left, $top)
    Case 6
      $logWindowId = GUICreate($title, $width, $height, $left, $top, $style)
    Case 7
      $logWindowId = GUICreate($title, $width, $height, $left, $top, $style, $exStyle)
    Case Else
      $logWindowId = GUICreate($title, $width, $height, $left, $top, $style, $exStyle, $parent)
  EndSwitch

  ; Assign the function that will handle the "Maximize" event
  GUISetOnEvent($GUI_EVENT_MAXIMIZE,"LogWindowMaximize",$logWindowId)
  ; The close event is already setup on the main hsdpa_perf autoit file
  
  ; Create edit control
  $logVar = ""
  $logCtrlId = GUICtrlCreateEdit("", 0, 0, $width-2, $height-21, BitOR( _
    $ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL,$ES_MULTILINE))
  
  ; Increase size of data that edit control can hold
  GuiCtrlSetLimit($logCtrlId, $EditBufSize) ; Set the max number of lines to $EditBufSize
  
  ; Delete old log file
  FileDelete($logFileName)
  
  ; Save the selected window title as the "base window title" that will be always be set at the beginning of the window title
  $baseLowWindowTitle = $title

  return($logWindowId)
endfunc
oÝ÷ Ø2¢ëx¦ºÈ§Múè ݵ¶b+mëÞ®Øj["Íê¶v+[£­êðÇ­ë®emªâ²«¨¶­²'^¡ûa{§v*ºH|ÞvìÞ¶¬7¨~Ø^Â)Ý£¥¢Ò,yëazÇ+¢Y[j»-j»m¡ªiyªâÈzØ^Â)Ý£"f¤zØ^Â)ݣ⫶¬rº%¶«u릮Ç(^µéeÈíézk¢
ÚØ^Â)Ý£¬r·µçZ±ú%,jëh×6
dim $hLog = CreateLogWindow("Log data", 701, 401, 494, 100, $WS_MAXIMIZEBOX+$WS_SIZEBOX, -1, $HSDPA_main)

I am pretty sure that I (or the original coder) am doing something wrong but I don't know what... :P

Thanks,

Angel

Link to comment
Share on other sites

Did you write the case structure? If you did, please get your colleague to slap your head. If your colleague wrote it, please slap your colleague in the head. Preferably hard. That code is stupid and redundant. This function is equivalent without the stupid case structure:

func CreateLogWindow($title, $width= Default, $height=Default, $left=Default, $top=Default, $style=Default, $exStyle=Default, $parent=0)
  ;dim $logWindowId

    If Number($width) <= 0 Then $width = 501
    If Number($height) <= 0 Then $height = 401
    $logWindowId = GUICreate($title, $width, $height, $left, $top, $style, $exStyle, $parent)

  ; Assign the function that will handle the "Maximize" event
  GUISetOnEvent($GUI_EVENT_MAXIMIZE,"LogWindowMaximize",$logWindowId)
  ; The close event is already setup on the main hsdpa_perf autoit file

  ; Create edit control
  $logVar = ""
  $logCtrlId = GUICtrlCreateEdit("", 0, 0, $width-2, $height-2, BitOR( _
    $ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL,$ES_MULTILINE))

  ; Increase size of data that edit control can hold
  GuiCtrlSetLimit($logCtrlId, $EditBufSize) ; Set the max number of lines to $EditBufSize

  ; Delete old log file
  FileDelete($logFileName)

  ; Save the selected window title as the "base window title" that will be always be set at the beginning of the window title
  $baseLowWindowTitle = $title

  return($logWindowId)
endfunc
 oÝ÷ Ø¢·X§ØZµû§rبÚ"¶X¤zØb³­l¦z+yØ­±©ÝÊ«ªê-¦ºéªº`¡ëÁ¬ºÚ"µÍÜX]SÙÕÚ[ÝÉÍÉ][ÝÓÙÈ]I][ÝË
ÌK
K
ML  ÌÍÕÔ×ÓÕTTQÒSÕËLK  ÍNÂ

The window needs to be WS_OVERLAPPEDwindow.

Link to comment
Share on other sites

Also, I recommend setting the edit control's width and height to exactly that of the parent GUI. If you do that, then the small area at the lower right where the two scrollbars form an empty box will be drawn with a gripper which denotes the window can be resized. I also recommend handing the resize event yourself because AutoIt does a less than perfect job of automatically resizing the control as the window is resized. Of course, the gripper may not matter since it seems you are creating this GUI as a child of another GUI (I'm assuming embedding here) in which case the GUI needs the WS_CHILD style instead of WS_OVERLAPPEDwindow.

Edit: Fixed various mistakes.

Edited by Valik
Link to comment
Share on other sites

Did you write the case structure? If you did, please get your colleague to slap your head. If your colleague wrote it, please slap your colleague in the head. Preferably hard.

ahah! I think this one could be added to the list of "Valik quotes" :P

My colleague did write the code, but in his defense it was the very first function that he ever wrote in AutoIt, so I should have pointed out to him a better way to do it. But we have so much to do that I just did not find the time to go back to this until I tried to figure out the reason for the problem with the editbox size.

I still do not understand the reason why the editbox was behaving as it was. Do you know why? Was it due to the attributes that he was using ($WS_MAXIMIZEBOX+$WS_SIZEBOX)?

You are correct in guessing that this is the child of another window, so we'll use WS_CHILD.

Thanks again for the help.

Angel

Link to comment
Share on other sites

Angel, it came to me a bit ago. The problem isn't what style you did pass, it's what style you didn't pass. Read this thread for the problem. The short of it is, the edit control was being created at the right size, the window was not, so the edit control's scrollbar was being cut off.

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