简体   繁体   中英

WXwidgets for GUI in C++:

I am totally beginner in creating GUIS and I am using wxwidgets to create GUI programs in CodeBlocks. I am following this tutorials here:

http://wiki.codeblocks.org/index.php?title=WxSmith_tutorials

I have figured out how to create dialog boxes and frames. Now, I have created in C++ a program that reads information from a .txt file and calls a method displayInfo() that prints this information using cout. What I would like to do is to print this information on a single window, by clicking a button, say: "Print Information".

The part that I am finding hard, is how to call my displayInfo() method from the main.cpp of the frame, and how to display that information on a window, instead of the terminal. I tried to import the header file of my class in the main.cpp of the frame, and called displayInfo(), but I do not think this is the right way to do it.

Any help would be appreciated.

wxWidgets has some predefined dialog boxes for display small quantities of text.

See wxMessageBox description

Otherwise you will have to use a DrawText method on the panel or window.

I reccomend using a text control and then redirecting cout to the text control

Like this:

#include <iostream>

  wxTextCtrl *control = new wxTextCtrl(...);

  wxStreamToTextRedirector redirect(control);

  // all output to cout goes into the text control until the exit from current
  // scope

For more discussion of neat variations on this trick, take a look at:

http://docs.wxwidgets.org/2.8/wx_wxtextctrl.html

Scroll down to the section titled: wxTextCtrl and C++ streams

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM