Re: tiny little question about win32lib

new topic     » goto parent     » topic index » view thread      » older message » newer message
jessedavis said...

Yes, your fix works well. redrawing is certainly an answer; however, I do not understand what Windows is doing.

This isn't a fix. This is the answer.

jessedavis said...

Anytime something is moved the entire screen needs to be repainted. w32hpaint is never fired unless a portion of the app window (win) goes off screen and then only if moved back on the screen. As the window moves back onto the screen multiple w32Paint events are triggered, Each time a narrow band of the window is redrawn (added to the complete image). I assume that Windows silently repainting the entire screen as the screen buffer is updated. w32Paint is reconstructing the screen buffer a narrow band at the time as the app window moves back onto the screen - Windows then updates the entire screen every time the buffer changes..

Windows expects your application to know what it's doing when painting the window. Windows will not try to predict what you want to do. Most of the time you won't want Windows trying to perform these actions for you. So all Windows is going to do is tell you when and where to repaint. It will not hold a buffer for you. It will not redraw what you previously asked it to draw. This is the way the Win32 API is designed, so this is how your application should behave.

The correct solution is to use a buffer bitmap to hold your graphics and then copy that to the window whenever a repaint event is triggered. I've updated your example below.

--  code generated by Win32Lib IDE v1.0.4 Build July-06-2008 
constant TheProgramType="exw"  
include Win32lib.ew 
without warning 
constant win = createEx( Window, "DEMONSTRATION WINDOW", 0, Default, Default, 474, 326, 0, 0 ) 
constant pb_2 = createEx( PushButton, "QUIT", win, 20, 232, 124, 28, 0, 0 ) 
setFont( pb_2,"Arial",14,Normal+Bold) 
constant pb_1 = createEx( PushButton, "generate", win, 268, 232, 124, 28, 0, 0 ) 
setFont( pb_1,"Arial",14,Normal+Bold) 
integer buffer = 0 
-- copy the buffer to the screen 
procedure redrawBuffer() 
    if buffer then 
        copyBlt( win, 0, 0, buffer ) 
    end if 
end procedure 
-- create a new buffer of the correct size 
procedure updateBuffer( integer width, integer height ) 
    if buffer then 
        destroy( buffer ) 
    end if 
    buffer = createEx( Pixmap, "", win, 0, 0, width, height, 0, 0 ) 
    setFont (buffer, "Consolas",12,Normal) 
    wPuts({buffer,15,20},"Hello to the world, yet Again!") 
    wPuts({buffer,15,40},"Now that text is on screen grab Window") 
    wPuts({buffer,15,55},"Top bar & Move it so part of text") 
    wPuts({buffer,15,70},"Leaves the monitor (off the edge)") 
    wPuts({buffer,15,85},"Now, move it back to starting position.") 
    wPuts({buffer,15,120},"Notice vanishing text AND unaffected control...") 
end procedure 
procedure pb_2_onClick (integer self, integer event, sequence params) 
end procedure 
setHandler( pb_2, w32HClick, routine_id("pb_2_onClick")) 
procedure pb_1_onClick (integer self, integer event, sequence params) 
    sequence size = getClientSize( win ) 
    -- manually update the buffer 
    updateBuffer( size[3], size[4]-100 ) 
end procedure 
setHandler( pb_1, w32HClick, routine_id("pb_1_onClick")) 
procedure win_onPaint (integer self, integer event, sequence params) 
end procedure 
setHandler( win, w32HPaint, routine_id("win_onPaint")) 
procedure win_onResize (integer self, integer event, sequence params) 
    -- move the buttons around to keep them out of the text 
    setRect( pb_1, 20, params[3]-48, 124, 28, w32True ) 
    setRect( pb_2, params[2]-168, params[3]-48, 124, 28, w32True ) 
    -- update the buffer to the new window size 
    updateBuffer( params[2], params[3]-100 ) 
end procedure 
setHandler( win, w32HResize, routine_id("win_onResize")) 
WinMain( win,Normal ) 


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


Quick Links

User menu

Not signed in.

Misc Menu