码迷,mamicode.com
首页 > 编程语言 > 详细

MFC--Accel tmp

时间:2015-05-17 00:40:56      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

//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);
}

MFC--Accel tmp

标签:

原文地址:http://www.cnblogs.com/starnix/p/4508868.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!