http://tech521.com/show_data.asp?tid=1534
有一个DELPHI的
不知道能否翻译成C
你看看吧
或许能找出些思路
8-)

解决方案 »

  1.   

    这个函数可使窗体自动靠边,希望对你有所启发
    BOOL AdjustPos(CRect* lpRect)
    {//自动靠边
    int iSX=GetSystemMetrics(SM_CXFULLSCREEN);
    int iSY=GetSystemMetrics(SM_CYFULLSCREEN);
    RECT rWorkArea;
    BOOL bResult = SystemParametersInfo(SPI_GETWORKAREA,  
    sizeof(RECT),
    &rWorkArea,
    0);    
    CRect rcWA;
    if(!bResult)
    {//如果调用不成功就利用GetSystemMetrics获取屏幕面积
    rcWA=CRect(0,0,iSX,iSY);
    }
    else
    rcWA=rWorkArea;
     
    int iX=lpRect->left;
    int iY=lpRect->top;
     
    if(iX < rcWA.left + DETASTEP && iX!=rcWA.left)
    {//调整左
    //pWnd->SetWindowPos(NULL,rcWA.left,iY,0,0,SWP_NOSIZE);
    lpRect->OffsetRect(rcWA.left-iX,0);
    AdjustPos(lpRect);
    return TRUE;
    }
    if(iY < rcWA.top + DETASTEP && iY!=rcWA.top)
    {//调整上
    //pWnd->SetWindowPos(NULL ,iX,rcWA.top,0,0,SWP_NOSIZE);
    lpRect->OffsetRect(0,rcWA.top-iY);
    AdjustPos(lpRect);
    return TRUE;
    }
    if(iX + lpRect->Width() > rcWA.right - DETASTEP && iX !=rcWA.right-lpRect->Width())
    {//调整右
    //pWnd->SetWindowPos(NULL ,rcWA.right-rcW.Width(),iY,0,0,SWP_NOSIZE);
    lpRect->OffsetRect(rcWA.right-lpRect->right,0);
    AdjustPos(lpRect);
    return TRUE;
    }
    if(iY + lpRect->Height() > rcWA.bottom - DETASTEP && iY !=rcWA.bottom-lpRect->Height())
    {//调整下
    //pWnd->SetWindowPos(NULL ,iX,rcWA.bottom-rcW.Height(),0,0,SWP_NOSIZE);
    lpRect->OffsetRect(0,rcWA.bottom-lpRect->bottom);
    return TRUE;
    }
    return FALSE;
    }
      

  2.   

    下面的代码可以看懂吗?有问题给我留言好了void CFashionWnd::OnMoving(UINT nSide, LPRECT lpRect)
    {
    long ScreenX,ScreenY;
    CRect WndRect;
    CRect RealRect;
    CPoint CursorPos;
    int nSnaping=0; ScreenX=GetSystemMetrics(SM_CXSCREEN);
    ScreenY=GetSystemMetrics(SM_CYSCREEN);
    GetCursorPos(&CursorPos);
    GetWindowRect(&WndRect); RealRect.left = CursorPos.x - m_CursorOffset.cx;
    RealRect.right = RealRect.left + (WndRect.right - WndRect.left);
    RealRect.top = CursorPos.y - m_CursorOffset.cy;
    RealRect.bottom = RealRect.top + (WndRect.bottom - WndRect.top); //left edge
    if(abs(RealRect.left) < m_SnapDist)
    {
    lpRect->left = 0;
    lpRect->right = (WndRect.right - WndRect.left);
    nSnaping=1;
    }
    else
    {
    lpRect->left = RealRect.left;
    lpRect->right = RealRect.right;
    }

    //top edge
    if(abs(RealRect.top) < m_SnapDist)
    {
    lpRect->top = 0;
    lpRect->bottom = (WndRect.bottom - WndRect.top);
    nSnaping=2;
    }
    else
    {
    lpRect->top = RealRect.top;
    lpRect->bottom = RealRect.bottom;
    } //right edge
    if(abs(ScreenX - RealRect.right) < m_SnapDist)
    {
    lpRect->right = ScreenX;
    lpRect->left = lpRect->right - (WndRect.right - WndRect.left);
    nSnaping=1;
    }
    else
    {
    if(nSnaping!=1 && nSnaping!=2)
    {
    lpRect->left = RealRect.left;
    lpRect->right = RealRect.right;
    }
    } //bottom edge
    if(abs(ScreenY - RealRect.bottom) < m_SnapDist)
    {
    lpRect->bottom = ScreenY;
    lpRect->top = lpRect->bottom - (WndRect.bottom - WndRect.top);
    nSnaping=2;
    }
    else
    {
    if(nSnaping!=1 && nSnaping!=2)
    {
    lpRect->top = RealRect.top;
    lpRect->bottom = RealRect.bottom;
    }
    }
    }
      

  3.   

    注:m_SnapDist为自定义的吸引距离,随便啦