Пример #1
0
static LRESULT CALLBACK
EditProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) {
    EditCtrl *w = (EditCtrl *)dwRefData;
    CrashIf(w->hwnd != (HWND)lp);

    if (w->preFilter) {
        bool discard = false;
        auto res = w->preFilter(hwnd, msg, wp, lp, discard);
        if (discard) {
            return res;
        }
    }

    if (WM_NCDESTROY == msg) {
        RemoveWindowSubclass(GetParent(w->hwnd), EditParentProc, 0);
        RemoveWindowSubclass(w->hwnd, EditProc, 0);
        return DefSubclassProc(hwnd, msg, wp, lp);
    }

    // Node: this is sent during creation, which is too early for us (we didn't
    // subclass the window yet)
    // currently, we force it with SetWindowPos(... SMP_FRAMECHANGED)
    if (WM_NCCALCSIZE == msg) {
        NCCALCSIZE_PARAMS *p = (NCCALCSIZE_PARAMS *)lp;
        RECT orig = p->rgrc[0];
        LRESULT res = DefSubclassProc(hwnd, msg, wp, lp);
        RECT curr = p->rgrc[0];
        w->ncDx = RectDx(orig) - RectDx(curr);
        w->ncDy = RectDy(orig) - RectDy(curr);
        return res;
    }

    return DefSubclassProc(hwnd, msg, wp, lp);
}
Пример #2
0
void RootWindow::DrawPict(HDC hdc)
{
    RECT    clientRc;
    long    picDx, picDy;
    int     winDx, winDy;
    HDC     dcTmp = NULL;
    HBITMAP bmpTmp = NULL;
    HBITMAP bmpOld = NULL;

    if (NULL == g_pic)
        return;

    GetClientRect(m_hwnd, &clientRc);
    winDx = RectDx(&clientRc);
    winDy = RectDy(&clientRc);

    g_pic->get_Width(&picDx);
    g_pic->get_Height(&picDy);

    dcTmp = CreateCompatibleDC(hdc);
    if (NULL == dcTmp)
        return;

    bmpTmp = CreateCompatibleBitmap(hdc, winDx, winDy);
    if (NULL == bmpTmp)
        goto Exit;
    bmpOld = (HBITMAP)SelectObject(dcTmp, bmpTmp);

    HDC dcToDraw = dcTmp;

    FillRectangle(dcToDraw, 0, 0, RectDx(&clientRc), RectDy(&clientRc), COL_WHITE);

    if (m_fPictHasBorder)
    {
        RECT tmpRc = { 0 };
        tmpRc.left = m_pictPosX - BORDER_PIXEL_SIZE;
        tmpRc.top  = m_pictPosY - BORDER_PIXEL_SIZE;
        tmpRc.right = tmpRc.left + m_pictPixelDx + 2*BORDER_PIXEL_SIZE;
        tmpRc.bottom = tmpRc.top + m_pictPixelDy + 2*BORDER_PIXEL_SIZE;
        FillRectangle(dcToDraw, &tmpRc, COL_RED);
    }

    g_pic->Render(dcToDraw, 
                  m_pictPosX, m_pictPosY, 
                  m_pictPixelDx, m_pictPixelDy,
                  0, picDy, 
                  picDx, -picDy, NULL);

    BitBlt(hdc, 0, 0, winDx, winDy, dcToDraw, 0, 0, SRCCOPY);

    SelectObject(dcTmp, bmpOld);

Exit:
    if (NULL != bmpTmp)
        DeleteObject(bmpTmp);
    if (NULL != dcTmp)
        DeleteDC(dcTmp);
}
Пример #3
0
void RootWindow::DrawPictCentered(HDC hdc)
{
    RECT    clientRc;
    int     winDx, winDy;

    if (NULL == g_pic)
        return;

    GetClientRect(m_hwnd, &clientRc);
    winDx = RectDx(&clientRc);
    winDy = RectDy(&clientRc);

    m_pictPosX = 0;
    if (winDx > m_pictPixelDx)
        m_pictPosX = (winDx - m_pictPixelDx) / 2;

    m_pictPosY = 0;
    if (winDy > m_pictPixelDy)
        m_pictPosY = (winDy - m_pictPixelDy) / 2;

    m_count = 0;
    m_direction = AnimDirRight;

    DrawPict(hdc);
}
Пример #4
0
SIZE TextPanelUI::EstimateSize(SIZE szAvailable)
{
    RECT rcText = { 0, 0, MAX(szAvailable.cx, m_cxWidth), 9999 };
    m_nLinks = 0;
    BlueRenderEngineUI::DoPaintPrettyText(m_mgr->GetPaintDC(), m_mgr, rcText, m_txt, UICOLOR_EDIT_TEXT_NORMAL, UICOLOR__INVALID, NULL, m_nLinks, DT_CALCRECT | m_uTextStyle);
    return CSize(RectDx(rcText), RectDy(rcText));
}
Пример #5
0
SIZE WarningPanelUI::EstimateSize(SIZE szAvailable)
{
    RECT rcText = { 0, 0, szAvailable.cx, szAvailable.cy };
    ::InflateRect(&rcText, -6, -4);
    int nLinks = 0;
    BlueRenderEngineUI::DoPaintPrettyText(m_mgr->GetPaintDC(), m_mgr, rcText, m_txt, UICOLOR_EDIT_TEXT_NORMAL, UICOLOR__INVALID, NULL, nLinks, DT_WORDBREAK | DT_CALCRECT);
    return CSize(0, RectDy(rcText) + 16);
}
Пример #6
0
void ResizeHwndToClientArea(HWND hwnd, int dx, int dy, bool hasMenu)
{
    WINDOWINFO wi = { 0 };
    wi.cbSize = sizeof(wi);
    GetWindowInfo(hwnd, &wi);

    RECT r = { 0 };
    r.right = dx; r.bottom = dy;
    DWORD style = wi.dwStyle;
    DWORD exStyle = wi.dwExStyle;
    AdjustWindowRectEx(&r, style, hasMenu, exStyle);
    if ((dx == RectDx(wi.rcClient)) && (dy == RectDy(wi.rcClient)))
        return;

    dx = RectDx(r); dy = RectDy(r);
    int x = wi.rcWindow.left;
    int y = wi.rcWindow.top;
    MoveWindow(hwnd, x, y, dx, dy, TRUE);
}
Пример #7
0
bool CreateEditCtrl(EditCtrl *w) {
    // Note: has to remember this here because when I GetWindowStyle() later on,
    // WS_BORDER is not set, which is a mystery, because it is being drawn.
    // also, WS_BORDER seems to be painted in client areay
    w->hasBorder = bit::IsMaskSet<DWORD>(w->dwStyle, WS_BORDER);

    RECT rc = w->initialPos;
    w->hwnd = CreateWindowExW(w->dwExStyle, WC_EDIT, L"", w->dwStyle, rc.left, rc.top, RectDx(rc),
                              RectDy(rc), w->parent, nullptr, GetModuleHandleW(nullptr), nullptr);

    if (!w->hwnd) {
        return false;
    }
    SetFont(w, GetDefaultGuiFont());
    SetWindowSubclass(w->hwnd, EditProc, 0, (DWORD_PTR)w);
    SetWindowSubclass(GetParent(w->hwnd), EditParentProc, 0, (DWORD_PTR)w);
    return true;
}
Пример #8
0
bool TreeCtrl::Create(const WCHAR* title) {
    if (!title) {
        title = L"";
    }

    RECT rc = this->initialPos;
    HMODULE hmod = GetModuleHandleW(nullptr);
    this->hwnd = CreateWindowExW(this->dwExStyle, WC_TREEVIEWW, title, this->dwStyle, rc.left, rc.top, RectDx(rc),
                                 RectDy(rc), this->parent, this->menu, hmod, nullptr);
    if (!this->hwnd) {
        return false;
    }
    TreeView_SetUnicodeFormat(this->hwnd, true);
    this->SetFont(GetDefaultGuiFont());
    Subclass(this);

    return true;
}