April 20, 2024, 02:54:59 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


GDI DC Width and Height

Started by definitelyokay, June 03, 2010, 10:29:21 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

definitelyokay

June 03, 2010, 10:29:21 AM Last Edit: June 03, 2010, 10:44:50 AM by JosephE
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

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
' ------------------------------------------------------ '

LarryMc

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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

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

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

definitelyokay

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.

LarryMc

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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

definitelyokay

Wow. I read that like 5 times and still didn't notice that ::)...thanks! :)

LarryMc

It gets worse as you get older. trust me. I know! ;)

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library