- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have created a dialog box with a list box in the resource.Under property style I have checked the vertical and horizontal scroll. When I execute the program andthe dialog box is displayed the list box shows the vertical scroll bar and it does work. Butit does not show thehorizontalscrollbar.
How would I make display both working vertical and horizontal scrollbar?
Any help is appriciated.
thanks
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is (broken) by design. List boxes do not display horizontal scrollbar unless you tell them explicitly what's the length of the (longest) item, in pixels.
LB_SETHORIZONTALEXTENT message sets the length of scrollbar thumb and shows it if necessary. As any Windows message used with DFLOGM, it will work only when called from a dialog callback. In addition, you have to select the text into a DC and then measure it in pixels in order to obtain the length. Here you are (untested):
Code:
If you fill in the list box on startup, you should define a startup (DLG_INIT callback) and call the subroutine above from there. If you change the list box' contents dynamically, you have to call the subroutine after every change (or optimize it a little so that you don't iterate through entire list every time).Subroutine SetHorzScrollbar(Dlg, idListBox) use Dflogm use Dfwin implicit none type(Dialog):: Dlg integer, intent(in):: idListBox integer:: hDC, b, hFont, nItems, i, hOldFont, maxLen type(T_SIZE):: SZ character(200):: sItem hFont = DlgSendCtrlMessage(Dlg, idListBox, WM_GETFONT, 0, 0) nItems = DlgSendCtrlMessage(Dlg, idListBox, LB_GETCOUNT, 0, 0) hDC = GetDC(GetDlgItem(Dlg%hWnd, idListBox)) hOldFont = SelectObject(hDC, hFont) maxLen = 0 do i = 0, nItems-1 !Get the i-th item b = DlgSendCtrlMessage(Dlg, idListBox, LB_GETTEXT, i, LOC(sItem)) !Measure the text length in pixels b = GetTextExtentPoint32(hDC, sItem, index(sItem,char(0)-1), SZ) maxLen = max(maxLen, SZ%cx) end do b = DlgSendCtrlMessage(Dlg, idListBox, LB_SETHORIZONTALEXTENT, maxLen+5, 0)
b = SelectObject(hDC, hOldFont)
b = ReleaseDC(GetDlgItem(Dlg%hWnd), idListBox) end subroutine SetHorzScrollbar
Jugoslav
Message Edited by JugoslavDujic on 08-27-2004 09:44 AM
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page