在Windows上的运行过程中,如何确定用于某些对话框窗口中某些控件的字体?像Microsoft Spy ++一样。
答案 0 :(得分:2)
我在Spy ++中找不到此功能,但是这是我刚刚为该任务编写的一个小程序:
#include <windows.h>
#include <stdio.h>
int main(int argc, char **argv)
{
if (argc != 2) {
fprintf(stderr, "Usage: findfont WINDOWTITLE\n");
return 1;
}
LPCSTR title = argv[1];
HWND hWnd = FindWindow(NULL, title);
if (hWnd == NULL) {
fprintf(stderr, "Window titled \"%s\" not found\n", title);
return 1;
}
HFONT hFont = (HFONT) SendMessage(hWnd, WM_GETFONT, 0, 0);
if (hFont == NULL) {
fprintf(stderr, "WM_GETFONT failed\n");
return 1;
}
LOGFONT lf = { 0 };
if (!GetObject(hFont, sizeof(LOGFONT), &lf)) {
fprintf(stderr, "GetObject failed\n");
return 1;
}
printf("Face name: %s Height: %ld\n", lf.lfFaceName, lf.lfHeight);
return 0;
}