IonicWind Software

IWBasic => Games and Graphics => Topic started by: definitelyokay on June 03, 2010, 10:29:21 AM

Title: GDI DC Width and Height
Post by: definitelyokay on June 03, 2010, 10:29:21 AM
I need to find the width an height to my device context.

Here's a link I was following...http://www.codeguru.com/forum/archive/index.php/t-119164.html (http://www.codeguru.com/forum/archive/index.php/t-119164.html)

Edit. This works :)


' Make a new device context exactly like the one given to us:
' (we need it to do our drawing operations in memory)
DC = _CreateCompatibleDC(TargetDC)

' Figure out the width and height of this thing:
int hBmp = _GetCurrentObject(TargetDC, OBJ_BITMAP)
BITMAP bmp
_GetObject(hBmp, Len(bmp), bmp)
Width = bmp.bmWidth
Height = bmp.bmHeight
' ------------------------------------------------------ '
Title: Re: GDI DC Width and Height
Post by: LarryMc on June 03, 2010, 10:49:27 AM
Quote from: JosephE on June 03, 2010, 10:29:21 AM
However, eb doesn't seem to have a & operator for referencing a variable's address.
yes it does and I use it all the time

Quote from: JosephE on June 03, 2010, 10:29:21 AM

_GetObject(hBmp, & bmp, Len(bmp))


Proper usage would be
&bmpand not
& bmp

LarryMc
Title: Re: GDI DC Width and Height
Post by: LarryMc on June 03, 2010, 11:06:09 AM
I looked up the GETOBJ function and saw you had your parameter order wrong.

After you got the parameter order correct it worked without a &.

That's because bmp is a UDT structure(BITMAP) and IWB passes strings and UDTs byref (address) by default.

Numeric variables are passed by value by default but there are times when you need to pass them byref so you prepend the &.

I personally do that with numeric values like passing a rgb composite color and also pass &r,&g,&b so I get the 3 individual colors back from a subrotine.

LarryMc

Title: Re: GDI DC Width and Height
Post by: definitelyokay on June 03, 2010, 12:10:26 PM
Thank you larry! I'm glad to find that out! :)

Very useful to know since I'm embarking on a new EB project right now. I swear I couldn't find the & address operator in the manual, except when passing the address of a sub.
Title: Re: GDI DC Width and Height
Post by: LarryMc on June 03, 2010, 12:16:47 PM
It's kind of obscure. ;)
From the Languages/Operators section of the help file:

QuoteSome symbols are reused for other purposes depending on the context of the operator. For example the & symbol is used as the bit wise AND operator and also as the Address Of operator

LarryMc
Title: Re: GDI DC Width and Height
Post by: definitelyokay on June 03, 2010, 12:30:53 PM
Wow. I read that like 5 times and still didn't notice that ::)...thanks! :)
Title: Re: GDI DC Width and Height
Post by: LarryMc on June 03, 2010, 01:00:28 PM
It gets worse as you get older. trust me. I know! ;)

LarryMc