VOID DecodeDialog()

in tools/VerifyResources/VerifyResources.cpp [273:372]


VOID DecodeDialog(VOID *lpv, DLGDECODE *pdecdlg)
{
    BOOL bExtended;
    WORD *pwT = (WORD *)lpv;

    if (*pwT == 1 && *(pwT + 1) == 0xffff)
    {
        // dlgVer == 1 and signature == 0xffff means extended dialog;
        // after those fields and the helpID field, the fields in memory
        // match those of the DLGTEMPLATE except that the extended style and style are revsersed.

        pwT += 4; // skip over dlgVer, signature, and helpID

        DLGTEMPLATE *pdlgT = (DLGTEMPLATE *)pwT;

        pdecdlg->dlgtempl.style = pdlgT->dwExtendedStyle;
        pdecdlg->dlgtempl.dwExtendedStyle = pdlgT->style;
        pdecdlg->dlgtempl.cdit = pdlgT->cdit;
        pdecdlg->dlgtempl.x = pdlgT->x;
        pdecdlg->dlgtempl.y = pdlgT->y;
        pdecdlg->dlgtempl.cx = pdlgT->cy;
        pdecdlg->dlgtempl.cy = pdlgT->cy;

        pdecdlg->pdlg = &pdecdlg->dlgtempl;

        bExtended = TRUE;
    }
    else
    {
        pdecdlg->pdlg = (DLGTEMPLATE *)lpv;

        bExtended = FALSE;
    }

    // in both cases, continue after the DLGTEMPLATE
    pwT = (WORD *)((char *)pwT + sizeof(DLGTEMPLATE));

    // 0xffff means we have a integer class identitifer; otherwise a string;
    // all other cases like this are the same.
    if (*pwT == 0xffff)
    {
        pwT++;
        pdecdlg->lpszMenu = NULL;
        pdecdlg->wMenu = *pwT;
        pwT++;
    }
    else
    {
        pdecdlg->lpszMenu = (LPCTSTR)pwT;
        pwT += wcslen(pdecdlg->lpszMenu) + 1;
    }

    if (*pwT == 0xffff)
    {
        pwT++;
        pdecdlg->lpszClass = NULL;
        pdecdlg->wClass = *pwT;
        pwT++;
    }
    else
    {
        pdecdlg->lpszClass = (LPCTSTR)pwT;
        pwT += wcslen(pdecdlg->lpszClass) + 1;
    }

    pdecdlg->lpszTitle = (LPCTSTR)pwT;
    pwT += wcslen(pdecdlg->lpszTitle) + 1;

    if (pdecdlg->pdlg->style & DS_SETFONT)
    {
        pdecdlg->wFont = *pwT++;

        if (bExtended)
        {
            // if extended, skip weight, italic, charset
            pwT += 2;
        }

        pdecdlg->lpszFont = (LPCTSTR)pwT;
        pwT += wcslen(pdecdlg->lpszFont) + 1;
    }

    // align on DWORD boundary
    pwT = (WORD *)RAWINPUT_ALIGN((INT_PTR)pwT);

    if (pdecdlg->pdlg->cdit > MAXDLGITEMS)
    {
        printf("Error: dialog has more than %d items\n", MAXDLGITEMS);
        pdecdlg->pdlg->cdit = MAXDLGITEMS;
    }

    for (int i = 0; i < pdecdlg->pdlg->cdit; i++)
    {
        DLGITEMDECODE *pitem = &pdecdlg->rgitems[i];

        ZeroMemory(pitem, sizeof(*pitem));

        DecodeDlgItem(&pwT, bExtended, pitem);
    }
}