Equivalent of a VB PictureBox

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Locked
srikant1987
Earned a small fee
Earned a small fee
Posts: 15
Joined: Thu Apr 05, 2007 11:33 am

Equivalent of a VB PictureBox

Post by srikant1987 » Fri Apr 13, 2007 7:44 am

Hello everyone,

I've been asked to write a program which plots curves given some "control points"

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Re: Equivalent of a VB PictureBox

Post by upCASE » Fri Apr 13, 2007 8:23 am

Hi!
srikant1987 wrote:What I wanted to ask is, which wxWidget controls have a DC of their own, because once I extract the DC, I can use functions like DrawLine on it and manage the task.
There is no direct equivalent, no widget does have a "DC of their own". But you can create one pretty easily for every window.
The most common approach would be to create a wxPanel as your canvas. Then you implement an event handler for wxPaintEvents, create a wxPaintDC in this handler and draw on the DC.
Another way would be to draw on a wxMemoryDC using a wxBitmap and blit the bitmap to a wxPanel, using wxPaintEvent, idle events, a timer or whatever. I suppose this is what a picturebox would do. It buffers the drawing in a bitmap and blits it to the control surface when there is need to repaint the window.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

srikant1987
Earned a small fee
Earned a small fee
Posts: 15
Joined: Thu Apr 05, 2007 11:33 am

Well ...

Post by srikant1987 » Fri Apr 13, 2007 1:06 pm

What you said might help (I mean, the idea of using a wxMemoryDC and copying it off onto a wxPanel: I've never handled bitmaps in the memory, so I couldn't have thought of it), but this wxPanel wouldn't do.

Actually, like I said, I'll be taking a few "control points" for input: and I'd like the points to be input by clicking on them (and wxPanel doesn't offer the OnMouseUP event

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Fri Apr 13, 2007 1:18 pm

I personally don't use wxDev-C++, so I can't comment on that.
wxPanel, just like almost every other window, can handle wxMouseEvents. For the OnPaint I recommend that you derive your class from wxPanel and implement it there.

To get the HWND you can either use GetHandle() or GetHWND(). It works perfectly for me, maybe you're missing some includes. Note that widgets should NOT be created on the stack.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

srikant1987
Earned a small fee
Earned a small fee
Posts: 15
Joined: Thu Apr 05, 2007 11:33 am

What?!

Post by srikant1987 » Fri Apr 13, 2007 5:43 pm

Well, I have the documentation for wxWidgets 2.8.0 (which you say you use), and it doesn't have any GetHWND listed in it (though the help-viewer I'm using {some Anthemion Help-viewer} might not be very reliable). Here's what it says:

wxWindow::GetHandle
void* GetHandle() const
Returns the platform-specific handle of the physical window. Cast it to an appropriate handle, such as HWND for Windows, Widget for Motif, GtkWidget for GTK or WinHandle for PalmOS.
wxPython note: This method will return an integer in wxPython.
wxPerl note: This method will return an integer in wxPerl.

Well, maybe I'll ask this question on wxDev-C++ forum. Well, I have Microsoft Visual C++ 8, but could you please tell me how I can add on this wxWidgets library to it (maybe it'll be like adding it on to the MSVC you use)? Btw wxDev-C++ is supposed to come with wxWidgets installed, but I'll check out: but many of the wxWidgets samples work fine on it, I don't know why I should get this weird error. What does this error really mean? What's a primary-expression?

Thanks for all the help!

lowjoel
Moderator
Moderator
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel » Sat Apr 14, 2007 1:54 am

Can you please not cross-post over 2 forums?

See http://forums.wxwidgets.org/viewtopic.php?t=13667

Joel

Locked