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);//cell width is 1 inches, logpixelsx is the screen horizontal pixels per inch 96;
M_ncellheight = DC. GetDeviceCaps (logpixelsy)/4;//cell height is 1/4 inches, Logpixelsy is the screen portrait of 96 pixels per inch;
M_nribbonwidth = m_ncellwidth/2;//Left vertical column banner width
M_nviewwidth = (m_ncellwidth) + m_nribbonwidth;//view is the logical window, also known as the workspace, the maximum window logic width, a~z a total of 26 columns, plus the left vertical banner width
M_nviewheight = M_ncellheight * 100;//view is logical window, window logic maximum height, 100 rows
return 0;
}
void Cmainwindow::onsize (UINT nType, int cx, int cy)
{
Switch (nType)
{
Case size_restored://manually resizing windows
Case size_maximized://Window Maximization
Case size_minimized://Window Minimized
Case size_maxhide://Other windows to maximize the
Case size_maxshow://Other Windows restores the
Default
Break
}
CX is the actual window width (pixels)
Cy is the actual window height (number of pixels)
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