Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 38263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:40:51+00:00 2026-05-10T14:40:51+00:00

How do I create a button control (with CreateWindow of a BUTTON window class)

  • 0

How do I create a button control (with CreateWindow of a BUTTON window class) that has a standard system-wide size (especially height) that’s consistent with the rest of Windows applications? I should of course take DPI into account and probably other settings.

Remark: Using USE_CW_DEFAULT for width and height results in a 0, 0 size button, so that’s not a solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T14:40:51+00:00Added an answer on May 10, 2026 at 2:40 pm

    In the perfect, hassle-free world…

    To create a standard size button we would have to do this:

    LONG units = GetDialogBaseUnits(); m_hButton = CreateWindow(TEXT("BUTTON"), TEXT("Close"),                   WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,                   0, 0, MulDiv(LOWORD(units), 50, 4), MulDiv(HIWORD(units), 14, 8),                  hwnd, NULL, hInst, NULL); 

    where 50 and 14 are respective DLU dimensions, 4 and 8 are horizontal and vertical dialog template units respectively, based on GetDialogBaseUnits() function documentation remarks.


    Nothing’s perfect

    BUT as Anders pointed out, those metrics are based on the system font. If your window uses a shell dialog font or simply anything not making your eyes bleed, you’re pretty much on your own.

    To get your own "dialog" base units, you have to retrieve current text metrics with GetTextMetrics() and use character height and average width (tmHeight and tmAveCharWidth of the TEXTMETRIC struct respectively) and translate them with MulDiv on your own, unless you are in a dialog, then MapDialogRect() will do all the job for you.

    Note that tmAveCharWidth only approximates the actual average character width so it’s recommended to use a GetTextExtentPoint32() function on an alphabetic character set instead.

    See:

    • Q145994: HOWTO: Calculate Dialog Units When Not Using the System Font
    • How does the dialog manager calculate the average width of a character?

    Simpler alternative

    If buttons are the only control you want to resize automatically, you can also use BCM_GETIDEALSIZE message Button_GetIdealSize() macro (Windows XP and up only) to retrieve optimal width and height that fits anything the button contains, though it looks pretty ugly without any margins applied around the button’s text.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 108k
  • Answers 108k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer set the url as http://www.website.com:20114/folder/file.ext May 11, 2026 at 9:14 pm
  • Editorial Team
    Editorial Team added an answer There are a couple of problems here... C# and Type… May 11, 2026 at 9:14 pm
  • Editorial Team
    Editorial Team added an answer What you are looking for is event bubbling. Set the… May 11, 2026 at 9:14 pm

Related Questions

Some of the controls I've created seem to default to the old Windows 95
I'm working on a simple application to start learning my way around WPF. I
I have a form with multiple fields that I'm validating (some with methods added
I understand that the Windows API uses classes, relying to the WNDCLASS / WNDCLASSEX

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.