VC6下没有问题 CRect m_rect;BOOL CXXXDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon
CRect m_rect;// CXXDlg::OnInitDialog()函数中
CRect rect;
CRect rc; GetClientRect(&rect);
m_list.GetWindowRect(&rc);
ScreenToClient(&rc); m_rect.left = rc.left - rect.left;
m_rect.top = rc.top - rect.top;
m_rect.right = rect.right - rc.right;
m_rect.bottom = rect.bottom - rc.bottom;// WM_SIZE消息响应函数OnSize中
void CXXXDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(m_list.GetSafeHwnd())
{
CRect rect;
GetClientRect(&rect);
CRect rc;
rc.left = rect.left + m_rect.left;
rc.top = rect.top + m_rect.top;
rc.right = rect.right - m_rect.right;
rc.bottom = rect.bottom - m_rect.bottom;
m_list.MoveWindow(&rc);
}
}
你这段代码有点问题,编绎可以通过,但运行时,改变SIZE,LIST就变得无限大一样,也没有滚动条
CRect m_rect;BOOL CXXXDlg::OnInitDialog()
{
CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
} // Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_list.ModifyStyle(0, LVS_REPORT);
m_list.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT); m_list.InsertColumn(0, _T("AA"), LVCFMT_LEFT, 100);
m_list.InsertColumn(1, _T("BB"), LVCFMT_LEFT, 100); for(int i=0; i<50; i++)
{
CString str;
str.Format(_T("%d - Hello - %d"), i, i);
m_list.InsertItem(i, _T(""));
m_list.SetItemText(i, 0, str);
m_list.SetItemText(i, 1, str);
} CRect rect;
CRect rc; GetClientRect(&rect);
m_list.GetWindowRect(&rc);
ScreenToClient(&rc); m_rect.left = rc.left - rect.left;
m_rect.top = rc.top - rect.top;
m_rect.right = rect.right - rc.right;
m_rect.bottom = rect.bottom - rc.bottom;
return TRUE; // return TRUE unless you set the focus to a control
}void CXXXDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(m_list.GetSafeHwnd())
{
CRect rect;
GetClientRect(&rect);
CRect rc;
rc.left = rect.left + m_rect.left;
rc.top = rect.top + m_rect.top;
rc.right = rect.right - m_rect.right;
rc.bottom = rect.bottom - m_rect.bottom;
m_list.MoveWindow(&rc);
}
}
在解压出来的目录下MFC\Visual C++ 2008 Feature Pack\VisualStudioDemo
是一个VisualStudio的界面DEMO,可以看一下