Problema wxwidgets passaggio valori fra wxdialog a wxframe

di il
3 risposte

Problema wxwidgets passaggio valori fra wxdialog a wxframe

Vi posto il codice:
#ifndef __GETXYDLG_h__
#define __GETXYDLG_h__

#ifdef __BORLANDC__
	#pragma hdrstop
#endif

#ifndef WX_PRECOMP
	#include <wx/wx.h>
	#include <wx/dialog.h>
#else
	#include <wx/wxprec.h>
#endif

//Do not add custom headers between
//Header Include Start and Header Include End.
//wxDev-C++ designer will remove them. Add custom headers after the block.
////Header Include Start
#include <wx/timer.h>
#include <wx/spinctrl.h>
#include <wx/stattext.h>
#include <wx/button.h>
#include <wx/checkbox.h>
////Header Include End

////Dialog Style Start
#undef GetXYDlg_STYLE
#define GetXYDlg_STYLE wxCAPTION | wxSYSTEM_MENU | wxDIALOG_NO_PARENT | wxMINIMIZE_BOX | wxCLOSE_BOX
////Dialog Style End

class GetXYDlg : public wxDialog
{
	private:
		DECLARE_EVENT_TABLE();
        void SetTxtXYLabel();

	public:
		GetXYDlg(wxWindow *parent, wxWindowID id = 1, const wxString &title = wxT("GetXYDlg"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = GetXYDlg_STYLE);
		virtual ~GetXYDlg();
		void AutoCheckMouseClick(wxCommandEvent& event);
		void TmrCheckTimer(wxTimerEvent& event);
		void GetXYDlgActivate(wxActivateEvent& event);
		void OkClick(wxCommandEvent& event);
		LPPOINT GetLPPOINT();

	private:
		//Do not add custom control declarations between
		//GUI Control Declaration Start and GUI Control Declaration End.
		//wxDev-C++ will remove them. Add custom code after the block.
		////GUI Control Declaration Start
		wxTimer *TmrCheck;
		wxStaticText *TxtY;
		wxStaticText *TxtX;
		wxSpinCtrl *ClipY;
		wxSpinCtrl *ClipX;
		wxStaticText *WxStaticText2;
		wxStaticText *WxStaticText1;
		wxButton *Cancel;
		wxButton *Ok;
		wxCheckBox *AutoCheckMouse;
		////GUI Control Declaration End

	private:
		//Note: if you receive any error with these enum IDs, then you need to
		//change your old form code that are based on the #define control IDs.
		//#defines may replace a numeric value for the enum names.
		//Try copy and pasting the below block in your old form header files.
		enum
		{
			////GUI Enum Control ID Start
			ID_TMRCHECK = 1003,
			ID_TXTY = 1011,
			ID_TXTX = 1010,
			ID_CLIPY = 1009,
			ID_CLIPX = 1008,
			ID_WXSTATICTEXT2 = 1007,
			ID_WXSTATICTEXT1 = 1006,
			ID_CANCEL = 1005,
			ID_OK = 1004,
			ID_AUTOCHECKMOUSE = 1002,
			////GUI Enum Control ID End
			ID_DUMMY_VALUE_ //don't remove this value unless you have other enum values
		};

	private:
		void OnClose(wxCloseEvent& event);
		void CreateGUIControls();

};

#endif
e questo è "GetXYDlg.h"

e questo il "GetXYDlg.cpp"

#include "GetXYDlg.h"

//Do not add custom headers
//wxDev-C++ designer will remove them
////Header Include Start
////Header Include End
//{}
//----------------------------------------------------------------------------
// GetXYDlg
//----------------------------------------------------------------------------
//Add Custom Events only in the appropriate block.
//Code added in other places will be removed by wxDev-C++
////Event Table Start
BEGIN_EVENT_TABLE(GetXYDlg,wxDialog)
	////Manual Code Start
	////Manual Code End

	EVT_CLOSE(GetXYDlg::OnClose)
	EVT_ACTIVATE(GetXYDlg::GetXYDlgActivate)
	EVT_TIMER(ID_TMRCHECK,GetXYDlg::TmrCheckTimer)
	EVT_BUTTON(ID_OK,GetXYDlg::OkClick)
	EVT_CHECKBOX(ID_AUTOCHECKMOUSE,GetXYDlg::AutoCheckMouseClick)
END_EVENT_TABLE()
////Event Table End

GetXYDlg::GetXYDlg(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &position, const wxSize& size, long style)
: wxDialog(parent, id, title, position, size, style)
{
	CreateGUIControls();
}

GetXYDlg::~GetXYDlg()
{
}

void GetXYDlg::CreateGUIControls()
{
	//Do not add custom code between
	//GUI Items Creation Start and GUI Items Creation End.
	//wxDev-C++ designer will remove them.
	//Add the custom code before or after the blocks
	////GUI Items Creation Start

	SetTitle(wxT("GetXYDlg"));
	SetIcon(wxNullIcon);
	SetSize(8,8,489,118);
	Center();


	TmrCheck = new wxTimer();
	TmrCheck->SetOwner(this, ID_TMRCHECK);
	TmrCheck->Start(100);

	TxtY = new wxStaticText(this, ID_TXTY, wxT("TxtY"), wxPoint(314,9), wxDefaultSize, 0, wxT("TxtY"));
	TxtY->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	TxtX = new wxStaticText(this, ID_TXTX, wxT("TxtX"), wxPoint(249,9), wxDefaultSize, 0, wxT("TxtX"));
	TxtX->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	ClipY = new wxSpinCtrl(this, ID_CLIPY, wxT("0"), wxPoint(182,43), wxSize(121,22), wxSP_ARROW_KEYS, 0, 100, 0);
	ClipY->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	ClipX = new wxSpinCtrl(this, ID_CLIPX, wxT("0"), wxPoint(24,43), wxSize(118,22), wxSP_ARROW_KEYS, 0, 100, 0);
	ClipX->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	WxStaticText2 = new wxStaticText(this, ID_WXSTATICTEXT2, wxT("Y:"), wxPoint(156,46), wxDefaultSize, 0, wxT("WxStaticText2"));
	WxStaticText2->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	WxStaticText1 = new wxStaticText(this, ID_WXSTATICTEXT1, wxT("X:"), wxPoint(8,46), wxDefaultSize, 0, wxT("WxStaticText1"));
	WxStaticText1->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	Cancel = new wxButton(this, ID_CANCEL, wxT("Annulla"), wxPoint(391,40), wxSize(75,25), 0, wxDefaultValidator, wxT("Cancel"));
	Cancel->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	Ok = new wxButton(this, ID_OK, wxT("Ok"), wxPoint(391,7), wxSize(75,25), 0, wxDefaultValidator, wxT("Ok"));
	Ok->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	AutoCheckMouse = new wxCheckBox(this, ID_AUTOCHECKMOUSE, wxT("Cattura automaticamente coordinate mouse"), wxPoint(8,8), wxSize(234,17), 0, wxDefaultValidator, wxT("AutoCheckMouse"));
	AutoCheckMouse->SetValue(true);
	AutoCheckMouse->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));
	////GUI Items Creation End
}

bool AutoCheck = true;

void GetXYDlg::OnClose(wxCloseEvent& /*event*/)
{
	Destroy();
}

/*
 * AutoCheckMouseClick
 */
void GetXYDlg::AutoCheckMouseClick(wxCommandEvent& event)
{
    AutoCheck = AutoCheckMouse->IsChecked();
}

/*
 * TmrCheckTimer
 */
void GetXYDlg::TmrCheckTimer(wxTimerEvent& event)
{
   if (AutoCheck && (GetAsyncKeyState(83) ==  -32767))
    {
        AutoCheck = false;
        AutoCheckMouse->SetValue(false);
    }
    else if (AutoCheck)
    {
        SetTxtXYLabel();
    }
    else if (!AutoCheck && (GetAsyncKeyState(82) == -32767))
    {
        AutoCheck = true;
        AutoCheckMouse->SetValue(true);
    }
}

void GetXYDlg::SetTxtXYLabel()
{
    LPPOINT W = new POINT ;
    wxString Stri;
    GetCursorPos(W);
    Stri << "X: " << W->x;
    TxtX->SetLabel(Stri);
    Stri.Clear();
    Stri << " Y: " << W->y;
    TxtY->SetLabel(Stri);
    if (GetAsyncKeyState(65) == -32767)
    {
        AutoCheckMouse->SetValue(false);
        AutoCheck = false;
        ClipX->SetValue(W->x);
        ClipY->SetValue(W->y);
    }
    delete W;
    delete Stri;
}

/*
 * GetXYDlgActivate
 */
void GetXYDlg::GetXYDlgActivate(wxActivateEvent& event)
{
     ClipX->SetMax(GetSystemMetrics(0) - 1);
     ClipY->SetMax(GetSystemMetrics(1) - 1);
}

/*
 * OkClick
 */
void GetXYDlg::OkClick(wxCommandEvent& event)
{
	this->SetReturnCode(1);
	this->Show(false);
}

LPPOINT GetXYDlg::GetLPPOINT()
{
    LPPOINT R;
    R->x = ClipX->GetValue();
    R->y = ClipY->GetValue();
    return R;
    delete R;
}
questa è la mia dialogbox, che cattura le coordinate del mouse e imposta certi clipctrl, alla pressione del tasto ok, setta il codice di return a 1 e nasconde il wxdialog.

però quando invoco la funzione GetXYDlg::GetLPPOINT() dal wxframe mi da errore d'applicazione e si chiude

ecco il codice ( il wxframe è semplice, xk prima di fare il resto devo risolvere qst problema)

#ifndef __GALAXYREFRESHFRM_h__
#define __GALAXYREFRESHFRM_h__

#ifdef __BORLANDC__
	#pragma hdrstop
#endif

#ifndef WX_PRECOMP
	#include <wx/wx.h>
	#include <wx/frame.h>
#else
	#include <wx/wxprec.h>
#endif

//Do not add custom headers between
//Header Include Start and Header Include End.
//wxDev-C++ designer will remove them. Add custom headers after the block.
////Header Include Start
#include <wx/button.h>
#include <wx/panel.h>
////Header Include End

////Dialog Style Start
#undef GalaxyRefreshFrm_STYLE
#define GalaxyRefreshFrm_STYLE wxCAPTION | wxSYSTEM_MENU | wxMINIMIZE_BOX | wxCLOSE_BOX
////Dialog Style End

class GalaxyRefreshFrm : public wxFrame
{
	private:
		DECLARE_EVENT_TABLE();

	public:
		GalaxyRefreshFrm(wxWindow *parent, wxWindowID id = 1, const wxString &title = wxT("GalaxyRefresh"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = GalaxyRefreshFrm_STYLE);
		virtual ~GalaxyRefreshFrm();
		void WxButton1Click(wxCommandEvent& event);

	private:
		//Do not add custom control declarations between
		//GUI Control Declaration Start and GUI Control Declaration End.
		//wxDev-C++ will remove them. Add custom code after the block.
		////GUI Control Declaration Start
		wxButton *WxButton1;
		wxPanel *WxPanel1;
		////GUI Control Declaration End

	private:
		//Note: if you receive any error with these enum IDs, then you need to
		//change your old form code that are based on the #define control IDs.
		//#defines may replace a numeric value for the enum names.
		//Try copy and pasting the below block in your old form header files.
		enum
		{
			////GUI Enum Control ID Start
			ID_WXBUTTON1 = 1002,
			ID_WXPANEL1 = 1001,
			////GUI Enum Control ID End
			ID_DUMMY_VALUE_ //don't remove this value unless you have other enum values
		};

	private:
		void OnClose(wxCloseEvent& event);
		void CreateGUIControls();
};

#endif
il GalaxyRefreshFrm.h

e il GalaxyRefreshFrm.cpp:

#include "GalaxyRefreshFrm.h"
#include "GetXYDlg.h"

//Do not add custom headers between
//Header Include Start and Header Include End
//wxDev-C++ designer will remove them
////Header Include Start
////Header Include End

//----------------------------------------------------------------------------
// GalaxyRefreshFrm
//----------------------------------------------------------------------------
//Add Custom Events only in the appropriate block.
//Code added in other places will be removed by wxDev-C++
////Event Table Start
BEGIN_EVENT_TABLE(GalaxyRefreshFrm,wxFrame)
	////Manual Code Start
	////Manual Code End

	EVT_CLOSE(GalaxyRefreshFrm::OnClose)
	EVT_BUTTON(ID_WXBUTTON1,GalaxyRefreshFrm::WxButton1Click)
END_EVENT_TABLE()
////Event Table End

GalaxyRefreshFrm::GalaxyRefreshFrm(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &position, const wxSize& size, long style)
: wxFrame(parent, id, title, position, size, style)
{
	CreateGUIControls();
}

GalaxyRefreshFrm::~GalaxyRefreshFrm()
{
}

void GalaxyRefreshFrm::CreateGUIControls()
{
	//Do not add custom code between
	//GUI Items Creation Start and GUI Items Creation End
	//wxDev-C++ designer will remove them.
	//Add the custom code before or after the blocks
	////GUI Items Creation Start

	WxPanel1 = new wxPanel(this, ID_WXPANEL1, wxPoint(0,0), wxSize(312,300));
	WxPanel1->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	WxButton1 = new wxButton(WxPanel1, ID_WXBUTTON1, wxT("WxButton1"), wxPoint(83,55), wxSize(75,25), 0, wxDefaultValidator, wxT("WxButton1"));
	WxButton1->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	SetTitle(wxT("GalaxyRefresh"));
	SetIcon(wxNullIcon);
	SetSize(8,8,320,334);
	Center();

	////GUI Items Creation End
}

void GalaxyRefreshFrm::OnClose(wxCloseEvent& event)
{
	Destroy();
}

/*
 * WxButton1Click
 */
void GalaxyRefreshFrm::WxButton1Click(wxCommandEvent& event)
{
	GetXYDlg *dlg = new GetXYDlg(this);
	if (dlg->ShowModal() == 1)
	{
        LPPOINT F;
        F->x = dlg->GetLPPOINT()->x;
    }
}
il wxframe mostra la wxdialog, non ho inserito anke la galaxyrefreshapp xk era inutile dato che invocava semplicemente la wxframe (penso, io nn l'ho modificata)

uso devc++, kiunque mi può dare 1 mano mi faccia sapere, è 3 giorni che giro x risolvere il problema, ma niente, ho provato a impostare 1 variabile pubblica (aggiungendo sotto Public: LPPOINT e un nome che usavo, ma mi dava lo stesso l'errore)

spero che qualcuno mi possa rispondere

3 Risposte

Devi accedere o registrarti per scrivere nel forum
3 risposte