Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29234 Discussions

problem with horizontal scrolling in a simple dialogue window

robberman
Beginner
451 Views
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.
0 Kudos
3 Replies
Jugoslav_Dujic
Valued Contributor II
451 Views
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:
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
0 Kudos
robberman
Beginner
451 Views
Thanks a lot. I'll look forward to trying this out.....Rob
0 Kudos
Jugoslav_Dujic
Valued Contributor II
451 Views

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

0 Kudos
Reply