Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2003-11-18
2
Medium Priority
?
219 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
2 Comments
 
LVL 9

Accepted Solution

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

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

824 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