How can I make the Win32 API window more modern looking?
I ordered Programming Windows Fifth Edition a few days ago, and started working with it.
开发者_Python百科I'm starting to learn the win32 api, however, I got a question. The windows do not look modern winxp/win vista/win 7 style at all. How do I fix this?
It currently looks like this, crap font and all.
Thanks in advance!
Machiel
To get the font right you should call this after CreateWindow(Ex)
:
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0);
HFONT hFont = ::CreateFontIndirect(&ncm.lfMessageFont);
::SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
You didn't, apparently, actually read the book. You're looking for WM_SETFONT. There is a reason the common controls aren't the first thing the book covers.
You need to set the font for each control with WM_SETFONT, you create the font by passing NONCLIENTMETRICS.lfMessageFont to CreateFontIndirect (Use SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ...) to get NONCLIENTMETRICS)
For dialog boxes, you use the pseudo font "MS Shell Dlg" @ 8pt on < Vista and "Segoe UI" @ 9pt on >= Vista
You might want to check GetThemeSysFont
to fill a LOGFONT
of an appropriate system font, create it using CreateFontIndirect
, and WM_SETFONT
to assign it to each control that you create.
To my knowledge there is no way to set a different default for newly created windows in your application. Nor is there a way to set all of the windows that you've already created in a single step (ie. instead of just looping through them all, or assigning individually). The exception is dialog boxes which when created from resources allow the resource to specify the font used for all of the controls on the dialog box.
You might want to post some screen shots of exactly what differences you are talking about, this would help in figuring out what you need to change.
In general I would say that you probably need to include an approprite manifest with your app so your app uses the latest common controls.
Also, these days most UI is not developed using SDK style code, this is very difficult to program/maintain, instead use some kind of UI library, MFC at the very least.
精彩评论