Solved

Border in a dialog

Posted on 2010-09-16
7
397 Views
Last Modified: 2013-11-20
Hiya

Can anybody tell me how to get at runtime the border around a dialog?

That is, when designing a dialog there is a dotted region around the dialog area where controls can't be dragged. I need to know what the distance is between this border and the dialog eges.

John
0
Comment
Question by:IssacJones
  • 4
  • 3
7 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 33690208
Hi IssacJones,

do you mean the dotted, blue rectangle shown in the resource editor? If so there's no way: This isn't a part of the dialog or anything else, it's just a guide (just like i.e. the page margins in MS Word) border which even can be changed within the resource editor. A dailog doesn't have another border than its window rect and client rect.

ZOPPO
0
 

Author Comment

by:IssacJones
ID: 33690245
Yes, I mean the blue dotted line.

In that case, if I have a control next to the line i.e. immediately to the left of the line on the left. I could get the position of that control. Could I then work out what the distance is by finding out the distance from the left edge of the dialog and the control?

Could you tell me how to do that?
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 500 total points
ID: 33690353
Yes, that's not difficult - maybe best is to implement this as a generic function as the attached one and use it like this:


> // within a function of your dialog class
> CRect rect = GetDistances( this, GetDlgItem( IDOK ) );

After this 'rect' contains the distances to left, top, right and bottom border of the dialog's client rect - if you need it to the dialog's window rect borders pass 'false' as a third argument ...

Hope that helps,

ZOPPO
CRect GetDistances( CDialog* pDlg, CWnd* pCtrl, bool bUseClientRect = true )

{

	CRect rectDlg, rectCtrl;



	if ( false == bUseClientRect )

	{

		pDlg->GetWindowRect( &rectDlg );

		pDlg->ScreenToClient( &rectDlg );

	}

	else

	{

		pDlg->GetClientRect( &rectDlg );

	}



	pCtrl->GetWindowRect( &rectCtrl );

	pDlg->ScreenToClient( &rectCtrl );



	return CRect( rectCtrl.left - rectDlg.left, rectCtrl.top - rectDlg.top, rectDlg.right - rectCtrl.right, rectDlg.bottom - rectCtrl.bottom );

}

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:IssacJones
ID: 33690398
Thanks Zoppo

Could you explain, or direct me to somewhere else, how to get my head round the differences between GetWindowRect, GetClientRect and ScreenToClient?

I'm having difficulty in understanding how all these coordinate systems work together.

John
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 33690486
No problem:

- GetWindowRect: This in any case for every window (so even for every control) retrieves the bounding rectangle in screen coordinates, so relativ to the top/left corner of the monitor

- GetClientRect: This retrieves the client area of a window, this is the area within the window excluding borders, caption, scrollbars a.s.o. - client coordinates are relative to the upper-left corners of the window, so the returned rectangles top/left values are always ( 0, 0 )

- ScreenToClient: translates a point or a rect from screen coordinates to the client coordinate system of the given window

- ClientToScreen: Does the opposite, so it translates coordinates from the given window's client coordinate system to screen coordinates


So, i.e. in the above code (in case 'bUseClientRect' is 'true') the line
> pDlg->GetClientRect( &rectDlg );
retrieves the client area of the dialog, i.e. something like ( 0, 0, 400, 300 )
> pCtrl->GetWindowRect( &rectCtrl );
retrieves the screen coordinates of the control, i.e. something like ( 600, 250, 650, 280 )
> pDlg->ScreenToClient( &rectCtrl );
translates the coordinates in 'rectCtrl' by 'mapping' it into the dialog's client coordinates - so, i.e. if the dialog's top/left is 300, 200 in screen coordinates the resulting 'rectCtrl' is ( 300, 50, 350, 80 ) in client coordinates.


I hope that's not confuzing ;o)

If you're interested you can read a lot about general windows/controls issues here: http://www.functionx.com/visualc/Lesson07.htm - there allthough a description of these functions with some sample code can be found.


0
 

Author Closing Comment

by:IssacJones
ID: 33691454
Many thanks Zoppo
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 33691462
You're welcome - I'm glad I could help ...

Have a nice day,

best regards,

ZOPPO
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
java ^ examples 8 62
canBalance challenge 34 70
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 194
"Black Box" Testing of Control System Software 2 26
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now