Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used a commandbutton in a main window where OnClick function is written
as ShowWindow(SW_SHOWMAXIMIZED); is used.
The problem is that only the edges of the window increases but i want the tools inside the window also change size to fill the maximized window.

C++
void CDemoDlg::ClickMaximize()
{
ShowWindow(SW_SHOWMAXIMIZED);
}
Posted
Updated 29-Mar-12 21:00pm
v4

Create a command handler for the WM_SIZE message. You should be able to do this with the wizard.

In that handler:
1. Check to make sure you have a valid windows handle for at least one of your controls. The first time WM_SIZE is called, you have invalid handles. If this happens, just return.

2. Call GetClientRect() in your dialog to get the dimensions of the inside of the window.

3. Call MoveWindow() for each control to place them in a new size and position.

How you calculate the new positions will depend on how you want them to look.

If you want to position the control relative to existing controls, you can call GetWindowRect(), then ScreenToClient() to get the client based window position of the reference control.

If you get flicker on the controls, you can call LockWindowUpdate() before and after your resizing code to block repaints while the resizing is done.

This will give you a dialog that will adjust the controls dynamically as you resize it.
 
Share this answer
 
Comments
chaiein 16-Feb-12 4:45am    
first step is fine but next steps i am not getting
chaiein 16-Feb-12 4:47am    
i want to know what to include in movewindow()
JackDingler 16-Feb-12 9:02am    
You'll need to calculate where you want the control to appear.

The pass those coordinates to MoveWindow().

I can't tell you where you want the control to appear.

What I do for instance, if I have controls in a column, I'll place each subsequent control's CRect::top member to the previous control's, CRect::bottom + VerticalMargin. The value you set for Vertical margin will be a stylistic decision.
chaiein 13-Mar-12 6:02am    
void CDemoDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

CRect myRect;
GetWindowRect( &myRect);
//save current cursor coordinate
GetCursorPos(&point);
ScreenToClient(&point);
SendMessage(WM_NCLBUTTONDOWN, HTCAPTION, NULL);
//__super::OnLButtonDown(nFlags, point);
}

void CDemoDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

CRect myRect;
GetWindowRect( &myRect);
CPoint curpoint;
GetCursorPos(&curpoint);
{
MoveWindow(curpoint.x - point.x, curpoint.y - point.y,
myRect.right - myRect.left, myRect.bottom - myRect.top, TRUE);
}
}



The above code allows me to move but when its moved more i am not able to see backgrounds What correction is needed for above
JackDingler 13-Mar-12 9:50am    
I'm not sure why you're using the cursor position. It doesn't really fit you original question.

Repositioning the controls should be done inside the WM_SIZE handler.

If you goal is to move the controls using the mouse, then you may need to call Invalidate and UpdateWindow on the dialog.

I've never seen a problem with the background not getting updated, so maybe the problem is in what handler you're doing this?
C++
void CDemoDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default

	 CRect myRect;
	 GetWindowRect(&myRect);
              //save current cursor coordinate
		GetCursorPos(&point);
		//ScreenToClient(&point);
		SendMessage(WM_NCLBUTTONDOWN, HTCAPTION, 0);
	__super::OnLButtonDown(nFlags, point);
}

void CDemoDlg::OnMouseMove(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default

	CRect myRect;
	 GetWindowRect( &myRect);
	 CPoint curpoint;
	 GetCursorPos(&curpoint);
     {     
           MoveWindow(curpoint.x - point.x, curpoint.y - point.y, 
			myRect.right - myRect.left, myRect.bottom - myRect.top, TRUE);
     }
	
	 __super::OnMouseMove(nFlags, point);
}

This solved my problem of moving window
 
Share this answer
 
v2
Comments
JackDingler 30-Mar-12 11:13am    
I'm still not clear on what you're actually doing.

Normally we do a GetClientRect, and not a GetWindowRect. GetClientRect gets the window area inside the dialog frame.

I don't what you mean by the "the tools gets disappered", or why you're using the cursor position.

I think you've left something out, in your description.
chaiein 2-Apr-12 1:09am    
The above code i have used cursor position to move the window with out the title bar. So move window is working fine now using the above code. Now while trying to do maximising of window i tried the method as in the http://www.codeproject.com/Articles/1657/EasySize-Dialog-resizing-in-no-time in which i am facing problem "the tools disappear" means the items inside the window like buttons text box etc which i have used will become invisible. I don't know exactly why its happening but i guess that its placed somewhere where in the window and cannot view.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900