1. Default attributes in new Win32lib

Hi Derek,

I still did not find out why you generally changed WS_CHILD to
WS_CLIPPINGCHILD (WS_CHILD + WS_CLIPSIBLINGS) for all the controls. The
following code will not work correctly for me.(Win95/Win98) The picture
is from Winlib's DemoRecources folder. What would be wrong with the
commented statements, which should indicate the default attributes
according to Win32lib's documentation?

Regards,
Roland


--  code generated by Win32Lib IDE

include Win32Lib.ew
without warning

--  Window Win
constant Win = createEx( Window, "Window1", 0, 50, 50, 400, 300, 0, 0 )
constant BM = createEx( Bitmap, "Bitmap2", Win, 68, 44, 260, 172, 0, 0 )
setBitmap( BM,"largetiles.bmp")
constant Edit = createEx( EditText, "Hello World", Win,4,156,144,32,0,0)
--constant Edit = createEx( EditText, "Hello World", Win,4,156,144,32,
-- {WS_CHILD, WS_VISIBLE,ES_AUTOHSCROLL,ES_LEFT,WS_BORDER,WS_TABSTOP},0)
setHint( Edit,"This is an EditText")
setFont( Edit,"Arial",12,Normal+Bold)
setBitmap( Edit,"largetiles.bmp")
constant PB = createEx( PushButton, "Exit", Win,268, 64, 104, 36, 0, 0 )
--constant PB = createEx( PushButton, "Exit", Win, 268, 64, 104, 36,
--  {WS_CHILD,WS_VISIBLE,BS_PUSHBUTTON,WS_TABSTOP}, 0 )
setFont( PB,"Arial",12,Normal+Bold)

procedure Win_onAfterEvent (integer self, integer event, sequence params)
sequence result
   setPenWidth(Win,3)
   drawLine(Win, 10,10,390,260)
   setFont(Win, "Arial", 10, Bold+Italic)
   result=drawText(Win,"Fourscore and twenty years ago, our fathers,...",
            {5,50, 140, 120}, DT_WORDBREAK, 4, 0, 0)
end procedure
setHandler( Win, w32HAfterEvent, routine_id("Win_onAfterEvent"))

procedure PB_onClick (integer self, integer event, sequence params)
      closeWindow(Win)
end procedure
setHandler( PB, w32HClick, routine_id("PB_onClick"))

WinMain( Win,Normal )

new topic     » topic index » view message » categorize

2. Re: Default attributes in new Win32lib

R.Stowasser wrote:
> 
> Hi Derek,
> 
> I still did not find out why you generally changed WS_CHILD to
> WS_CLIPPINGCHILD (WS_CHILD + WS_CLIPSIBLINGS) for all the controls. The
> following code will not work correctly for me.(Win95/Win98) The picture
> is from Winlib's DemoRecources folder. What would be wrong with the
> commented statements, which should indicate the default attributes
> according to Win32lib's documentation?

I'm sure there a very good explanation for this Roland; I just 
can't think of it right now. It is on my plans to review this way
of operating but it hasn't hit the top of the priority list yet.

I'm currently finished working on the next release, but I could check 
this out over the next day or so.

-- 
Derek Parnell
Melbourne, Australia

new topic     » goto parent     » topic index » view message » categorize

3. Re: Default attributes in new Win32lib

R.Stowasser wrote:
> 
> Hi Derek,
> 
> I still did not find out why you generally changed WS_CHILD to
> WS_CLIPPINGCHILD (WS_CHILD + WS_CLIPSIBLINGS) for all the controls. The
> following code will not work correctly for me.(Win95/Win98) The picture
> is from Winlib's DemoRecources folder. What would be wrong with the
> commented statements, which should indicate the default attributes
> according to Win32lib's documentation?

Ok, you got me there. The docs are wrong. Sorry.

Here is the longer explanation...

The graphics model I'm working from is that each control is on its own
layer. This doesn't impact anything until controls overlap.  The 
bottom layer is the parent Window. All its child controls have layers
which are above the parent, meaning that when a child control overlaps
the parent window (a very normal thing), you get to see the child
control and not the portion of the parent that is overlapped. 

Now when you get child controls of the same parent (i.e. siblings) that
overlap, one will obscure a portion of the other, depending on the
relative 'height' of the layers they own. The higher one is seen and
the lower one is obscured. 

The height of a control's layer is first determined by the order that you
create the child controls in. The first child control is the highest layer
and subsequent child controls are on progressively lower layers.

You can alter the relative height of layers by using the moveZOrder()
routine. 

Each control, including the parent window, has canvas on which pixels are
drawn. All pixels drawn on a canvas share the same layer as the owning
control. This means that if one draws pixels onto a canvas that is 
on a lower layer than an overlapping control, the pixels in the overlapped
area will be obscured.
 
> --  code generated by Win32Lib IDE
> 
> include Win32Lib.ew
> without warning
> 
> --  Window Win
> constant Win = createEx( Window, "Window1", 0, 50, 50, 400, 300, 0, 0 )
> constant BM = createEx( Bitmap, "Bitmap2", Win, 68, 44, 260, 172, 0, 0 )
> setBitmap( BM,"largetiles.bmp")
> constant Edit = createEx( EditText, "Hello World", Win,4,156,144,32,0,0)
> --constant Edit = createEx( EditText, "Hello World", Win,4,156,144,32,
> -- {WS_CHILD, WS_VISIBLE,ES_AUTOHSCROLL,ES_LEFT,WS_BORDER,WS_TABSTOP},0)
> setHint( Edit,"This is an EditText")
> setFont( Edit,"Arial",12,Normal+Bold)
> setBitmap( Edit,"largetiles.bmp")
> constant PB = createEx( PushButton, "Exit", Win,268, 64, 104, 36, 0, 0 )
> --constant PB = createEx( PushButton, "Exit", Win, 268, 64, 104, 36,
> --  {WS_CHILD,WS_VISIBLE,BS_PUSHBUTTON,WS_TABSTOP}, 0 )
> setFont( PB,"Arial",12,Normal+Bold)
> 
> procedure Win_onAfterEvent (integer self, integer event, sequence params)
> sequence result
>    setPenWidth(Win,3)
>    drawLine(Win, 10,10,390,260)
>    setFont(Win, "Arial", 10, Bold+Italic)
>    result=drawText(Win,"Fourscore and twenty years ago, our fathers,...",
>             {5,50, 140, 120}, DT_WORDBREAK, 4, 0, 0)
> end procedure
> setHandler( Win, w32HAfterEvent, routine_id("Win_onAfterEvent"))
> 
> procedure PB_onClick (integer self, integer event, sequence params)
>       closeWindow(Win)
> end procedure
> setHandler( PB, w32HClick, routine_id("PB_onClick"))
> 
> WinMain( Win,Normal )

To get the effect you are (I think) trying for you can either create the
bitmap control last, so it appears on the bottom of the child control
layers, or use the moveZOrder() routine to place it on the bottom.

Also, (re)drawing pixels after *every* event is not a recommended way of
doing stuff. Try using just the w32HPaint event instead.

Now if my model needs improvement, I'm happy to consider any changes that
people may suggest. I'm wide open to improvements.

-- 
Derek Parnell
Melbourne, Australia

new topic     » goto parent     » topic index » view message » categorize

4. Re: Default attributes in new Win32lib

Hi Derek,

thank you for the explanations why using WS_CLIPSIBLINGS as a default 
style in Win32lib. They were very helpful for me and I have adapted my 
code so that it will work now as expected.
There is one question which came up. Should repaintWindow() not have the 
same effect in this case as the w32HPaint event?

Regards,
Roland


--  code generated by Win32Lib IDE

include Win32Lib.ew
without warning

--  Window Win
constant Win = createEx( Window, "Window1", 0, 50, 50, 400, 300, 0, 0 )
constant BM = createEx( Bitmap, "Bitmap2", Win, 68, 44, 260, 172, 0, 0 )
setBitmap( BM,"largetiles.bmp")
constant Edit = createEx( EditText, "Hello World",Win,4,156,144,32,0,0)
setHint( Edit,"This is an EditText")
setFont( Edit,"Arial",12,Normal+Bold)
setBitmap( Edit,"largetiles.bmp")
constant PB = createEx( PushButton, "Exit",Win, 268, 64, 104, 36, 0, 0 )
setFont( PB,"Arial",12,Normal+Bold)

procedure Win_onPaint (integer self, integer event, sequence params)
sequence result
   setPenWidth(Win,3)
   drawLine(Win, 10,10,390,260)
   setFont(Win, "Arial", 10, Bold+Italic)
   result=drawText(Win,"Fourscore and twenty years ago, our fathers, ..",
           {5,50, 140, 120}, DT_WORDBREAK, 4, 0, 0)
end procedure
setHandler( Win, w32HPaint, routine_id("Win_onPaint"))

procedure Win_onActivate (integer self, integer event, sequence params)
integer msg
   moveZOrder(BM,HWND_BOTTOM)
   msg = invokeHandler(Win, w32HPaint, {} )
--  repaintWindow(Win)
end procedure
setHandler( Win, w32HActivate, routine_id("Win_onActivate"))

procedure PB_onClick (integer self, integer event, sequence params)
   closeWindow(Win)
end procedure
setHandler( PB, w32HClick, routine_id("PB_onClick"))

WinMain( Win,Normal )

new topic     » goto parent     » topic index » view message » categorize

5. Re: Default attributes in new Win32lib

R.Stowasser wrote:
> 
> Hi Derek,
> 
> thank you for the explanations why using WS_CLIPSIBLINGS as a default 
> style in Win32lib. They were very helpful for me and I have adapted my 
> code so that it will work now as expected.
> There is one question which came up. Should repaintWindow() not have the 
> same effect in this case as the w32HPaint event?

Not really. The handler for w32HPaint is designed to be called during a
Windows Paint operation. This means that it expects that a device context
will be already established for the control AND that DC will already have
clipping regions defined in it for the siblings. Windows does this
automatically for the programmer just before sending a WM_PAINT message
to the application. This means that any drawing that happens during the
paint operation, will be clipped so it doesn't interfere with other
controls.

If you call the w32Handler directly (e.g. invokeHandler(...)) without first
setting up the appropriate device context, any drawing you do in that
handler may overwrite pixels already drawn by other controls - that is, 
they are not clipped.

To set up the device context for this is not a trival exercise. It is more
involved that just getting the default DC for the control. You need to
add clipping regions to avoid drawing on any overlapping controls. 

The repaintWindow() routine just informs Windows that the control needs
to be repainted, so Windows then constructs the right DC and sends a
WM_PAINT message to the application.


So in your example, don't call the event handler directly. Also you
don't need the call to repaintWindow() as it is done automatically
the first time the window is displayed. 

-- 
Derek Parnell
Melbourne, Australia

new topic     » goto parent     » topic index » view message » categorize

6. Re: Default attributes in new Win32lib

Derek Parnell wrote:

 > So in your example, don't call the event handler directly. Also you
 > don't need the call to repaintWindow() as it is done automatically
 > the first time the window is displayed.
 >
 > -- Derek Parnell Melbourne, Australia



I have revised my example code once again. It has become very compact
now. Thanks again for the help Derek.

Regards,
Roland


--  code generated by Win32Lib IDE

include Win32Lib.ew
without warning

--  Window Win
constant Win = createEx( Window, "Window1", 0, 50, 50, 400, 300, 0, 0 )
constant BM = createEx( Bitmap, "Bitmap2", Win, 68, 44, 260, 172, 0, 0 )
setBitmap( BM,"largetiles.bmp")
constant Edit = createEx( EditText,"Hello World",Win,4,156,144,32,0,0 )
setHint( Edit,"This is an EditText")
setFont( Edit,"Arial",12,Normal+Bold)
setBitmap( Edit,"largetiles.bmp")
constant PB = createEx( PushButton, "Exit",Win, 268, 64, 104, 36, 0, 0 )
setFont( PB,"Arial",12,Normal+Bold)

procedure Win_onActivate (integer self, integer event, sequence params)
sequence result
    moveZOrder(BM,HWND_BOTTOM)
    setPenWidth(Win,3)
    drawLine(Win, 10,10,390,260)
    setFont(Win, "Arial", 10, Bold+Italic)
    result=drawText(Win,"Fourscore and twenty years ago, our fathers,...",
            {5,50, 140, 120}, DT_WORDBREAK, 4, 0, 0)
end procedure
setHandler( Win, w32HActivate, routine_id("Win_onActivate"))

procedure PB_onClick (integer self, integer event, sequence params)
    closeWindow(Win)
end procedure
setHandler( PB, w32HClick, routine_id("PB_onClick"))

WinMain( Win,Normal )

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu