LB_SETHORIZONTALEXTENT (horizontal listbox control, non-MFC)
-
Hi, I have a listbox in my _non-MFC_ dialog-based app, and I need to have a horizontal scrollbar for when the text extends out of the listbox. I know that you have to set LB_SETHORIZONTALEXTENT to get this to work (why oh why didn't they make it as easy as the vertical scrollbar?), but I have had no joy in getting it to work. I guess that this is what I need to do: 1) Whenever items are added to the listbox, or the listbox is resized, find the longest string (using strlen()). 2) Calculate the width of that string in pixels. 3) Set LB_SETHORIZONTALEXTENT to the calculated number. Steps 1 and 3 are easy, but it's step 2 I have problems with. How can I find the width in pixels of the longest string? The only examples I can find are all written in MFC, which doesn't help as I can't find the equivalent non-MFC functions (eg. CDC::GetTextExtent). I anyone can tell me how to find the width of a string in a listbox in pixels without using MFC, or just tell me how to get the horizontal scrollbar working in a non-MFC listbox, I would be very grateful. Many thanks, KB
-
Hi, I have a listbox in my _non-MFC_ dialog-based app, and I need to have a horizontal scrollbar for when the text extends out of the listbox. I know that you have to set LB_SETHORIZONTALEXTENT to get this to work (why oh why didn't they make it as easy as the vertical scrollbar?), but I have had no joy in getting it to work. I guess that this is what I need to do: 1) Whenever items are added to the listbox, or the listbox is resized, find the longest string (using strlen()). 2) Calculate the width of that string in pixels. 3) Set LB_SETHORIZONTALEXTENT to the calculated number. Steps 1 and 3 are easy, but it's step 2 I have problems with. How can I find the width in pixels of the longest string? The only examples I can find are all written in MFC, which doesn't help as I can't find the equivalent non-MFC functions (eg. CDC::GetTextExtent). I anyone can tell me how to find the width of a string in a listbox in pixels without using MFC, or just tell me how to get the horizontal scrollbar working in a non-MFC listbox, I would be very grateful. Many thanks, KB
The API is
GetTextExtentPoint32()
--Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Ericahist updated (again) Sep 6! -
The API is
GetTextExtentPoint32()
--Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Ericahist updated (again) Sep 6!Thanks! That is exactly what I needed. I found a function using that API call along with LB_SETHORIZONTALEXTENT here: http://www.catch22.org.uk/tuts/dirlist.asp that does exactly what I needed, with a few minor qualifications. Thanks again, your help is much appreciated, KB