Create a Button using CreateWindow

Posted on 2003-03-22
Medium Priority
Last Modified: 2013-12-03

I am trying to create a button on a window using the CreateWindow function and the class "Button". However, the button being created is different in looks than buttons I create using Dialog Boxes resources. It has a different font and perhaps other different details that I can't make for sure. Am I missing some style flag? I found no help on that issue in the SDK Documentation. I wish to make the button I create on the window to look like my dialog boxes buttons.
Here is the CreateWindow code:

m_hPlayButton = CreateWindow("Button", "&Play", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 5, 5, 100, 100, m_hPlayWindow, NULL, (HINSTANCE)GetWindowLong(m_hPlayWindow, GWL_HINSTANCE), NULL);

Question by:IdanM
  • 2
  • 2

Expert Comment

ID: 8187831
did you specify a different font when you used dialogs? i don't use dialogs but i think they should look exactlly the same.
you can look at the source on my site www.PlanetCpp.com.
most source has a button on it for you to look at and one has the ability to change fonts.

Author Comment

ID: 8187944
I just used the resource editor to edit a Dialog Boxes. Some of your buttons in your site look the same as mine, with a different font.

Accepted Solution

TascoDLX earned 150 total points
ID: 8189247
To change the font, send the WM_SETFONT message to the button.  Such as:

   PostMessage(m_hPlayButton, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE,0));

You can pass a handle to any font you wish.  Such as:

   HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);


Expert Comment

ID: 8189405
the buttons on my site look the same as the ones you're having a problem with? thats the way buttons look, unless you specify to make them checkbox style. what is the difference that used to be in the dialog buttons, they should be the same

Author Comment

ID: 8190118
Thanks, that did the trick :)

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question