- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have cause to want a horizontal scroll bar for a list box control. The vertical scroll bars appear automatically then the number of items in the list exceeds the vertical display space. However if the text in an item exceeds the width of the list box the horizontal scroll bar does not automatically appear. So in the properties page for the list box I have set Horizontal Scroll to be true. But it still does not appear. Any suggestions? Thanks, ACAR.
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Stupid Windows won't do that automatically -- you have to send it a LB_SETHORIZONTALEXTENT message, and to find out the proper value, you must go through additional hoops.
Here's an old thread with a sample code of mine.
Here's an old thread with a sample code of mine.
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Stupid Windows won't do that automatically -- you have to send it a LB_SETHORIZONTALEXTENT message, and to find out the proper value, you must go through additional hoops.
Here's an old thread with a sample code of mine.
Here's an old thread with a sample code of mine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As you say Jugoslav ' Stupid Windows'! Once again you've pointed me to an excellent solution - many thanks. I don't know about you and other IVF users but I would have thought that this should be documented in Intel's help system by now.....
I thought I'd add my code in the hope of stopping someone else wasting an hour or so of their life. I tried the Add Files button but that didn't seem to work so I'll just paste it in:
SUBROUTINE FILES_OPEN_RECENT
USE FILES_OPEN_RECENT_MODULE
IMPLICIT NONE
EXTERNAL FILES_OPEN_RECENT_BUTTONS
EXTERNAL FILES_OPEN_RECENT_BUTTONS_DOUBLECLICK
EXTERNAL HORIZONTAL_SCROLL_BAR
LRET=DLGINIT(IDD_FILES_OPEN_RECENT,FILES_OPEN_RECENT_DLG)
CALL FILES_OPEN_RECENT_DIALOG_INITIALISE
LRET=DLGSETSUB(FILES_OPEN_RECENT_DLG,IDC_RECENT_JOB_LIST,FILES_OPEN_RECENT_BUTTONS)
LRET=DLGSETSUB(FILES_OPEN_RECENT_DLG,IDC_RECENT_JOB_LIST,FILES_OPEN_RECENT_BUTTONS_DOUBLECLICK,DLG_DBLCLICK)
LRET=DLGSETSUB(FILES_OPEN_RECENT_DLG,IDC_OPEN,FILES_OPEN_RECENT_BUTTONS)
LRET=DLGSETSUB(FILES_OPEN_RECENT_DLG,IDCANCEL,FILES_OPEN_RECENT_BUTTONS)
LRET=DLGSETSUB(FILES_OPEN_RECENT_DLG,IDC_DISMISS,FILES_OPEN_RECENT_BUTTONS)
IRET=DLGSETSUB(FILES_OPEN_RECENT_DLG,IDC_RECENT_JOB_LIST,HORIZONTAL_SCROLL_BAR)
CALL MODAL_DIALOG_INVOKE(FILES_OPEN_RECENT_DLG)
RETURN
END
SUBROUTINE HORIZONTAL_SCROLL_BAR(LOCAL_DIALOG,LOCAL_CONTROL,CBT)
USE DFWIN
USE DF_MODULE
USE DIALOG_MODULE
USE GLOBAL_CONSTANTS_MODULE
IMPLICIT NONE
!INPUT:
TYPE(DIALOG)::LOCAL_DIALOG
INTEGER::LOCAL_CONTROL
INTEGER::CBT
!LOCAL:
TYPE(T_SIZE)::PT
TYPE(T_RECT)::RECT
INTEGER::MAXLEN,HDC,HFONT,HOLDFONT,I,J
INTEGER::NUMBER_OF_ITEMS
CHARACTER(LONG_LINE_LENGTH),ALLOCATABLE::TEXT_ITEMS(:)
LRET=DLGGET(LOCAL_DIALOG,LOCAL_CONTROL,NUMBER_OF_ITEMS,DLG_NUMITEMS)
ALLOCATE(TEXT_ITEMS(NUMBER_OF_ITEMS))
MAXLEN=0
HDC=GETDC(GETDLGITEM(LOCAL_DIALOG%HWND,LOCAL_CONTROL))
HFONT=GETSTOCKOBJECT(DEFAULT_GUI_FONT)
HOLDFONT=SELECTOBJECT(HDC,HFONT)
DO I=1,NUMBER_OF_ITEMS
LRET=DLGGET(LOCAL_DIALOG,LOCAL_CONTROL,TEXT_ITEMS(I),I)
J=GETTEXTEXTENTPOINT32(HDC,TEXT_ITEMS(I),LEN_TRIM(TEXT_ITEMS(I)),PT)
MAXLEN=MAX(MAXLEN,PT%CX)
ENDDO
J=SENDMESSAGE(GETDLGITEM(LOCAL_DIALOG%HWND,LOCAL_CONTROL),LB_SETHORIZONTALEXTENT,MAXLEN+5,0)
J=SELECTOBJECT(HDC,HOLDFONT)
DEALLOCATE(TEXT_ITEMS)
! J=RELEASEDC(HDC)
RETURN
END
I've added to your routine the bits that recover the number of items and text from the list box. I have commented out the releasedc function because the compiler complained about a non-optional actual argument must be present when invoking a procedure with an explicit interface [HDC]. Don't know what this was supposed to do but it seems to work without it. I also note that whilst the horizontal scroll bar now works, one has to click in the list box before the routine is invoked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting acar
... ...
...
HDC=GETDC(GETDLGITEM(LOCAL_DIALOG%HWND,LOCAL_CONTROL))
! J=RELEASEDC(HDC)
RETURN
END
...
Don't know what this was supposed to do but it seems to work without it....
Without that call you may (almost certainly) be leaking a GDI handle. If so, then eventually this will cause your program (and depending on the OS version, maybe others) to fail, possibly in strange ways.
The MSDN documentation for ReleaseDC shows that it takes two arguments - the handle to the window and then the DC handle. Try:
[fortran]J = ReleaseDC(GetDlgItem(LOCAL_DIALOG%HWND,LOCAL_CONTROL), HDC)[/fortran]Leaking GDI handles is a notorious problem with Win32 programming. You can use the windows task manager (the thing that pops up when you press Ctrl-Shift-Esc) on some versions of windows to crudely monitor your program's use of GDI objects. With the Processes tab selected have a look under the View menu for Select Columns. If you see the number of objects in use go up as your program runs you know you have a problem. There are other numerous other free tools that can track this sort of leak too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for that Ian.

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