Solved

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

Posted on 2003-11-18
2
208 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 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Error on moodle after upgrade 3 106
Add content to output file 4 58
Named range not carried over 10 57
Doc'in system (example?) BA 7 78
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…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now