Borje:
GetWindowLong(hWnd, GWL_STYLE) returns the current state of the window
so this behaviour is normal. See the following MSKB article.
Value Returned by GetWindowLong(hWnd, GWL_STYLE) Article ID: Q83366
------------------
Dominic Mitchell
Announcement
Collapse
No announcement yet.
GetScrollInfo
Collapse
X
-
I also tested (under Win2000).
Code:#Compile Exe #Register None #Dim All #Include "win32api.inc" Sub ScrollTest (hWnd As Long) Local w As Asciiz * 20 If (GetWindowLong(hWnd, %GWL_STYLE) And %WS_VSCROLL) Then w$ = "VSCROLL" If (GetWindowLong(hWnd, %GWL_STYLE) And %WS_HSCROLL) Then w$ = Trim$(w$ + " HSCROLL") SetWindowText hWnd, w End Sub CallBack Function ShowHScroll: ShowScrollBar CbHndl, %SB_HORZ, 1: ScrollTest CbHndl: End Function CallBack Function ShowVScroll: ShowScrollBar CbHndl, %SB_VERT, 1: ScrollTest CbHndl: End Function CallBack Function HideHScroll: ShowScrollBar CbHndl, %SB_HORZ, 0: ScrollTest CbHndl: End Function CallBack Function HideVScroll: ShowScrollBar CbHndl, %SB_VERT, 0: ScrollTest CbHndl: End Function Function PbMain Local hDlg As Long Dialog New hDlg, "Test", , , 120, 150, %WS_OVERLAPPEDWINDOW To hDlg Control Add Button, hDlg, 101, "Show HScroll", 10, 10, 80, 12 Call ShowHScroll Control Add Button, hDlg, 102, "Show VScroll", 10, 30, 80, 12 Call ShowVScroll Control Add Button, hDlg, 103, "Hide HScroll", 10, 50, 80, 12 Call HideHScroll Control Add Button, hDlg, 104, "Hide VScroll", 10, 70, 80, 12 Call HideVScroll Dialog Show Modal hDlg End Function
------------------
E-MAIL: [email protected]
Leave a comment:
-
-
Yes, controls only there. Agree - strange that there is no way to find
this out easily. Hm, looked at messages. WM_WINDOWPOSCHANGED, WM_NCCALCSIZE
and WM_SIZE are triggered when scrollbars are added. Guess WM_SIZE is good
checkpoint.
But, also looked at styles. Looks like Matthew is right. WS_VSCROLL and
WS_HSCROLL style seems to depends on if any of those scrollbars are visible.
So following actually seems to work (only tested with list and edit control)
Code:'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ' Check if a control's scrollbars are shown. ' Returns zero if none, 1 if vertical, 2 if horizontal and 3 if both. '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ FUNCTION ScrollShown(BYVAL hWnd AS LONG) AS LONG LOCAL lRes AS LONG IF (GetWindowLong(hWnd, %GWL_STYLE) AND %WS_VSCROLL) THEN lRes = 1 IF (GetWindowLong(hWnd, %GWL_STYLE) AND %WS_HSCROLL) THEN lRes = lRes + 2 FUNCTION = lRes END FUNCTION
Did a quick test in MDI app's client area and moved pads in/out to force
scrollbars on/off - worked fine! Think Matthew is right..
[This message has been edited by Borje Hagsten (edited October 24, 2001).]
Leave a comment:
-
-
Borje's code states "control" rather than "dialog" or "window", so I gather he is just demonstrating a general concept.
------------------
Lance
PowerBASIC Support
mailto:[email protected][email protected]</A>
Leave a comment:
-
-
Borje -
What about windows with caption / menu ?
I agree that it's possible anyway (to test styles, is menu present), but strange that API doesn't offer direct way.
[This message has been edited by Semen Matusovski (edited October 24, 2001).]
Leave a comment:
-
-
Without storing anything, or causing flicker - tested and works with
ClientEdge on/off..
Code:'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ' Check if a control's scrollbars are shown. ' Returns zero if none, 1 if vertical, 2 if horizontal and 3 if both. '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ FUNCTION ScrollShown(BYVAL hWnd AS LONG) AS LONG LOCAL lRes AS LONG, rc AS RECT, rc2 AS RECT GetWindowRect hWnd, rc GetClientRect hWnd, rc2 IF rc2.nRight <= rc.nRight - rc.nLeft - GetSystemMetrics(%SM_CXVSCROLL) THEN lRes = 1 IF rc2.nBottom <= rc.nBottom - rc.nTop - GetSystemMetrics(%SM_CXHSCROLL) THEN lRes = lRes + 2 FUNCTION = lRes END FUNCTION
------------------
Leave a comment:
-
-
Thats exactly what I do too... I track my own scroll positions, etc, and just set the control according to the %WM_xSCROLL message type (line up/down, page up/down, etc).
I find it much easier than reading the info and trying to correlate it back to the desired position.
------------------
Lance
PowerBASIC Support
mailto:[email protected][email protected]</A>
Leave a comment:
-
-
Guys --
In certain situation (my custom control by itself decides to turn on or off scroll bars) I found simple workaround - decided to keep SCROLLINFO instead of retrieving it.
Just now I mostly worry about external windows, because somehow I wrote a fragment, which simply tests return code of GetScrollInfo.
I agree with Borje about styles - at least for my control it's not important.
To use GetClientRect is reliable, but will be flickers, because this method means that it's neccessary to do ShowScrollBar %FALSE, and if client area was changed, to mark "there is scroll bar" and to turn it on.
Maybe something else return status of scroll bar ?
------------------
E-MAIL: [email protected]
Leave a comment:
-
-
A control can have WS_VSCROLL/WS_HSCROLL style but not show scrollbar.
In empty control, can grab "clean" client rect in static RECT for
later compare in WM_SIZE.
Then again, filling SetScrollInfo with zeroes on hide looks like a
better/faster/prettier way to me..
------------------
Leave a comment:
-
-
Semen--
Quick question, are you using a normal window, or one of the predefined controls?
--Jules
------------------
Leave a comment:
-
-
Have you tried testing the window style for WS_HSCROLL and/or WS_VSCROLL?
Leave a comment:
-
-
Maybe can use GetClientRect? With/without scrollbar - different rects.
------------------
Leave a comment:
-
-
GetScrollInfo
Hi, guys --
Noticed one strange moment (at least, under Win2000).
I expected that GetScrollInfo should return 0, if there is no scroll bar.
But it retrieves something.
I can find workaround, because I enable/disable scroll bars by myself, but maybe you know reliable way to determine, whether scroll bar exist ?
BTW, situation is following.
I set ScrollInfo. When I see that scroll bar is not neccessary I do ShowScrollBar %False.
Looks, like it's necessary to do SetScrollInfo with zeroes also.
------------------
E-MAIL: [email protected]
[This message has been edited by Semen Matusovski (edited October 23, 2001).]Tags: None
-
Leave a comment: