void TconfPageBase::createWindow(void)
{
    m_hwnd=createDialog(dialogId,hwndParent);
    assert(m_hwnd);
    ShowWindow(m_hwnd,SW_HIDE);
    setWindowText(m_hwnd,dialogName());
    translate();
    if (tr->translateMode && dialogId!=IDD_ABOUT) {
        HWND hed=GetDlgItem(m_hwnd,IDC_ED_HELP);
        if (hed) {
            SendMessage(hed,EM_SETREADONLY,FALSE,0);
            SetWindowLong(hed,GWL_STYLE,GetWindowLong(hed,GWL_STYLE)|ES_WANTRETURN);
        }
    }
}
Example #2
0
    const void *Dialog::dialogTemplateWithSystemFont()
    {
        dlgData_.clear();

        NONCLIENTMETRICSW ncm = {0, };
        ncm.cbSize = CCSIZEOF_STRUCT(NONCLIENTMETRICSW, lfMessageFont); // For Windows under Vista.
        SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);

        HINSTANCE inst = Batang::Win32Environment::instance().getInstance();
        HRSRC rsrc = FindResourceW(inst, dialogName(), RT_DIALOG);
        size_t size = SizeofResource(inst, rsrc);
        HGLOBAL mem = LoadResource(inst, rsrc);
        uint8_t *ptr = static_cast<uint8_t *>(LockResource(mem));
        uint16_t data16;
        uint32_t style;
        wchar_t *stmp;
        size_t tmpsize, prev = 26, next = 26;

        dlgData_.assign(ptr, ptr + prev); // dlgVer to cy in DLGTEMPLATEEX: 26 bytes

        auto szOrOrd = [&ptr, &prev, &next, this]() -> void
        {
            prev = next;
            uint16_t *tmp = reinterpret_cast<uint16_t *>(ptr + prev);
            if(*tmp == 0x0000)
                next = prev + 2;
            else if(*tmp == 0xFFFF)
                next = prev + 4;
            else
            {
                wchar_t *stmp = reinterpret_cast<wchar_t *>(tmp);
                next = prev + (wcslen(stmp) + 1) * sizeof(wchar_t);
            }
            dlgData_.insert(dlgData_.end(), ptr + prev, ptr + next);
        };

        szOrOrd();
        szOrOrd();

        prev = next;
        stmp = reinterpret_cast<wchar_t *>(ptr + prev);
        next = prev + (wcslen(stmp) + 1) * sizeof(wchar_t); // title

        dlgData_.insert(dlgData_.end(), ptr + prev, ptr + next);

        auto lfHeightToPoint = [](int32_t height) -> uint16_t
        {
            if(height >= 0)
                return static_cast<uint16_t>(height);

            HWND desktop = GetDesktopWindow();
            HDC hdc = GetDC(desktop);
            uint16_t ret = static_cast<uint16_t>(static_cast<double>(-height * 72) / GetDeviceCaps(hdc, LOGPIXELSY) + 0.5);
            ReleaseDC(desktop, hdc);

            return ret;
        };

        prev = next;
        style = *reinterpret_cast<uint32_t *>(ptr + 12);
        if((style & DS_SETFONT) || (style & DS_SHELLFONT))
        {
            data16 = lfHeightToPoint(ncm.lfMessageFont.lfHeight);
            if(data16 < 9)
                data16 = 9; // XXX: Dialog's font size must be least 9pt.
            dlgData_.insert(dlgData_.end(), reinterpret_cast<uint8_t *>(&data16), reinterpret_cast<uint8_t *>(&data16 + 1));

            prev += 2;
            next = prev + 2;
            dlgData_.insert(dlgData_.end(), ptr + prev, ptr + next);
            dlgData_.push_back(ncm.lfMessageFont.lfItalic);
            dlgData_.push_back(ncm.lfMessageFont.lfCharSet);
            next += 2;

            stmp = reinterpret_cast<wchar_t *>(ptr + next);
            prev = next + (wcslen(stmp) + 1) * sizeof(wchar_t);

            tmpsize = (wcslen(ncm.lfMessageFont.lfFaceName) + 1) * sizeof(wchar_t);
            dlgData_.insert(dlgData_.end(),
                reinterpret_cast<uint8_t *>(ncm.lfMessageFont.lfFaceName),
                reinterpret_cast<uint8_t *>(ncm.lfMessageFont.lfFaceName) + tmpsize);
        }

        size_t rest = 4 - (dlgData_.size() % 4);
        if(rest < 4)
        {
            for(; rest > 0; -- rest)
                dlgData_.push_back(0);
        }

        rest = 4 - (prev % 4);
        if(rest < 4)
            prev += rest;

        dlgData_.insert(dlgData_.end(), ptr + prev, ptr + size);

        // TODO: Controls

        FreeResource(mem);

        return &*dlgData_.begin();
    }