# Draw in C++ with wxRuby

**URL:** <https://www.ruby-forum.com/t/draw-in-c-with-wxruby/188740>\
**Category:** wxRuby\
**Created:** [May 17, 2010, 5:09pm UTC](https://www.ruby-forum.com/t/draw-in-c-with-wxruby/188740 "2010-05-17T17:09:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![emmanuel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3e96dc/32.png) [@emmanuel](https://www.ruby-forum.com/u/emmanuel)\
**Post date:** [May 17, 2010, 5:09pm UTC](https://www.ruby-forum.com/t/draw-in-c-with-wxruby/188740/1 "2010-05-17T17:09:36Z")

</div>

Hello,

I want to draw using C++ wxWdiget in some windows created using wxRuby.

Does anybody know if it is possible ?

I tried one thing which is maybe very naive … but it does not work :

1- I created a Frame using wxRuby  
2- i got the field wx\_id of this instance of Frame  
3- I tried to get the wxWindow in C++ using this id (using  
FindWindowById of the C++ api of wxWidget)

Any help will be very appreciated !

Emmanuel

---

<div class="post-metadata">

**Author:** ![emmanuel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3e96dc/32.png) [@emmanuel](https://www.ruby-forum.com/u/emmanuel)\
**Post date:** [May 17, 2010, 6:41pm UTC](https://www.ruby-forum.com/t/draw-in-c-with-wxruby/188740/2 "2010-05-17T18:41:24Z")

</div>

Does this work with, say, Canvas properly fitted into the frame?  
Actually drawing on the frame may not be as good as it looks.

Yours,  
Sergey

17.05.2010, × 19:09, Emmanuel E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) ÎÁÐÉÓÁÌ  
(Á):

---

<div class="post-metadata">

**Author:** ![emmanuel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3e96dc/32.png) [@emmanuel](https://www.ruby-forum.com/u/emmanuel)\
**Post date:** [May 17, 2010, 7:09pm UTC](https://www.ruby-forum.com/t/draw-in-c-with-wxruby/188740/3 "2010-05-17T19:09:03Z")

</div>

Sergey C. wrote:

> Does this work with, say, Canvas properly fitted into the frame?  
> Actually drawing on the frame may not be as good as it looks.
> 
> Yours,  
> Sergey
> 
> 17.05.2010, ï¿½ 19:09, Emmanuel E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½  
> (ï¿½):

NÃ´ i don t think you understood.  
In thÃ© example i give,  
FindWindowById retiens NULL!

Emmanuel

---

<div class="post-metadata">

**Author:** ![emmanuel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3e96dc/32.png) [@emmanuel](https://www.ruby-forum.com/u/emmanuel)\
**Post date:** [May 17, 2010, 10:37pm UTC](https://www.ruby-forum.com/t/draw-in-c-with-wxruby/188740/4 "2010-05-17T22:37:18Z")

</div>

I’d checked whether it happens with non-frame windows. Can’t check  
after migrating on snow leopard it just don’t work

Yours,  
Sergey

17.05.2010, Ð² 21:09, Emmanuel E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Ð½Ð°Ð¿Ð¸ÑÐ°Ð»(Ð°):

---

<div class="post-metadata">

**Author:** ![emmanuel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3e96dc/32.png) [@emmanuel](https://www.ruby-forum.com/u/emmanuel)\
**Post date:** [May 17, 2010, 11:44pm UTC](https://www.ruby-forum.com/t/draw-in-c-with-wxruby/188740/5 "2010-05-17T23:44:46Z")

</div>

Sergey C. wrote:

> I’d checked whether it happens with non-frame windows. Can’t check  
> after migrating on snow leopard it just don’t work
> 
> Yours,  
> Sergey
> 
> 17.05.2010, Ð² 21:09, Emmanuel E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> Ð½Ð°Ð¿Ð¸ÑÐ°Ð»(Ð°):

YOU DID NOT UNDERSTAND !?!

Whatever object is created using wxRuby, I want to be able to manipulate  
the corresponding wxWidget object in C++, how do I do that ?

---

<div class="post-metadata">

**Author:** ![emmanuel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3e96dc/32.png) [@emmanuel](https://www.ruby-forum.com/u/emmanuel)\
**Post date:** [May 18, 2010, 12:40am UTC](https://www.ruby-forum.com/t/draw-in-c-with-wxruby/188740/6 "2010-05-18T00:40:48Z")

</div>

it was clear since the beginning.

try get\_id() on your window, and if it fails

try to do it with the regular window - not frame - unless you have to.  
I’m used to get strange effects with frames sometimes.

good luck

18.05.2010, × 1:44, Emmanuel E. ÎÁÐÉÓÁÌ(Á):

> YOU DID NOT UNDERSTAND !?!
> 
> ## Whatever object is created using wxRuby, I want to be able to manipulate the corresponding wxWidget object in C++, how do I do that ?
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> wxruby-users mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [http://rubyforge.org/mailman/listinfo/wxruby-users](http://rubyforge.org/mailman/listinfo/wxruby-users)

Sergey C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![emmanuel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3e96dc/32.png) [@emmanuel](https://www.ruby-forum.com/u/emmanuel)\
**Post date:** [May 19, 2010, 1:42am UTC](https://www.ruby-forum.com/t/draw-in-c-with-wxruby/188740/7 "2010-05-19T01:42:32Z")

</div>

On 17/05/2010 16:09, Emmanuel E. wrote:

> I tried one thing which is maybe very naive … but it does not work :
> 
> 1- I created a Frame using wxRuby  
> 2- i got the field wx\_id of this instance of Frame  
> 3- I tried to get the wxWindow in C++ using this id (using  
> FindWindowById of the C++ api of wxWidget)

I don’t think this is naive - it looks like the right way to do this.  
The return value of wx\_id should simply be a ruby Fixnum representation  
of the C++ int.

You don’t say exactly what is going wrong here, but in your later  
messages you suggest that you’re getting NULL back in C++ when you try  
wxWindow::FindWindowById. Can you provide some more detail about how  
you’re passing the value from Ruby to your C++ library, and how you call  
FindWindowById in C++?

One test might be to find the object in C++ by GetChildren, inspecting  
its pointer address and comparing to what you have in Ruby - for  
debugging, you can access the C++ pointer address of a Wx::Window with  
the method ptr\_addr.

The advice to draw upon a Panel, rather than directly on a Frame, is  
sound and in line with standard Wx techniques.

PS - don’t SHOUT on this list. The support offered here works wholly on  
the basis of good-will.

alex

---

<div class="post-metadata">

**Author:** ![emmanuel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3e96dc/32.png) [@emmanuel](https://www.ruby-forum.com/u/emmanuel)\
**Post date:** [May 19, 2010, 8:01am UTC](https://www.ruby-forum.com/t/draw-in-c-with-wxruby/188740/8 "2010-05-19T08:01:51Z")

</div>

Alex F. wrote:

> On 17/05/2010 16:09, Emmanuel E. wrote:
> 
> > I tried one thing which is maybe very naive … but it does not work :
> > 
> > 1- I created a Frame using wxRuby  
> > 2- i got the field wx\_id of this instance of Frame  
> > 3- I tried to get the wxWindow in C++ using this id (using  
> > FindWindowById of the C++ api of wxWidget)
> 
> I don’t think this is naive - it looks like the right way to do this.  
> The return value of wx\_id should simply be a ruby Fixnum representation  
> of the C++ int.
> 
> You don’t say exactly what is going wrong here, but in your later  
> messages you suggest that you’re getting NULL back in C++ when you try  
> wxWindow::FindWindowById. Can you provide some more detail about how  
> you’re passing the value from Ruby to your C++ library, and how you call  
> FindWindowById in C++?
> 
> One test might be to find the object in C++ by GetChildren, inspecting  
> its pointer address and comparing to what you have in Ruby - for  
> debugging, you can access the C++ pointer address of a Wx::Window with  
> the method ptr\_addr.
> 
> The advice to draw upon a Panel, rather than directly on a Frame, is  
> sound and in line with standard Wx techniques.
> 
> PS - don’t SHOUT on this list. The support offered here works wholly on  
> the basis of good-will.
> 
> alex

Hello,

first… sorry for “shouting” .. I should not have…🙂  
And it is indeed very nice of both of you to take time trying to help  
me.  
I really appreciate!

Yes, The problem was not that I could not draw in the window but that  
FindWindowById returned NULL.  
… now I just solved it (yes!) … I was not properly linking my C++  
code to build the dynamic library..

It is all working now …

Thank you very much (and sorry!) again

Emmanuel
