Thread: Ask a control for the "best fit" size?

  1. #1
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Banks of the River Styx

    Question Ask a control for the "best fit" size?

    How do I ask a control/window, such as an edit box, static text, button, etc., what is its "best fit" size - like, the size that it would appear decent at.

    Edit boxes, for example. How do I determine what height I should make them? Too tall, and there is a bunch of whitespace, too short, and the text in the box will get cut off. How do I determine this magic height at which an edit box will look normal?
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  2. #2
    train spotter
    Join Date
    Aug 2001
    near a computer
    At a guess....

    GetDC() of the edit.

    It should have a Font in the DC.

    Use GetTextExtent() to find the size of a given string within the edit.

    Inflate the size to account for a border.


    Resize control with MoveWindow() or SetWindowPos()
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 03-25-2003, 05:13 PM
  2. Changing a Structures Members array size
    By Xei in forum C++ Programming
    Replies: 1
    Last Post: 11-07-2002, 07:45 PM
  3. Can't I reduce the default size of Activex Control (rcBounds)
    By samudrala_99 in forum Windows Programming
    Replies: 1
    Last Post: 10-23-2002, 09:24 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. File Size and File Size on Disk
    By DavidP in forum A Brief History of
    Replies: 4
    Last Post: 12-15-2001, 08:03 PM