void CAppBar::AppBar_QuerySetPos(UINT uEdge, LPRECT lprc, PAPPBARDATA pabd, BOOL fMove)
{
    int iHeight = 0;
    int iWidth = 0;

    // Fill out the APPBARDATA struct and save the edge we're moving to
    // in the appbar OPTIONS struct.
    pabd->rc = *lprc;
    pabd->uEdge = uEdge;
    m_pOptions->uSide = uEdge;

    AppBar_QueryPos(&(pabd->rc));

     SHAppBarMessage(ABM_SETPOS, pabd);
    // Tell the system we're moving to this new approved position.
    if (fMove)
    {       
        MoveWindow(pabd->hWnd, pabd->rc.left, pabd->rc.top, 
                 pabd->rc.right - pabd->rc.left,
                   pabd->rc.bottom - pabd->rc.top, TRUE);       
    }

    // Save the appbar rect.  We use this later when we autohide.  If we're
    // currently hidden, then don't mess with this.
    if (!m_pOptions->fAutoHide)
        g_rcAppBar = pabd->rc;
}
void Main_OnMouseMove(HWND hwnd, int x, int y, UINT /* keyFlags */)
{
    // If we're not currently in the middle of moving the appbar window,
    // there's nothing to do.
    if (!s_fMoving)
    {
        return;
    }

    // Convert the mouse position to screen coordinates
    POINT ptCursor = {x, y};
    ClientToScreen(hwnd, &ptCursor);

    // Find out which edge of the screen we're closest to
    int cxScreen = GetSystemMetrics(SM_CXSCREEN);
    int cyScreen = GetSystemMetrics(SM_CYSCREEN);

    DWORD dx, dy;
    WORD horiz, vert;
    if (ptCursor.x < (cxScreen / 2))
    {
        dx = ptCursor.x;
        horiz = ABE_LEFT;
    }
    else
    {
        dx = cxScreen - ptCursor.x;
        horiz = ABE_RIGHT;
    }

    if (ptCursor.y < (cyScreen / 2))
    {
        dy = ptCursor.y;
        vert = ABE_TOP;
    }
    else
    {
        dy = cyScreen - ptCursor.y;
        vert = ABE_BOTTOM;
    }

    // Build a drag rectangle based on the edge of the screen that we're
    // closest to.
    POPTIONS pOpt = GetAppbarData(hwnd);
    if ((cxScreen * dy) > (cyScreen * dx))
    {
        s_rcDrag.top = 0;
        s_rcDrag.bottom = cyScreen;
        if (horiz == ABE_LEFT)
        {
            s_rcDrag.left = 0;
            s_rcDrag.right = s_rcDrag.left + pOpt->cxWidth;
            pOpt->uSide = ABE_LEFT;
        }
        else
        {
            s_rcDrag.right = cxScreen;
            s_rcDrag.left = s_rcDrag.right - pOpt->cxWidth;
            pOpt->uSide = ABE_RIGHT;
        }
    }
    else
    {
        s_rcDrag.left = 0;
        s_rcDrag.right = cxScreen;
        if (vert == ABE_TOP)
        {
            s_rcDrag.top = 0;
            s_rcDrag.bottom = s_rcDrag.top + pOpt->cyHeight;
            pOpt->uSide = ABE_TOP;
        }
        else
        {
            s_rcDrag.bottom = cyScreen;
            s_rcDrag.top = s_rcDrag.bottom - pOpt->cyHeight;
            pOpt->uSide = ABE_BOTTOM;
        }
    }

    // Finally, make sure this is an OK position with the system and move
    // the window.
    APPBARDATA abd;
    abd.cbSize = sizeof(APPBARDATA);
    abd.hWnd = hwnd;

    AppBar_QueryPos(hwnd, &s_rcDrag);
    MoveWindow(hwnd, s_rcDrag.left, s_rcDrag.top,
               s_rcDrag.right - s_rcDrag.left,
               s_rcDrag.bottom - s_rcDrag.top,
               TRUE);
}