15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


How can I size client rect precisely ?

Taehoon Kee -- keeth@chollian.dacom.co.kr
Thursday, September 19, 1996

Environment : VC++ 4.0, Windows 95

To size a view at wanted size,
In my view class's OnInitialUpdate,

 rect.left   = 100;
 rect.top    = 100;
 rect.right  = 200;
 rect.bottom = 200;

 AdjustWindowRect( &rect, AfxGetMainWnd()->GetStyle(), TRUE);
 AfxGetMainWnd()->MoveWindow( rect, TRUE);

And then,
In OnDraw,
 I call GetClientRect,

The result I wanted was ( 0, 0, 100, 100),
BUT the result was -> ( 0, 0,  96,  96) !
I guess difference 4 is border's thickness,
 but I started this app by turning off "Thick Frame".

What is wrong ?

To size a view at wanted size,
I try CalcWindowRect and AdjustWindowRect.
But Both were wrong.

And in case of adopting ToolBar and/or StatusBar,
 problems get worse.

How can I do it ?

Thanks in advance.
Taehoon



ganeshs@nationwide.com
Monday, September 23, 1996

Environment : VC++ 4.0, Windows 95

> To size a view at wanted size,
> In my view class's OnInitialUpdate,
>
>  rect.left   = 100;
>  rect.top    = 100;
>  rect.right  = 200;
>  rect.bottom = 200;
>
>  AdjustWindowRect( &rect, AfxGetMainWnd()->GetStyle(), TRUE);
>  AfxGetMainWnd()->MoveWindow( rect, TRUE);
>
> And then,
> In OnDraw,
>  I call GetClientRect,
>
> The result I wanted was ( 0, 0, 100, 100),
> BUT the result was -> ( 0, 0,  96,  96) !
> I guess difference 4 is border's thickness,
>  but I started this app by turning off "Thick Frame".
>
> What is wrong ?
>
> To size a view at wanted size,
> I try CalcWindowRect and AdjustWindowRect.
> But Both were wrong.
>
> And in case of adopting ToolBar and/or StatusBar,
>  problems get worse.
>
> How can I do it ?
>
> Thanks in advance.
> Taehoon

    Put the  CalcWindowRect call in  your frame window's  OnCreate, then
call MoveWindow, and  things should be fine. What's  happening is, since
the  View does  not  have  a "frame",  CalcWindowRect  returns the  rect
unchanged. So, effectively, you're using the same initial values to size
the Frame, not taking the Frame's "frame" into account.

    For correct View sizing with ToolBars/StatusBars, use RepositionBars
with  the reposQuery  option (again)  in your  Frame window's  OnCreate,
passing  the View's  desired size.  Then call  MoveWindow with  the Rect
returned,      and       RepositionBars      again.       Check      out
ftp://ftp.microsoft.com/softlib/mslfiles/DLGCBR32.EXE.    This   program
explains the procedure for a Dialog, but the same principle applies.

/ ___|    / ___| __ _ _ __   ___  ___| |
\___ \   | |  _ / _` | '_ \ / _ \/ __| '_ \
 ___) |  | |_| | (_| | | | |  __/\__ \ | | |
|____(_)  \____|\__,_|_| |_|\___||___/_| |_|




| Вернуться в корень Архива |