WxWidgets Button problem

Hi, I need some help with wxwidgets, this code does not work for some reason:


MyPanel::MyPanel(wxFrame *parent):wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE)
{
	wxButton Button(this,wxEVT_PAINT,wxT("Paint"), wxPoint(0,20),wxDefaultSize);
	wxButton *ButtonState;
	ButtonState=&Button;
	if(ButtonState->IsPressed()==true)
		Connect(wxEVT_PAINT,wxPaintEventHandler(MyPanel::OnPaint));
}


It comes up with the error IsPressed is not a member of wxButton although I looked at the class wxButton and it shows this

public:
virtual bool IsPressed() const { return m_isPressed; }

Does any one know why?
Last edited on
What documentation are you looking at??

I just looked at VXWidgets version 2.6 and version 2.* documentation - and I do not see any
member function of wxButton called IsPressed().
This is the code for the class wxButton:



///////////////////////////////////////////////////////////////////////////////
// Name:        wx/univ/button.h
// Purpose:     wxButton for wxUniversal
// Author:      Vadim Zeitlin
// Modified by:
// Created:     15.08.00
// RCS-ID:      $Id: button.h 41227 2006-09-14 19:36:47Z VZ $
// Copyright:   (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
// Licence:     wxWindows licence
///////////////////////////////////////////////////////////////////////////////

#ifndef _WX_UNIV_BUTTON_H_
#define _WX_UNIV_BUTTON_H_

class WXDLLEXPORT wxInputHandler;

#include "wx/bitmap.h"

// ----------------------------------------------------------------------------
// the actions supported by this control
// ----------------------------------------------------------------------------

#define wxACTION_BUTTON_TOGGLE  _T("toggle")    // press/release the button
#define wxACTION_BUTTON_PRESS   _T("press")     // press the button
#define wxACTION_BUTTON_RELEASE _T("release")   // release the button
#define wxACTION_BUTTON_CLICK   _T("click")     // generate button click event

// ----------------------------------------------------------------------------
// wxButton: a push button
// ----------------------------------------------------------------------------

class WXDLLEXPORT wxButton : public wxButtonBase
{
public:
    wxButton() { Init(); }
    wxButton(wxWindow *parent,
             wxWindowID id,
             const wxBitmap& bitmap,
             const wxString& label = wxEmptyString,
             const wxPoint& pos = wxDefaultPosition,
             const wxSize& size = wxDefaultSize,
             long style = 0,
             const wxValidator& validator = wxDefaultValidator,
             const wxString& name = wxButtonNameStr)
    {
        Init();

        Create(parent, id, bitmap, label, pos, size, style, validator, name);
    }

    wxButton(wxWindow *parent,
             wxWindowID id,
             const wxString& label = wxEmptyString,
             const wxPoint& pos = wxDefaultPosition,
             const wxSize& size = wxDefaultSize,
             long style = 0,
             const wxValidator& validator = wxDefaultValidator,
             const wxString& name = wxButtonNameStr)
    {
        Init();

        Create(parent, id, label, pos, size, style, validator, name);
    }

    bool Create(wxWindow *parent,
                wxWindowID id,
                const wxString& label = wxEmptyString,
                const wxPoint& pos = wxDefaultPosition,
                const wxSize& size = wxDefaultSize,
                long style = 0,
                const wxValidator& validator = wxDefaultValidator,
                const wxString& name = wxButtonNameStr)
    {
        return Create(parent, id, wxNullBitmap, label,
                      pos, size, style, validator, name);
    }

    bool Create(wxWindow *parent,
                wxWindowID id,
                const wxBitmap& bitmap,
                const wxString& label = wxEmptyString,
                const wxPoint& pos = wxDefaultPosition,
                const wxSize& size = wxDefaultSize,
                long style = 0,
                const wxValidator& validator = wxDefaultValidator,
                const wxString& name = wxButtonNameStr);

    virtual ~wxButton();

    virtual void SetImageLabel(const wxBitmap& bitmap);
    virtual void SetImageMargins(wxCoord x, wxCoord y);
    virtual void SetDefault();

    virtual bool IsPressed() const { return m_isPressed; }
    virtual bool IsDefault() const { return m_isDefault; }

    // wxButton actions
    virtual void Toggle();
    virtual void Press();
    virtual void Release();
    virtual void Click();

    virtual bool PerformAction(const wxControlAction& action,
                               long numArg = -1,
                               const wxString& strArg = wxEmptyString);

    virtual bool CanBeHighlighted() const { return true; }

    static wxInputHandler *GetStdInputHandler(wxInputHandler *handlerDef);
    virtual wxInputHandler *DoGetStdInputHandler(wxInputHandler *handlerDef)
    {
        return GetStdInputHandler(handlerDef);
    }


protected:
    virtual wxSize DoGetBestClientSize() const;

    virtual bool DoDrawBackground(wxDC& dc);
    virtual void DoDraw(wxControlRenderer *renderer);

    // common part of all ctors
    void Init();

    // current state
    bool m_isPressed,
         m_isDefault;

    // the (optional) image to show and the margins around it
    wxBitmap m_bitmap;
    wxCoord  m_marginBmpX,
             m_marginBmpY;

private:
    DECLARE_DYNAMIC_CLASS(wxButton)
};

#endif // _WX_UNIV_BUTTON_H_



There are several button.h files in wxwidgets - what design of button class you see depends on what platform you arte running on.

wx/button.h defines the buttonbase class - and at the end of this file is a host of conditional includes like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// returns the default button size for this platform
    static wxSize GetDefaultSize();

protected:
    DECLARE_NO_COPY_CLASS(wxButtonBase)
};

#if defined(__WXUNIVERSAL__)
    #include "wx/univ/button.h"
#elif defined(__WXMSW__)
    #include "wx/msw/button.h"
#elif defined(__WXMOTIF__)
    #include "wx/motif/button.h"
#elif defined(__WXGTK20__)
    #include "wx/gtk/button.h"
#elif defined(__WXGTK__)
    #include "wx/gtk1/button.h"
#elif defined(__WXMAC__)
    #include "wx/mac/button.h"
#elif defined(__WXCOCOA__)
    #include "wx/cocoa/button.h"
#elif defined(__WXPM__)
    #include "wx/os2/button.h"
#elif defined(__WXPALMOS__)
    #include "wx/palmos/button.h"
#endif

#endif // wxUSE_BUTTON

#endif 


So on windows you will get the button class located in wx/msw/button.h.

__WXUNIVERSAL__ would have to be defined to get the wx/univ/button.h by default - but
that is obviously not happening _ so you do no have __WXUNIVERSAL__ setup/defined.
I don't know if that would be something that is specified at wxwidget installation time (i can't remember suc an option being present) or if you can just define it at the top of your cpp file.

Check the wxwidget documentation.
doesn't work, I put #define __WXUNIVERSAL__ at the top of my program
Wxwidgets itself must be compiled this way. Look at build/msw/config.gcc on how to enable wxuniversal port, then run make from a command prompt to build. For VS is similar, only change config.vc and run nmake.
how? I'm using windows 7 ultimate
Instead of trying to test IsPressed, why dont you attach a click event(why are you using a paint event?), see this example.
http://wiki.wxwidgets.org/Writing_Your_First_Application-Adding_A_Button looks pretty straight forward.
Topic archived. No new replies allowed.