Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Whats the screen size? 1

Status
Not open for further replies.

Lorey

Programmer
Feb 16, 2003
88
SG
Hi!

I need to have a dialog screen 400 pixel in height running in 1024 (height)screen. How would I know in the design time the size of the dialog Im creating in VC++?

Please help!
 
Does the window size vary according to the number of items in it? If it does, work out what size you want and use SetWindowPos to resize it. In fact, the easy way is not to half design it: just dump all the controls you want on the dialog, strategically positioned either horizontally or vertically. In the program, read the position, and position the other controls relative to your strategically positioned controls. Then resize the dialog.

Note of warning if you do it this way:

1) there are two routines: GetWindowRect and GetClientRect. WindowRect returns the coordinates relative to the top left corner of the screen. ClientRect is the client area so the top left corner is always 0,0
2) When SetWindowPos is called, it expects the coordinates to be relative to 0,0 (tlc in the example below) of the client area.
3) The difference between the window width and the client width divided by 2 is the border width. Add this to the client height and subtract from the bottom window position to get the top left corner of the client area.
4) MoveWindow is a good alternative to SetWindowPos if you don't want to play with Z orders and all the other strange bits.
Code:
RECT crect, wrect;
LONG borderwidth;
POINT tlc;
GetClientRect (hwnd, &crect);
GetWindowRect (hwnd, &wrect);
borderwidth = ((wrect.right - wrect.left) - (crect.right - crect.left))/2;
tlc.x = wrect.left + borderwidth;
tlc.y = wrect.bottom - (crect.bottom - crect.top + borderwidth);

Why MS can't give a routine that tells you the position relative to 0,0 is beyond me. It has been like this since Windows 2.1 (circa 1988).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top