Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. LB_SETHORIZONTALEXTENT (horizontal listbox control, non-MFC)

LB_SETHORIZONTALEXTENT (horizontal listbox control, non-MFC)

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++helptutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kayembi
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • K Kayembi

      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

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      The API is GetTextExtentPoint32() --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Ericahist updated (again) Sep 6!

      K 1 Reply Last reply
      0
      • M Michael Dunn

        The API is GetTextExtentPoint32() --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Ericahist updated (again) Sep 6!

        K Offline
        K Offline
        Kayembi
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups