# wxRuby: MemoryDC problems

**URL:** <https://www.ruby-forum.com/t/wxruby-memorydc-problems/116287>\
**Category:** Ruby\
**Created:** [October 4, 2007, 5:40am UTC](https://www.ruby-forum.com/t/wxruby-memorydc-problems/116287 "2007-10-04T05:40:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jay\_McGavren](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e79b87/32.png) [@Jay\_McGavren](https://www.ruby-forum.com/u/Jay_McGavren)\
**Post date:** [October 4, 2007, 5:40am UTC](https://www.ruby-forum.com/t/wxruby-memorydc-problems/116287/1 "2007-10-04T05:40:44Z")

</div>

I’m trying to put together a quick test of buffered animation with  
WxRuby, but I’m encountering a fair amount of trouble… I’m drawing  
to a Wx::Bitmap first, then using Wx::DC#draw\_bitmap to copy it to a  
Wx::Window. But I get the following error:

C:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.1-i386-mswin32/lib/wx/  
classes/bitmap.rb:18:in `draw': uninitialized constant Wxruby2::Bitmap::MemoryDC (NameError) from dc_draw_line.rb:30:in`on\_init’  
…

Is MemoryDC not implemented yet in WxRuby 1.9.1? It’s in the  
documentation, but I know large chunks of that are auto-generated, so  
I don’t totally trust it. Maybe I’m doing something wrong, though?

My code is below. Any advice would be most appreciated!

-Jay

gems\_loaded = false  
begin  
require ‘wx’  
rescue LoadError  
if gems\_loaded == false  
require ‘rubygems’  
gems\_loaded = true  
retry  
else  
raise  
end  
end

class MyApp \< Wx::App  
def on\_init  
#Create the top window.  
frame = Wx::Frame.new(nil, :size =\> [300, 300])  
#Create a panel within it.  
view = Wx::Window.new(frame)

```
    buffer = Wx::Bitmap.new(300, 300)

    @x = 0

#Set up a handler for paint events.
view.evt_paint do |event|
  #Wx::Window#paint takes a block.
  #This will later be called with a device context to paint on.
  view.paint do |dc|
    buffer.draw do |buffer_dc|
      buffer_dc.clear
      buffer_dc.pen = Wx::Pen.new(Wx::Colour.new(128, 128, 128), 5)
      buffer_dc.draw_line(@x, 0, @x + 100, 100)
    end
    dc.draw_bitmap(buffer, 0, 0, false)
  end
  @x += 1
end
#Show the window.
frame.show
return true

```

end  
end

app = MyApp.new

app.main\_loop
