Link to home
Start Free TrialLog in
Avatar of IssacJones
IssacJones

asked on

Border in a dialog

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
Avatar of Zoppo
Zoppo
Flag of Germany image

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
Avatar of IssacJones
IssacJones

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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.


Many thanks Zoppo
You're welcome - I'm glad I could help ...

Have a nice day,

best regards,

ZOPPO