BOOL CDemoDlg::OnInitDialog()
{
...
int ScreenWidth = GetSystemMetrics( SM_CXSCREEN );
int ScreenHeight = GetSystemMetrics( SM_CYSCREEN ); MoveWindow( 0, 0, ScreenWidth, ScreenHeight - 32 ); GetDlgItem( IDC_FOLDER_TREE )->MoveWindow( 10, 10, 100, 100 );
......
}LRESULT CDemoDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if( message == WM_DISPLAYCHANGE )
{
int ScreenWidth = GetSystemMetrics( SM_CXSCREEN );
int ScreenHeight = GetSystemMetrics( SM_CYSCREEN ); MoveWindow( 0, 0, ScreenWidth, ScreenHeight - 32 ); GetDlgItem( IDC_FOLDER_TREE )->MoveWindow( 10, 10, 100, 100 );
...
}
return CDialog::WindowProc(message, wParam, lParam);}问题:在OnInitDialog中对话框和控件的大小都可以改变,但是在WM_DISPLAYCHANGE时对话框大小没变,控件大小变了,我要怎么才能使对话框大小改变?
{
...
int ScreenWidth = GetSystemMetrics( SM_CXSCREEN );
int ScreenHeight = GetSystemMetrics( SM_CYSCREEN ); MoveWindow( 0, 0, ScreenWidth, ScreenHeight - 32 ); GetDlgItem( IDC_FOLDER_TREE )->MoveWindow( 10, 10, 100, 100 );
......
}LRESULT CDemoDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if( message == WM_DISPLAYCHANGE )
{
int ScreenWidth = GetSystemMetrics( SM_CXSCREEN );
int ScreenHeight = GetSystemMetrics( SM_CYSCREEN ); MoveWindow( 0, 0, ScreenWidth, ScreenHeight - 32 ); GetDlgItem( IDC_FOLDER_TREE )->MoveWindow( 10, 10, 100, 100 );
...
}
return CDialog::WindowProc(message, wParam, lParam);}问题:在OnInitDialog中对话框和控件的大小都可以改变,但是在WM_DISPLAYCHANGE时对话框大小没变,控件大小变了,我要怎么才能使对话框大小改变?
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.cx = 600;
cs.cy = 400; return TRUE;
}
PreCreateWindow——在这个里面
或者可能MoveWindow用如下格式:
BOOL MoveWindow(
HWND hWnd, //带上对话框句柄
int X,
int Y,
int nWidth,
int nHeight,
BOOL bRepaint
);
带句柄也不行
SetWindowPos两种方法也一样
void CDemoDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
int ScreenWidth = GetSystemMetrics( SM_CXSCREEN );
int ScreenHeight = GetSystemMetrics( SM_CYSCREEN ); MoveWindow( 0, 0, ScreenWidth, ScreenHeight - 32, TRUE );
GetDlgItem( IDC_FOLDER_TREE )-> MoveWindow( 10, 10, 100, 100 );
...
}
.h
afx_msg void OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI);.cpp
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
.....
}添加上面的响应
设置最大尺寸
.h
afx_msg void OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI);.cpp
...
ON_WM_GETMINMAXINFO()
....
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
lpMMI->ptMaxSize = CPoint(nX, nY);
lpMMI->ptMaxPosition = CPoint(left, top);
lpMMI->ptMinTrackSize = CPoint(nX, nY);
lpMMI->ptMaxTrackSize = CPoint(nX, nY);
}
添加上面的响应
设置最大尺寸