Re: was wondering...

new topic     » goto parent     » topic index » view thread      » older message » newer message

Monty wrote:

>I am having a hard time understanding how to use this constant.  It =
bears
>some resemblance to how the constants are used in the win32lib, which I
>can't quite understand either.=20

Regarding the Win32Lib constant, it's a 'handle', along the same lines =
of a file handle - something that lets Win32Lib know what object you are =
referring to in your function. By analogy:

   puts( "hi there" )

doesn't have enough information to display, because Euphoria needs to =
know what device is being referred to. You need to include the specific =
device:

   puts( Screen, "hi there" )

In the same way:

   wPuts( "hi there" )

doesn't have enough information, because it doesn't know what window or =
control to write to. You need to include the handle:

   wPuts( MyWindow, "hi there" )

In "real" Win32 calls, the handle is something called a "device =
context". "hDC" is shorthand for "handle to the device context". From =
the Win32 help file:

"A device context is a structure that defines a set of graphic objects =
and their associated attributes, and the graphic modes that affect =
output. The graphic objects include a pen for line drawing, a brush for =
painting and filling, a bitmap for copying or scrolling parts of the =
screen, a palette for defining the set of available colors, a region for =
clipping and other operations, and a path for painting and drawing =
operations."

In short, a device context contains all the information Win32 needs to =
know about how to write to something: what object is being referred to, =
it's current font, it's text color, it's pen thickness, it's drawing =
mode, and so forth.

Working with a DC is a bit complex. Like a file, it needs to be opened =
before you can use it, and closed when you are done with it. When you =
close a DC, it "forgets" it's prior settings. There *is* an option for =
having a DC remember it's settings after closure, but at an additional =
overhead of about 800K per window.

In any event, Win32Lib attempts to shield you from this, by letting you =
pass it's own window handle instead. The value for Win32Lib's handles is =
just an index to an internal data structure that it maintains with =
information about the type of window, the attributes, and so on. So the =
first handle value that Win32Lib will return is 1, the second is 2, and =
so forth.

Internally, Win32Lib converts the handle into a DC by looking it up. The =
value was stored in the window_handle structure when the window (or =
control) was created:

   global function getHandle( integer iWin )
      return window_handle[ iWin ]
   end function

For some reason (probably because it's "fuzzy headed" Tuesday) I'm a bit =
unclear on when exactly a hDC needs to be released, so I won't go into =
further details and make a total fool of myself. In the =
soon-to-be-released next version of Win32Lib, I've gotten rid of the =
persistant text and graphics, so things are a bit more complex. I used =
to defer everything into the WM_PAINT event. Now, everything is done "on =
demand", and is a bit more complex to optimize.

-- David Cuny

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu