Solved

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

Posted on 2003-11-18
2
217 Views
Last Modified: 2013-11-20
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
Comment
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
2 Comments
 
LVL 9

Accepted Solution

by:
Priyesh earned 500 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

by:AndyAinscow
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

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
In this post we will learn different types of Android Layout and some basics of an Android App.
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, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Suggested Courses

626 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