【发布时间】:2019-05-15 14:21:42
【问题描述】:
我正在 CodeBlocks 中使用 wxSmith 学习 C++。
我已经构建了一个有两个框架的应用程序,我需要访问顶层窗口中的变量。
void test12052019Frame::OnButton1Click(wxCommandEvent& event)
{
wxString test1 = "";
wxString test2 = "";
test1 = TextCtrl1->GetValue();
test2 = TextCtrl2->GetValue();
// compare/parse userid/password
// Access ERP system and get credential schema
// build the treeview
if(test1 == "titou" && test2 == "123123"){
// todo auth. against Mysql
wxMessageBox("You're in !!\n");
TreeCtrl1->Show();
TreeCtrl1->ExpandAll();
}else
wxMessageBox("You're out !!\nWrong userid/password");
}
void test12052019Frame::OnTreeCtrl1ItemActivated(wxTreeEvent& event)
{
//TreeCtrl1 is my tree
//when I click on any option of my tree
//it activate a wxMessageBox with the label
//of the option selected...
//just let go your imagination :)
NewFrameActivities *mynewwindow = new NewFrameActivities(this);
wxString thelabel;
wxTreeItemId test3;
test3 = TreeCtrl1->GetSelection();
thelabel = TreeCtrl1->GetItemText(test3);
wxMessageBox(thelabel);
mynewwindow->SetLabel(thelabel);
//mynewwindow->StaticBox1->SetLabel(tosomething...);
//I have a textctrl in this event (textctrl1) and
//textctrl(textctrl1) in another event
mynewwindow->TextCtrl1->ChangeValue("thetest\nsetvalue\n");
mynewwindow->Show(TRUE);
}
我需要知道第一个事件的用户名 (顶层窗口,textctrl1) Visual demo
【问题讨论】:
-
就像在第一个函数中那样调用
TextCtrl1->GetValue()? -
来自另一个框架?我不这么认为
-
为了让它工作,我不得不在顶部声明 wxString test1 和 test2 ,这很难看......
-
不,你没有。您可以在调用下一个函数时直接使用调用结果。如在例如
mynewwindow->TextCtrl1->ChangeValue(TextCtrl1->GetValue());。 实验! -
每当您引用 textctrl1 时,它都在其上下文中。我有两个带有名为 textctrl1 的 textctrl 的框架。顺便说一句,在全局范围内声明这两个变量使其工作......丑陋
标签: c++ codeblocks wxwidgets