MFC--Accel tmp

技术分享

 

//Code

 

class CMainWindow : public CFrameWnd
{
protected:
    int m_nCellWidth;   // Cell width in pixels
    int m_nCellHeight;  // Cell height in pixels
    int m_nRibbonWidth; // Ribbon width in pixels
    int m_nViewWidth;   // Workspace width in pixels
    int m_nViewHeight;  // Workspace height in pixels
    int m_nHScrollPos;  // Horizontal scroll position
    int m_nVScrollPos;  // Vertical scroll position
    int m_nHPageSize;   // Horizontal page size
    int m_nVPageSize;   // Vertical page size

   //...

}

 

int CMainWindow::OnCreate (LPCREATESTRUCT lpCreateStruct)
{
    if (CFrameWnd::OnCreate (lpCreateStruct) == -1)
        return -1;

    //
    // Initialize internal width and height values based on screen metrics.
    //
    CClientDC dc (this);
    m_nCellWidth = dc.GetDeviceCaps (LOGPIXELSX);//单元格宽度为1英寸,LOGPIXELSX是屏幕横向每英寸像素数96;
    m_nCellHeight = dc.GetDeviceCaps (LOGPIXELSY) / 4;//单元格高度为1/4英寸,LOGPIXELSY是屏幕纵向每英寸像素数96;
    m_nRibbonWidth = m_nCellWidth / 2;//左侧竖列条幅宽度
    m_nViewWidth = (26 * m_nCellWidth) + m_nRibbonWidth;//视图就是逻辑窗口,也叫工作区,窗口逻辑最大宽度,A~Z共26列,加上左侧竖列条幅宽度
    m_nViewHeight = m_nCellHeight * 100;//视图就是逻辑窗口,窗口逻辑最大高度,100行
    return 0;
}

void CMainWindow::OnSize (UINT nType, int cx, int cy)
{
 switch(nType)
 {
 case SIZE_RESTORED://手动调整过窗口大小
 case SIZE_MAXIMIZED://窗口最大化
 case SIZE_MINIMIZED://窗口最小化
 case SIZE_MAXHIDE://其他窗口最大化了
 case SIZE_MAXSHOW://其他窗口还原了
 default:
  break;
 }

 //cx是实际窗口宽度(像素数)
 //cy是实际窗口高度(像素数)

    CFrameWnd::OnSize (nType, cx, cy);

    //
    // Set the horizontal scrolling parameters.
    //
    int nHScrollMax = 0;
    m_nHScrollPos = m_nHPageSize = 0;

    if (cx < m_nViewWidth) {
        nHScrollMax = m_nViewWidth - 1;
        m_nHPageSize = cx;
        m_nHScrollPos = min (m_nHScrollPos, m_nViewWidth -
            m_nHPageSize - 1);
    }

    SCROLLINFO si;
    si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
    si.nMin = 0;
    si.nMax = nHScrollMax;
    si.nPos = m_nHScrollPos;
    si.nPage = m_nHPageSize;

    SetScrollInfo (SB_HORZ, &si, TRUE);

    //
    // Set the vertical scrolling parameters.
    //
    int nVScrollMax = 0;
    m_nVScrollPos = m_nVPageSize = 0;

    if (cy < m_nViewHeight) {
        nVScrollMax = m_nViewHeight - 1;
        m_nVPageSize = cy;
        m_nVScrollPos = min (m_nVScrollPos, m_nViewHeight -
            m_nVPageSize - 1);
    }

    si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
    si.nMin = 0;
    si.nMax = nVScrollMax;
    si.nPos = m_nVScrollPos;
    si.nPage = m_nVPageSize;

    SetScrollInfo (SB_VERT, &si, TRUE);
}

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。