0

Using the GetClientRect inside the CView::OnInitialUpdate() gives me lower values in Width and the Height than using the same code inside the CView::OnSize.

ie

Inside OnInitialUpdate I get

tagRECT = {top=0 bottom=468 left=0 right=1009}

while inside OnSize I get

tagRECT = {top=0 bottom=518 left=0 right=1062}

What seems to be wrong here ?

Maverick
  • 1,105
  • 12
  • 41
  • Why do you assume the values returned from `GetClientRect` to be the same? After all, `OnSize` is called in response to a change in size. – IInspectable Feb 06 '16 at 19:02
  • The window is starting up as maximized and the onsize is called after initial update without any change in the window size. I suspect space for horizontal and vertical scrollers in the initial update call. – Maverick Feb 06 '16 at 19:20
  • Scrollbar's width is only about 20 pixels, so that can't be it. The initial size is set in `CreateWindow`, before `HWND` is ready, so `WM_SIZE`/`OnSize` is not called. At some point after `OnInitialUpdate` there is a call to `SetWindowPos` which changes the size and sends `WM_SIZE` message. If you didn't change the size directly then it must have been done by the frame work. – Barmak Shemirani Feb 06 '16 at 21:45
  • Yes I knew from the begging that the extra space is too much for the scrollers. I think that you have right , the framework somewhere change the position and the size of the view. The question is : is there a safe place to get the final size just for once or for initialization? I can do this of course inside the onsize but what can I do if I want it for initialization purposes only at the view creation ? – Maverick Feb 07 '16 at 08:51
  • Why do you need a "safe place"? When the size changes you have to do all the calculations you need. So the answer is simple: The size changes -> OK let me do the new calculations. – xMRi Feb 08 '16 at 07:16
  • Yes that's true but I can't really remember right now if onsize is called at least one time at the initialization ... I suppose it will but if not then I have a problem here.That's maybe the main reason why I need to get valid values in the initial update. Anyway as soon as I return to my office I will give it a try. The conclusion is that initial update does not contain correct values as I expected for the view dimension for a reason only framework knows . – Maverick Feb 08 '16 at 13:48
  • Try to respond to your view's `ON_WINDOWPOSCHANGING` and `ON_WINDOWPOSCHANGED` with only a call to their `__super`'s implementation, and put a breakpoint on both. Do the same on the frame that contains the view. Maybe you will see where the resize request that modifies client rect coordinates comes from. – sergiol Jun 04 '16 at 09:44
  • @sergiol This question is about 3 months old. I have solved the problem, i dont remember how right now, but I solved. Thank you for your interesting :-) – Maverick Jun 04 '16 at 09:47

0 Answers0