<p>How do I create a button control (with <code>CreateWindow</code> of a <code>BUTTON</code> 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.</p>

<blockquote>
  <p><strong>Remark:</strong> Using <code>USE_CW_DEFAULT</code> for width and height results in a 0, 0 size button, so that's not a solution.</p>
</blockquote>

[{'answer_id': 58636, 'author': 'Timbo', 'author_id': 1810, 'author_profile': 'https://Stackoverflow.com/users/1810', 'pm_score': 3, 'selected': False, 'text': '<p>This is what MSDN has to say: <a href="http://msdn.microsoft.com/en-us/library/ms997619.aspx" rel="noreferrer">Design Specifications and Guidelines - Visual Design: Layout</a>.</p>\n\n<p>The default size of a button is 50x14 DLUs, which can be calculated to pixels using the examples shown for <a href="http://msdn.microsoft.com/en-us/library/ms645475(VS.85).aspx" rel="noreferrer">GetDialogBaseUnits</a>.</p>\n\n<p>The <a href="http://msdn.microsoft.com/en-us/library/ms645502(VS.85).aspx" rel="noreferrer">MapDialogRect</a> function seems to do the calculation for you.</p>\n'}, {'answer_id': 58689, 'author': 'macbirdie', 'author_id': 5049, 'author_profile': 'https://Stackoverflow.com/users/5049', 'pm_score': 4, 'selected': True, 'text': '<h2>In the perfect, hassle-free world...</h2>\n\n<p>To create a standard size button we would have to do this:</p>\n\n<pre><code>LONG units = GetDialogBaseUnits();\nm_hButton = CreateWindow(TEXT("BUTTON"), TEXT("Close"), \n                 WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, \n                 0, 0, MulDiv(LOWORD(units), 50, 4), MulDiv(HIWORD(units), 14, 8),\n                 hwnd, NULL, hInst, NULL);\n</code></pre>\n\n<p>where <strong>50</strong> and <strong>14</strong> are respective DLU dimensions, <strong>4</strong> and <strong>8</strong> are horizontal and vertical dialog template units respectively, based on <a href="http://msdn.microsoft.com/en-us/library/ms645475(VS.85).aspx" rel="noreferrer"><code>GetDialogBaseUnits()</code> function</a> documentation remarks.</p>\n\n<hr>\n\n<h2>Nothing\'s perfect</h2>\n\n<p><strong>BUT</strong> 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.</p>\n\n<p>To get your own "dialog" base units, you have to retrieve current text metrics with <code>GetTextMetrics()</code> and use character height and average width (<code>tmHeight</code> and <code>tmAveCharWidth</code> of the <code>TEXTMETRIC</code> struct respectively) and translate them with MulDiv by your own, <strong>unless</strong> you are in a dialog, then <code>MapDialogRect()</code> will do all the job for you.</p>\n\n<p>Note that <code>tmAveCharWidth</code> only approximates the actual average character width so it\'s recommended to use a <a href="http://msdn.microsoft.com/en-us/library/dd144938.aspx" rel="noreferrer"><code>GetTextExtentPoint32()</code></a> function on an alphabetic character set instead.</p>\n\n<p>See:</p>\n\n<ul>\n<li><a href="http://support.microsoft.com/kb/145994" rel="noreferrer">How to calculate dialog box units based on the current font in Visual C++</a></li>\n<li><a href="http://support.microsoft.com/kb/125681" rel="noreferrer">How To Calculate Dialog Base Units with Non-System-Based Font</a></li>\n</ul>\n\n<hr>\n\n<h2>Simpler alternative</h2>\n\n<p>If buttons are the only control you want to resize automatically, you can also use <a href="http://msdn.microsoft.com/en-us/library/bb775961(VS.85).aspx" rel="noreferrer"><code>BCM_GETIDEALSIZE</code></a> message <a href="http://msdn.microsoft.com/en-us/library/bb761851(VS.85).aspx" rel="noreferrer"><code>Button_GetIdealSize()</code></a> 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.</p>\n'}, {'answer_id': 59387, 'author': 'Anders', 'author_id': 3501, 'author_profile': 'https://Stackoverflow.com/users/3501', 'pm_score': 1, 'selected': False, 'text': '<p>@macbirdie: you should NOT use GetDialogBaseUnits(), it is based on the default system font (Ugly bitmap font). You should use MapDialogRect()</p>\n'}]
['https://Stackoverflow.com/questions/58620', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5049/']