From: Lyle Johnson Date: 2003-01-15T02:14:55+09:00 Subject: Re: FXRuby problem on Windows Daniel P. Zepeda wrote: > I've cut down a larger program to this test case that shows a problem on > windows. When I run this on my Linux box, I get an application window with > some colored boxes and the string "Hi There, (I'm on my way, I'm making > it) in it. When I run this same program on my Windows box, I get Zip, > nada, at first a gray window, then a transparent one if I minimize > thenmaximize the window. Some debugging statements show that onPaint *is* > getting called. Can anyone tell me what the problem is here? I haven't had a chance to look at this under Windows yet, but I think I see what's wrong; you need to call FXDC#end to "flush" out the drawing commands that you're making. The fact that it *happens* to work under Linux is just a coincidence. Device contexts (i.e. FXDCWindow instances) are just supposed to be temporary objects, not things that you hang on to for the life of a program. They are most often constructed and torn down within a SEL_PAINT handler, although there are some other times you might need to use them (for some examples, see the scribble.rb example program). As an illustration (no pun intended), I'd recommend restructuring the test case as follows. First, move the code for setting up the screen device context (@sdc) into the SEL_PAINT handler for the canvas widget: def onPaint( sender, sel, event ) sdc = FXDCWindow.new( @canvas ) sdc.drawImage( @image, 0,0 ) sdc.end end Note that sdc doesn't need to be (and probably shouldn't be) an instance variable, it's just a local. Also note the call to FXDCWindow#end after the drawing is complete. Next, I'd move the code related to drawing the image out into a separate routine: def setupImage @image.resize( @canvas.width, @canvas.height ) idc = FXDCWindow.new( @image ) idc.setForeground( FXColor::White ) idc.fillRectangle( 0,0, @canvas.width, @canvas.height ) step = 5 0.step(50, step ) { |y| 0.step(50, step ) { |x| idc.setForeground(FXRGB( rand(255), rand(255), rand(255))) idc.fillRectangle( x,y, x+@canvas.height, y+@canvas.width ) } } idc.fillRectangle( 50,50, @canvas.width, @canvas.height ) idc.setForeground(FXColor::Black) idc.setTextFont( @font ) idc.drawText( 60,80, "Hi There, (I'm on my way I'm making it!)") idc.end end As with onPaint(), the device context (idc) is now just a local variable. I also replaced the instance variables @canvasWidth and @canvasHeight with direct calls to the canvas for its width and height, but that's less important. After these changes, the create() method is much simpler: def create super @font.create @image.create setupImage show(PLACEMENT_SCREEN) end As I said, I haven't tried it out on Windows yet, but I think the added calls to FXDC#end will probably take care of the problem you were seeing. If not, let me know and I'll take a closer look. Hope this helps, Lyle