Search code examples
windowsfontsdialogwindowanalysis

How to determine font used in dialog window


How to determine font used for some control in some dialog window in runnning process on Windows? Something like Microsoft Spy++ does.


Solution

  • I did not find this functionality in Spy++, but here's a small program that I just wrote for this task:

    #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;
    }