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

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


Spinner control size

Edwin Dingjan -- dingjan@dds.nl
Wednesday, January 29, 1997

Environment : VC 4.2b + Windows 95

I have the following problem,

a spinner button in a view, no buddy stuff etc :

  hctrlSpinY = new CSpinButtonCtrl;
  hctrlSpinY->Create(WS_CHILD | WS_BORDER , 
                CRect(10,
                          20 ,
                          50,  
                          30,this, IDC_BLOCK_SPIN);


The third parameter in the rectangle, the rect.right, doesn't same to work.
What I have found, that if I change the spinner options with UDS_HORZ, it
works.
Also if the next command is MoveWindow, with the SAME rectangle, the
spinner button size is correct.
Is this a bug in MFC (I am allmost scared to say it mike) ?
Or am I doing something wrong ?

greetings

Edwin Dingjan    sm:-)e
dingjan@dds.nl
http://huizen.dds.nl/~dingjan
the Netherlands



Mike Blaszczak -- mikeblas@nwlink.com
Thursday, January 30, 1997

[Mini-digest: 2 responses]

At 08:09 1/29/97 +0100, Edwin Dingjan wrote:
>Environment : VC 4.2b + Windows 95

>I have the following problem,
>a spinner button in a view, no buddy stuff etc :
>
>  hctrlSpinY = new CSpinButtonCtrl;
>  hctrlSpinY->Create(WS_CHILD | WS_BORDER , 
>                CRect(10,
>                          20 ,
>                          50,  
>                          30,this, IDC_BLOCK_SPIN);

The code you provide won't compile.  You're missing a closing parenthesis.
You should use something more like this:

hctrlSpinY->Create(WS_CHILD | WS_BORDER, 
                CRect(10, 20, 50, 30), this, IDC_BLOCK_SPIN);

You might also want to provide WS_VISIBLE. Missing the visible flag won't
prevent your code from compiling, but it _will_ prevent you from seeing
the control you're trying to create.

>The third parameter in the rectangle, the rect.right, doesn't same to work.
>What I have found, that if I change the spinner options with UDS_HORZ, it
>works.

That seems to make sense to me: the coordinates you're providing describe
a control that is much wider than it is tall, and the Windows control
proably realizes that as it's working out the best way to draw itself.

Windows clamps the width of a UDS_VERT control, or the height of a 
UDS_HORZ control, to be less than or equal to the width of a scroll bar.
You can find the width of a scrollbar on your system by calling
the GetSystemMetrics() API.

>Also if the next command is MoveWindow, with the SAME rectangle, the
>spinner button size is correct.

That's one way to force the size to be whatever you want.  Windows only
clamps the size at the initial creation of the control.

> Or am I doing something wrong ?

Just because one doesn't understand a certain behaviour doesn't mean
a bug certainly exists. I really, really wish people would quit jumping
to that conclusion: it would free up a lot of time for me and my friends.
I could go to a hockey game each _week_ instead of just going once a year!

> Is this a bug in MFC (I am allmost scared to say it mike) ?

Perhaps you shouldn't be afraid of saying it, but you should be respectful
of the consequences of saying it.  You shouldn't be afraid to run down
the street screaming "FIRE!", but you should understand the consequences
of such an action.

If you'd traced through the MFC code involved here, you'd only watch
twenty or thirty statements go by.  Neglecting the hookproc, MFC does
very little when you create a window.  You can see that the numbers you
pass for your size and position are handed off directly to Windows, and it
is Windows that implements the up/down control, not MFC.  (I've said
this a dozen times on the list, you know: MFC doesn't _implement_ the
common controls--it just makes them more convenient for C++ programmers
to use.)

Maybe, even after that exercise, you'd still not understand why the control
isn't being created at the coordinates passed to Windows, but you'd at least
refrain from saying that MFC has a bug in this behaviour.  MFC isn't at all
involved in the behaviour you see!


.B ekiM
http://www.nwlink.com/~mikeblas/
These words are my own. I do not speak on behalf of Microsoft.
           This performance was not lip-synched.

-----From: Roma 

Edwin Dingjan wrote:
> 
> Environment : VC 4.2b + Windows 95
> 
> I have the following problem,
> 
> a spinner button in a view, no buddy stuff etc :
> 
>   hctrlSpinY = new CSpinButtonCtrl;
>   hctrlSpinY->Create(WS_CHILD | WS_BORDER ,
>                 CRect(10,
>                           20 ,
>                           50,
>                           30,this, IDC_BLOCK_SPIN);
> 
> The third parameter in the rectangle, the rect.right, doesn't same to work.
> What I have found, that if I change the spinner options with UDS_HORZ, it
> works.
> Also if the next command is MoveWindow, with the SAME rectangle, the
> spinner button size is correct.
> Is this a bug in MFC (I am allmost scared to say it mike) ?
> Or am I doing something wrong ?
  I don't know why rect parameter doesn't work, but I can say you that
this is not an MFC bug. CSpinButtonCtrl is just a transparent wrapper
for
the common *windows* control. The members of this class only send
messages to
the windows control.
So your question probably should look like this:

 Is this a bug in Windows (I am allmost scared to say it Bill) ?
 Or am I doing something wrong ?
 
> 
> greetings
> 
> Edwin Dingjan    sm:-)e
> dingjan@dds.nl
> http://huizen.dds.nl/~dingjan
> the Netherlands
Best regards,
-Roma




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