# Device context (get\_dc) Question from printing.rb in wxRuby samples

**URL:** <https://www.ruby-forum.com/t/device-context-get-dc-question-from-printing-rb-in-wxruby-samples/206740>\
**Category:** wxRuby\
**Created:** [May 9, 2011, 2:38am UTC](https://www.ruby-forum.com/t/device-context-get-dc-question-from-printing-rb-in-wxruby-samples/206740 "2011-05-09T02:38:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [May 9, 2011, 2:38am UTC](https://www.ruby-forum.com/t/device-context-get-dc-question-from-printing-rb-in-wxruby-samples/206740/1 "2011-05-09T02:38:46Z")

</div>

I am using Windows XP SP 3 but want to stay general.

Below is a method within printing.rb. I have added comments marked by  
#–.  
My question is about get\_dc. The device context is obviously created  
and  
the code works as presented.  
It also works as documented below. Why does just get\_dc satisfy the  
linkage?  
When does one use the Wx:: or the Wx::PrintOut format? How does one  
decide  
to use just the short form?

Where could I have found this answer?

`
def on_print_page(page)
    dc = get_dc #-- don;'t understand where get_dc comes from
                                   #--Wx::get_dc works
                                   #-- Wx::PrintOut.get_dc also works
                                   #--PrintOut.get_dc also works
                                   #-- looks like just get_dc is ok, why 
and
when
                                   #-- the variable dc is probably a 
class
or module but
                                   #-- where do I find its definition?
```
if dc
    if page == 1
        draw_page_one(dc) ##-- dc = device context passed in
    elsif (page == 2)
        draw_page_two(dc) ##-- dc = device context passed in
    end
    dc.set_device_origin(0, 0)
    dc.set_user_scale(1.0, 1.0)

    buf = "PAGE #{page}"
    dc.draw_text(buf, 10, 10)

    return true
else
    return false
end

```
end #–end of on_print_page`

---

<div class="post-metadata">

**Author:** ![ann\_m](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e8cbc/32.png) [@ann\_m](https://www.ruby-forum.com/u/ann_m)\
**Post date:** [May 11, 2011, 1:41am UTC](https://www.ruby-forum.com/t/device-context-get-dc-question-from-printing-rb-in-wxruby-samples/206740/2 "2011-05-11T01:41:54Z")

</div>

It has a lot to do with scope.

On 09/05/2011 10:38 AM, “Ann M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

I am using Windows XP SP 3 but want to stay general.

Below is a method within printing.rb. I have added comments marked by  
#–.  
My question is about get\_dc. The device context is obviously created  
and  
the code works as presented.  
It also works as documented below. Why does just get\_dc satisfy the  
linkage?  
When does one use the Wx:: or the Wx::PrintOut format? How does one  
decide  
to use just the short form?

Where could I have found this answer?

`
def on_print_page(page)
    dc = get_dc #-- don;'t understand where get_dc comes from
                                   #--Wx::get_dc works
                                   #-- Wx::PrintOut.get_dc also works
                                   #--PrintOut.get_dc also works
                                   #-- looks like just get_dc is ok, why 
and
when
                                   #-- the variable dc is probably a 
class
or module but
                                   #-- where do I find its definition?
```
if dc
    if page == 1
        draw_page_one(dc) ##-- dc = device context passed in
    elsif (page == 2)
        draw_page_two(dc) ##-- dc = device context passed in
    end
    dc.set_device_origin(0, 0)
    dc.set_user_scale(1.0, 1.0)

    buf = "PAGE #{page}"
    dc.draw_text(buf, 10, 10)

    return true
else
    return false
end

```
end #–end of on_print_page
–
Ann M.
removed_email_address@domain.invalid`

---

<div class="post-metadata">

**Author:** ![ann\_m](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e8cbc/32.png) [@ann\_m](https://www.ruby-forum.com/u/ann_m)\
**Post date:** [May 15, 2011, 11:15pm UTC](https://www.ruby-forum.com/t/device-context-get-dc-question-from-printing-rb-in-wxruby-samples/206740/3 "2011-05-15T23:15:54Z")

</div>

On 09/05/11 00:59, Ann M. wrote:

> Below is a method within printing.rb. I have added comments marked  
> by #–.  
> My question is about get\_dc. The device context is obviously created  
> and the code works as presented.  
> It also works as documented below. Why does just get\_dc satisfy the  
> linkage?  
> When does one use the Wx:: or the Wx::PrintOut format? How does one  
> decide to use just the short form?

get\_dc is an instance method of Wx::Printout, and in the sample, it’s  
called from within a class that inherits from that.

> Where could I have found this answer?

[http://wxruby.rubyforge.org/doc/printout.html#Printout\_getdc](http://wxruby.rubyforge.org/doc/printout.html#Printout_getdc)

> ```
> #-- where do I find its definition?
> 
> ```

I don’t think PrintOut.get\_dc or Wx::get\_dc will work? There are no such  
class/module methods in either Wx::Printout or the global Wx:: module.

alex
