I need to controll minumum size of dilalog. This code works very strange.
Could you temm me what is wrong ?
Thanks
Martin
void CSearchDlg::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
// TODO: Add your message handler code here and/or call default
RECT rect;
GetWindowRect( &rect );
lpMMI->ptMinTrackSize.x = rect.left + SD_MINWIDTH;
lpMMI->ptMinTrackSize.y = rect.top + SD_MINHEIGHT;
CWnd::OnGetMinMaxInfo(lpMMI);
}
CWnd::OnGetMinMaxInfo(lpMMI);
CRect r;
c_MinMax.GetWindowRect(&r);
lpMMI->ptMinTrackSize = CPoint(t.Width(), r.Height());
Note that calling the CWnd::OnGetMinMaxInfo version afterwards does no good, it likely
will undo the changes you have made. The only reason to call it at all is because it will
set other values you may not care about. What is odd about your code is that it sets the
minimum tracking size to be progressively larger than the actual window itself.
joe
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm
GetWindowRect() return the window's rect in screen coordinates. But, the
struct MINMAXINFO uses relative coordinates.
The following should do the job :
void CSearchDlg::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
// TODO: Add your message handler code here and/or call default
lpMMI->ptMinTrackSize.x = SD_MINWIDTH;
lpMMI->ptMinTrackSize.y = SD_MINHEIGHT;
CWnd::OnGetMinMaxInfo(lpMMI);
}
ML
"Martin Pospisil" <pospi...@volny.cz> a écrit dans le message de news:
#mCzB5ZnBHA.1716@tkmsftngp02...
If I remember correct this is taken from the book "The MFC Answer Book" by Eugene Kaine -
an excellent book, by the way.
The .h file:
#if !defined(AFX_TEMPDLG_H__438D2240_D7F1_11D4_B4DA_A2E73A688D1D__INCLUDED_)
#define AFX_TEMPDLG_H__438D2240_D7F1_11D4_B4DA_A2E73A688D1D__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// TempDlg.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CTempDlg dialog
CSize GetDialogSize(LPCTSTR pszTemplName,CWnd* pParent);
class CTempDlg : public CDialog
{
// Construction
public:
CRect m_rcDlg;
CTempDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CTempDlg)
enum { IDD = 0 };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTempDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CTempDlg)
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the
previous line.
#endif // !defined(AFX_TEMPDLG_H__438D2240_D7F1_11D4_B4DA_A2E73A688D1D__INCLUDED_)
The .cpp file:
// TempDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TempDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CSize GetDialogSize(LPCTSTR pszTemplName,CWnd* pParent)
{
CTempDlg dlg;
dlg.Create(pszTemplName, pParent);
return dlg.m_rcDlg.Size();
}
/////////////////////////////////////////////////////////////////////////////
// CTempDlg dialog
CTempDlg::CTempDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTempDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTempDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CTempDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTempDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTempDlg, CDialog)
//{{AFX_MSG_MAP(CTempDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTempDlg message handlers
BOOL CTempDlg::OnInitDialog()
{
GetWindowRect(&m_rcDlg);
m_rcDlg -= m_rcDlg.TopLeft();
EndDialog(0);
return TRUE;
}
On Tue, 15 Jan 2002 09:20:56 +0100, "Martin Pospisil" <pospi...@volny.cz> wrote:
Ruben
Joseph M. Newcomer [MVP]
Useful when you want to restrict sizing of a dialog or form view (with OnGetMinMaxInfo) so
that it will never get smaller than it's template size.
Have you any better suggestion to get the size in screen coordinates of the dialog from
the resource?
Ruben
When I have made SDI apps with form views I usually let the user expand the frame but not
reduce it to a size smaller than the template size, in order to not show the scroll bars.
I also save the position, size and style (maximized or normal) of the frame window when
the app is closed and use this info to position and size the frame in PreCreateWindow() of
the main frame - the style I set in InitInstance() of the app class.
The form view calls ResizeParentToFit() in OnInitialUpdate() by default. I remove this
because otherwise my saved settings for the frame, done in pre create window, is lost.
To find out the minimal size of the form view (the client area of the frame window) I
simply call the GetDialogSize() function once in OnIitialUpdate() of the form and save
this as a member variable. GetDialogSize() creates an invisible dialog from the given
template, gets the size and immediately destroys the dialog.
m_sizeInitial=GetDialogSize(MAKEINTRESOURCE(IDTemplate_For_This_View),this); - can it get
any easier? For me, that is - windows may have to put a little bit more effort in here,
creating the dialog and all, but I don't care.
The mainframe asks the form view for it's minimum size in OnGetMinMaxInfo() and adds size
for menu, statusbar, toolbars, border and so on, and passes this on to the ptMinTrackSize
in the MINMAXINFO structure.
Is there anywhere I can find the size of the form view as created in the resource editor,
with this method, without calculating it from the dialog units in the resource or creating
it as I have done?
Why is this any different from creating the invisible frame as you do? I assume you also
have to add the size of status bar, menu bar, tool bars and whatever else you have in the
frame unless you create them also. Or have I missed something?
Well, everything is simple when you know how to do it. I remember that I spent several
days before I got the result I wanted, when I just started out to learn MFC, a year and a
half ago.
Ruben
On Wed, 16 Jan 2002 09:21:34 +0100, Ruben Jönsson <ru...@pp.sbbs.se> wrote:
>One correction: The code is actually taken from MSJ, september 1998, C++ Q&A by Paul
>DiLascia.
>
>When I have made SDI apps with form views I usually let the user expand the frame but not
>reduce it to a size smaller than the template size, in order to not show the scroll bars.
>I also save the position, size and style (maximized or normal) of the frame window when
>the app is closed and use this info to position and size the frame in PreCreateWindow() of
>the main frame - the style I set in InitInstance() of the app class.
>
>The form view calls ResizeParentToFit() in OnInitialUpdate() by default. I remove this
>because otherwise my saved settings for the frame, done in pre create window, is lost.
>
>To find out the minimal size of the form view (the client area of the frame window) I
>simply call the GetDialogSize() function once in OnIitialUpdate() of the form and save
>this as a member variable. GetDialogSize() creates an invisible dialog from the given
>template, gets the size and immediately destroys the dialog.
>m_sizeInitial=GetDialogSize(MAKEINTRESOURCE(IDTemplate_For_This_View),this); - can it get
>any easier? For me, that is - windows may have to put a little bit more effort in here,
>creating the dialog and all, but I don't care.
>
>The mainframe asks the form view for it's minimum size in OnGetMinMaxInfo() and adds size
>for menu, statusbar, toolbars, border and so on, and passes this on to the ptMinTrackSize
>in the MINMAXINFO structure.
>
>Is there anywhere I can find the size of the form view as created in the resource editor,
>with this method, without calculating it from the dialog units in the resource or creating
>it as I have done?
Thinking about it, the scroll view (which the form view is derived from) should know about
the size of the form as created in the resource editor, since it has to know when the
scroll bars should be visible.
GetTotalSize() in OnInitialUpdate() returns this size in pixels. No need for a static
invisible control, an invisible dialog or an invisible frame any more. For a formview,
anyway.
>
>Why is this any different from creating the invisible frame as you do? I assume you also
>have to add the size of status bar, menu bar, tool bars and whatever else you have in the
>frame unless you create them also. Or have I missed something?
>
>Well, everything is simple when you know how to do it. I remember that I spent several
>days before I got the result I wanted, when I just started out to learn MFC, a year and a
>half ago.
>
>Ruben
>
Ruben