how can this be a window id?

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.
Post Reply
language1446
In need of some credit
In need of some credit
Posts: 2
Joined: Wed Sep 30, 2020 1:33 pm

how can this be a window id?

Post by language1446 » Sun Oct 11, 2020 7:27 am

Hi! I was wondering how can "this"(class address) could be a window's id.

something like code below.

Code: Select all

wxPanel *panel = new wxPanel(this, wxID_ANY);
or

Code: Select all

Bind(wxEVT_COMMAND_BUTTON_CLICKED, &Button::OnQuit, this, wxID_EXIT);

Code: Select all

Button::Button(const wxString& title) : 
        wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(250, 150)) 
{
    wxPanel *panel = new wxPanel(this, wxID_ANY);
    wxButton *button = new wxButton(panel, wxID_EXIT, wxT("Quit"), wxPoint(20, 20));

    Bind(wxEVT_COMMAND_BUTTON_CLICKED, &Button::OnQuit, this, wxID_EXIT);
    button->SetFocus();
    Centre();
}
Last edited by doublemax on Sun Oct 11, 2020 7:49 am, edited 1 time in total.

User avatar
doublemax
Moderator
Moderator
Posts: 15283
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: how can this be a window id?

Post by doublemax » Sun Oct 11, 2020 7:56 am

I'm not sure what you're referring to. In none of these examples is "this" used as an ID.

For wxButton and wxPanel the first two parameters are "wxWindow *parent, wxWindowID id". wxWindowID ist just an int. So "this" is used as "wxWindow *".

As for the Bind call. The matching overload is this:

Code: Select all

Bind (const EventTag &eventType, void(Class::*method)(EventArg &), EventHandler *handler, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
In this case, "this" is matches "EventHandler *handler".
Use the source, Luke!

Post Reply