Jump to content

.net things I want to do in C++

- - - - -

  • Please log in to reply
5 replies to this topic

#1
Axel

Axel

    Newbie

  • Members
  • PipPip
  • 27 posts
I want to do these things(they are GDI+ , but I wouldn't mind using GTK+, I'm using the wxwidgets library already which takes extremely much space) in C++

Graphics g = Graphics.FromHwnd(handle);

g.DrawString(.....);
I want this way for linux too :)

#2
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
GTK+ does this using either Cairo or Pango. With Pango it's probably simpler, but Cairo has more drawing flexibility (I'm using cairomm in a C++ project right now). wxWidgets uses what is known as a wxPaintDC (Paint Device Context) within the OnPaint() method of a wxWindow to perform drawing operations. To perform an identical task to what you have, do this in wxWidgets:
void MyObject::OnPaint(wxPaintEvent e)
{
  wxPaintDC dc;
  wxString str(wxT("Some String"));
  dc.DrawText(str, 10, 10); // Some random coordinates.
  render(dc);
}
At least that's how I think it works in wxWidgets... didn't test it just read the docs. O_o

In gtkmm (the GTK+ made for C++), you'd create a Cairo::Context object from the Gtk::Widget you want to draw on.
Cairo::RefPtr<Cairo::Context> context = myWidget->get_window()->create_cairo_context();
std::string str("Some String");
context->show_text(str);
That should do it, and if you want to move or change color you have to modify the Cairo::Context. Also, I advise if you can simply do what you're trying to do with a wxStaticText or Gtk::Label than I suggest that course of action first.

Wow I changed my sig!

#3
Axel

Axel

    Newbie

  • Members
  • PipPip
  • 27 posts
Well but how would I paint on a window ? (Graphics.FromHwnd(); )

#4
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
What I showed you does paint on the window. You can use a Cairo::Context or a wxPaintDC to perform most the other painting operations that a .NET System.Drawing.Graphics object can do. I'm not sure what .NET is supposed to be doing differently, is there something specific you'd like help on drawing?
Wow I changed my sig!

#5
Axel

Axel

    Newbie

  • Members
  • PipPip
  • 27 posts
No I wanted to draw on a window that isn't mine that I got by FindWindow or whatever

#6
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts

Axel said:

No I wanted to draw on a window that isn't mine

Hmm, I don't think that most any of these API's were designed for that. Even doing so with the Windows API sounds, at least to me, pretty sketchy. Why would you need to draw on a window that isn't part of your application? It's inherently difficult to make any assumptions about a user's computer, especially what programs they happen to be running at the time.

This forces me to ask the question, what are you actually trying to do?

Wow I changed my sig!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users