Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Does window width equal (xmax - xmin) or (xmax - xmin  + 1)?

Posted on 2003-11-18
Medium Priority
218 Views
I am confused as to what the meaning of a window is in regards to the Windows SDK.
Some functions like SetWindowPos() require the window width and height as parmeters and other function like GetWindowRect() pass back the left, right, top, and bottom positions.  I am trying to understand exactly how they relate.

I keep coming across code that says width = xmax - xmin.  For example in Microsoft Knowledge Base #68556 it has a call to GetWindowRect(hDlg, &rect) followed by a call to SetWindowPos() in which the fourth parameter for the width is the following:

rect.right - rect.left,     // Based on the values returned by
// GetWindowRect, calculate the new
// width of the main window.

I would think that the width would be rect.right - rect.left + 1.  If the window is 3 pixels wide and placed at the upper right corner wouldn't there be pixels at horizontal screen locations 0, 1, and 2?  Therefore right - left would be 2 - 0 which is only 2 (not 3)

Could someone please explain to me the logic of whether or not you add 1 to the right - left calculation to figure out window width?

Thanks,
Mark

0
Question by:kaplan1
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions

LVL 9

Accepted Solution

Priyesh earned 2000 total points
ID: 9775838
If the window is 3 pixels wide, and you place it at top left corner, it would span from 0 to 3

Try this code:

HWND hWnd = CreateWindow("EDIT", "", WS_CHILD|WS_VISIBLE, 0, 0, 3, 3, m_hWnd, NULL, AfxGetInstanceHandle(), NULL) ;

RECT rc ;
::GetClientRect(hWnd, &rc) ;//see rect = {0, 0, 3, 3}

So, the answer would be width = right - left. not right - left +1
0

LVL 44

Expert Comment

ID: 9776823
If rect is a CRect then it has a function rect.Width().
Also note there is a NormalizeRect function which forces a positive width and height of the rect.  (think of left = 90, right=60, unnormalised width= -30, rect.right-rect.left=-30 but if you normalise it the width is then 30).
Why could the left be bigger than the right?
eg. Use the mouse to select an area but start at the bottom right first.  If the programmer was lazy you would end up with that situation.
0

## Featured Post

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
###### Suggested Courses
Course of the Month10 days, 7 hours left to enroll

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

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