Graphics g = Graphics.FromHwnd(handle); g.DrawString(.....);I want this way for linux too :)
5 replies to this topic
#1
Posted 27 July 2011 - 01:48 PM
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++
|
|
|
#2
Posted 27 July 2011 - 05:39 PM
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:
In gtkmm (the GTK+ made for C++), you'd create a Cairo::Context object from the Gtk::Widget you want to draw on.
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_oIn 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
Posted 28 July 2011 - 01:20 AM
Well but how would I paint on a window ? (Graphics.FromHwnd(); )
#4
Posted 01 August 2011 - 02:26 PM
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
Posted 01 August 2011 - 02:28 PM
No I wanted to draw on a window that isn't mine that I got by FindWindow or whatever
#6
Posted 01 August 2011 - 05:40 PM
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


Sign In
Create Account


Back to top









