CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Dec 2009
    Posts
    161

    How to make a Dialog resizable

    Hi,

    I am dealing with dialog window created usign ResEdit as a resource editor. Now, I'd need to make a window resizable and to have all the child controls in it resize themselves according to the dialog size. Can iy actually be done?


    This is the code for the dialog:

    Code:
    //
    // Dialog resources
    //
    
    IDD_POPUP DIALOG 25, 25, 485, 254
    STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "List View Window"
    FONT 8, "MS Shell Dlg"
    BEGIN
        CONTROL "", IDC_LIST1, WC_LISTVIEW, WS_TABSTOP | WS_BORDER | LVS_ALIGNLEFT | LVS_REPORT, 4294967294, 4294967295, 489, 230
    END
    thanks

  2. #2
    Join Date
    Dec 2009
    Posts
    161

    Re: How to make a Dialog resizable

    I see lots of examples of how to do this out there but they are all for MFC
    or other toolkits. I need to do this in a C++ app using normal win32 API
    calls.

  3. #3
    Join Date
    Feb 2005
    Posts
    2,160

    Re: How to make a Dialog resizable

    There's nothing inherent to MFC that makes this any different. Basically you have to do it all yourself. Make the dialog resizable (resizing border: WS_SIZEBOX or WS_THICKFRAME), then handle the WM_SIZE message. In your handler, resize all you controls to fit the dialog the way you want by calling MoveWindow or SetWindoPos on them.

  4. #4
    Join Date
    Dec 2009
    Posts
    161

    Re: How to make a Dialog resizable

    I noticed something strange with this code:

    Code:
    INT_PTR CALLBACK procPopup(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	UNREFERENCED_PARAMETER(lParam);
    
    	RECT rc;
    	memset(&rc,0,sizeof(RECT));
    	GetWindowRect(hDlg, &rc);
    	
    	TCHAR szBottom[5] = {0};
    	_itot_s(rc.bottom,szBottom,5,10);
    
    	TCHAR szRight[5] = {0};
    	_itot_s(rc.right,szRight,5,10);
    
    	TCHAR szTop[5] = {0};
    	_itot_s(rc.top,szTop,5,10);
    
    	TCHAR szLeft[5] = {0};
    	_itot_s(rc.left,szLeft,5,10);
    
    	TCHAR marameo[256] = {0};
    	_tcsncat_s(marameo, _T("Bottom: "),10);
    	_tcsncat_s(marameo, szBottom,5);
    	_tcsncat_s(marameo, _T(" Width: "),10);
    	_tcsncat_s(marameo, szRight,5);
    	_tcsncat_s(marameo, _T(" Top: "),10);
    	_tcsncat_s(marameo, szTop,5);
    	_tcsncat_s(marameo, _T(" Left: "),10);
    	_tcsncat_s(marameo, szLeft,5);
    
    
    	switch (message)
    	{
    	case WM_SIZE:
    		SetWindowText(hDlg, (LPTSTR)marameo);
    		break;
    
    	case WM_MOVE:
    		//SetWindowText(hDlg, (LPTSTR)marameo);
    		break;
    	}
    
    }
    even if I just move the window that will affect "bottom" and "right" vars...so I think using the values from RECT might be wrong approach

  5. #5
    Join Date
    Dec 2009
    Posts
    161

    Re: How to make a Dialog resizable

    I guess this is the right code to achieve the goal:

    Code:
    	int dlgw           = 0;
    	int dlgh           = 0;
    	TCHAR szWidth[5]   = {0};
    	TCHAR szHeight[5]  = {0};
    	TCHAR marameo[256] = {0};
    	HWND hListView     = GetDlgItem(hDlg, IDC_LIST1);
    
    	case WM_SIZE:
    		//
    		// WM_SIZE Notification
    		// http://msdn.microsoft.com/en-us/library/ms632646%28VS.85%29.aspx
    		//
    
    		// Resize List view inside window
    		//
    		dlgw = (int)LOWORD(lParam);
    		dlgh = (int)HIWORD(lParam);
    
    		_itot_s(dlgw,szWidth,5,10);
    		_itot_s(dlgh,szHeight,5,10);
    
    		_tcsncat_s(marameo, _T("Width: "),10);
    		_tcsncat_s(marameo, szWidth,5);
    		_tcsncat_s(marameo, _T(" Height: "),10);
    		_tcsncat_s(marameo, szHeight,5);
    	
    		SetWindowText(hDlg, (LPTSTR)marameo);
    
    		MoveWindow(hListView, -1, -1, (dlgw + 2), (dlgh -25) , true);
    		ShowWindow(hListView, SW_SHOW);
    		/////////////////////////////////////////////////////////////////////
    		break;
    Now, I'd like to avoid the window from resizing less the x300, y250 like it has some min width and minheight values....do you think that is possible?

    thanks

  6. #6
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: How to make a Dialog resizable

    Quote Originally Posted by THEARTOFWEB View Post
    Now, I'd like to avoid the window from resizing less the x300, y250 like it has some min width and minheight values....do you think that is possible?
    Sure - check out WM_GETMINMAXINFO message.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  7. #7
    Join Date
    Dec 2009
    Posts
    161

    Re: How to make a Dialog resizable

    by the way, I have found the the status bar does not need any actual parameters to be redrawn! the following creates a status bar in the Dialog:

    Code:
    	// Create Status Bar
    	//
    	InitCommonControls();
    	HWND hWndStatus = CreateWindowEx(0,STATUSCLASSNAME,NULL,WS_CHILD | WS_VISIBLE,0,0,10,10,hDlg,(HMENU)IDC_STATUSBAR,hInst,NULL);
    	
    	UINT indicators[] = {250,1100};                                         // Lunghezza celle status bar:
    																			//da 0 a 250 e da 250 a 1100
    
    	SendMessage( hWndStatus, SB_SETPARTS, 2, (LPARAM)(LPINT)indicators);    // setta la status bar in due celle con
    																			// con le misure create prima (indicators)
    
    	SendMessage( hWndStatus, SB_SETTEXT, 0, (LPARAM)TEXT("Hello World!") ); // Riempi prima cella
    	SendMessage( hWndStatus, SB_SETTEXT, 1, (LPARAM)TEXT("Hello World!") ); // Riempi seconda cella
    
    	if (hWndStatus == NULL)
    	{
    		MessageBox (NULL, TEXT("Status Bar not created!"), NULL, MB_OK );
    	}
    with this I handle the WM_SIZE inside the dlgProc:

    Code:
    MoveWindow(hStatusBar, 0, 0, 0 ,0 , true);
    ShowWindow(hStatusBar, SW_SHOW);
    it gets redrawn correctly!

  8. #8
    Join Date
    Dec 2009
    Posts
    161

    Re: How to make a Dialog resizable

    Quote Originally Posted by VladimirF View Post
    Sure - check out WM_GETMINMAXINFO message.
    uhm...I think I need some help with that

  9. #9
    Join Date
    Dec 2009
    Posts
    161

    Re: How to make a Dialog resizable

    I tried adding this:

    Code:
    	case WM_GETMINMAXINFO:
    		pMMI = (LPMINMAXINFO)lParam;
    		pMMI->ptMaxTrackSize.x = 300;
    		pMMI->ptMaxTrackSize.y = 300;
    		break;
    Yet, whenever I move or resize the Dialog window it resizes to those parameters and cannot be resized anymore :-(

    EDIT: sorry that was a shame of me:

    Code:
    	case WM_GETMINMAXINFO:
    		pMMI = (LPMINMAXINFO)lParam;
    		pMMI->ptMinTrackSize.x = 300;
    		pMMI->ptMinTrackSize.y = 300;
    		break;

  10. #10
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: How to make a Dialog resizable

    If you want to move a lot of windows without too much flickering, you can use DeferWindowPos.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  11. #11
    Join Date
    Nov 2009
    Posts
    3

    Re: How to make a Dialog resizable

    http://andyuk2010.blogspot.com/2011/...-controls.html

    0 down vote


    The above blog posting has instructions on how to create a minimalist re-sizeable dialog in MFC.

    It is basically an implementation of Paulo Messina's posting at CodeProject but with as much extraneous stuff removed as possible, just to help clarify how to do it better.

    It is fairly straightforward to implement once you've had a bit of practice: the important bits are to:

    i. ensure you have his CodeProject libraries etc pulled into your project and it all compiles correctly.

    ii. do the extra initialization required inside the OnInitDialog method: make the gripper visible, set the maximum dilog size, add anchor points to the dialog control items that you wish to 'stretch' etc.

    iii. Replace usage of CDialog with CResizableDialog at the appropriate points: in the dialog class definition, constructor, DoDataExchange, BEGIN_MESSAGE_MAP, OnInitDialog etc.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured