- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'd really appreciate it if someone could give me a tip with making a dialog box in which there is a list box capable of horizontal scrolling (if the text is longer than the window width). There is no problem with the vertical scroll working, but even with the "horizontal scroll" checked off, the latter is not working. Is there some other thing I need to do in order to activate horizontal scrolling? Thanks alot...Rob
p.s. I've attached a small program that demonstrates the problem.
p.s. I've attached a small program that demonstrates the problem.
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As MS would say, "This feature is by design". (Read: The design was very stupid, but now we mustn't change it because it would break existing programs). To make long story short, a list box, even with WS_HSCROLL style set, does not adjust horizontal scrollbar automatically. You have to send it a LB_SETHORIZONTALEXTENT message:
sItem() above are strings from the list. Of course, you can retrieve them using DlgGet. The code must be placed in a callback function; best, define a dialog-initialization callback (DlgSetSub(Dlg, IDD_MYDIALOG, OnDlgInit)) which is called immediately after DlgModal.
See Russ Freeman's home page for detailed discussion and a general solution (but it's in C, so it might not be applicable in your case).
HTH
Jugoslav
USE DFWIN TYPE(T_SIZE):: PT TYPE(T_RECT):: Rect INTEGER:: maxLen, hDC, hFont, hOldFont, i, j ... maxLen=0 hDC = GetDC(GetDlgItem(Dlg%hWnd, IDC_LIST1)) hFont = GetStockObject(DEFAULT_GUI_FONT) hOldFont = SelectObject(hDC, hFont) DO i=1,nItems j = GetTextExtentPoint32(hDC, sItem(i), LEN_TRIM(sItem(i)), PT) maxLen = MAX(maxLen, PT%cx) END DO j = SendMessage(GetDlgItem(Dlg%hWnd, IDC_LIST1), & LB_SETHORIZONTALEXTENT, maxLen+5, 0) j = SelectObject(hDC, hOldFont) j = ReleaseDC(hDC)
sItem() above are strings from the list. Of course, you can retrieve them using DlgGet. The code must be placed in a callback function; best, define a dialog-initialization callback (DlgSetSub(Dlg, IDD_MYDIALOG, OnDlgInit)) which is called immediately after DlgModal.
See Russ Freeman's home page for detailed discussion and a general solution (but it's in C, so it might not be applicable in your case).
HTH
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot. I'll look forward to trying this out.....Rob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For the start, first parameter of SendMessage is wrong -- you should send it to a HWND (obtained by GetDlgItem(hDlg, IDC_LOADTSERIES)), not to HDC.
Second, the length (of the scrollbar) is measured in pixels, not in characters (259) -- that's the whole point of this mess, i.e. that's why GetDC/SelectObject/GetTextExtentPoint32/ReleaseDC are required. Thus, you have to measure length, in pixels, for every string you add into listbox, find the maximal length, and do LB_SETHORIZONTALEXTENT for it.
Third, why do you create a hfontDlg at all? (Maybe it's just because you snipped the code down?).
Jugoslav

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