Manget

Torak 04.03.02 18:27

Funktio joka tekee ikkunasta magneettisen eli ikkuna napsahtaa näytön reunoihin kiinni (WinApi).

 Tekstiversio  Arvo: 2 (2 ääntä)  Äänestä: +  -
BOOL MagnetWindow(LPARAM *lParam)
{
    // Näytön koordinaatit
        RECT *pRect = (LPRECT) *lParam;
        static RECT rcOld = { 0, 0, 0, 0 };
        RECT rcDesktop;
        INT      iPower = 20;
        SIZE szSize;

        if(FALSE == SystemParametersInfo(SPI_GETWORKAREA, 0, &rcDesktop, 0))
                return FALSE;

        szSize.cx = pRect->right -  pRect->left;
        szSize.cy = pRect->bottom - pRect->top;


        if(pRect->top < iPower && rcOld.top > pRect->top)
        {
                pRect->top = 0;
                pRect->bottom = szSize.cy;
        }
        else
        if(pRect->bottom > (rcDesktop.bottom - iPower) &&
           rcOld.bottom  < pRect->bottom)
        {
                pRect->bottom = rcDesktop.bottom;
                pRect->top = rcDesktop.bottom - szSize.cy;
        }

        if(pRect->left < iPower && rcOld.left > pRect->left)
        {
                pRect->left = 0;
                pRect->right = szSize.cx;
        }
        else
        if(pRect->right > (rcDesktop.right - iPower) &&
                rcOld.right < pRect-> right)
        {
                pRect->right = rcDesktop.right;
                pRect->left =  rcDesktop.right - szSize.cx;
        }

        rcOld.top = pRect -> top;
        rcOld.bottom = pRect -> bottom;
        rcOld.left = pRect -> left;
        rcOld.right = pRect -> right;

        return TRUE;
}