Author Topic: C++ wxWidgets Text Editor  (Read 7240 times)

0 Members and 2 Guests are viewing this topic.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
C++ wxWidgets Text Editor
« on: May 13, 2011, 05:06:07 pm »
I was trying to make a text editor in C++ but I found no tutorials on the web. So I had to do some research on a few stuff to put it up and running. It is very simple, it is more of an example and has no Save/Open options, maybe I'll add those later.

If you want the full code you can find it here. In case you want a screenshot of it, here's one taken in Linux Mint (it is cross-platform don't worry)

Spoiler For Spoiler:


Here's the main part of the program, commented:

Code: [Select]
wxTextCtrl *textControl = new wxTextCtrl;                                  //Define the new textCtrl
   
    textControl = new wxTextCtrl(this, ID_TextBox,
      wxT(""), wxDefaultPosition, wxDefaultSize,
      wxTE_MULTILINE | wxTE_RICH , wxDefaultValidator, wxTextCtrlNameStr); //Creates a text box, with no text, id=ID_TextBox, it's multiline
     
    wxMenu *menuFile = new wxMenu;                                         //Create a new menu to be placed on a menu bar

    menuFile->Append( ID_About, _("&About...") );                          //Add the first option to the menu (will show up on top)
    menuFile->AppendSeparator();                                           //Add a separator, this is handy
    menuFile->Append( ID_Quit, _("E&xit") );                               //Add an option to the menu

    wxMenuBar *menuBar = new wxMenuBar;                                    //Create a new menu bar
    menuBar->Append( menuFile, _("&File") );                               //Append the file menu

    SetMenuBar( menuBar );                                                 //Defines the window menu bar to menuBar
   
    Maximize();                                                            //Maximizes the window

Attached is the source file.
« Last Edit: May 13, 2011, 05:09:35 pm by Scout »

Offline alberthrocks

  • Moderator
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 876
  • Rating: +103/-10
    • View Profile
Re: C++ wxWidgets Text Editor
« Reply #1 on: May 13, 2011, 05:28:11 pm »
Here's a Makefile to build this:
Code: [Select]
all:
@echo "** Building..."
g++ -c `wx-config --cppflags` helloworldgui.cpp -o helloworldgui.o
@echo "** Linking/creating executable..."
g++ `wx-config --libs` helloworldgui.o -o helloworld
clean:
@echo "** Removing object files and executable..."
rm -f helloworldgui.o helloworldgui
install:
echo '** Installing (why in the world do you want to install this??)...'
cp helloworldgui /usr/bin
uninstall:
@echo '** Uninstalling...'
rm /usr/bin/helloworldgui
Make a file called Makefile, copy+paste the above stuff into it, and save it in the same dir as helloworldgui.cpp.
Then, in a terminal, make sure you are in the directory where the Makefile and source are, and type:
Code: [Select]
make
To run, type:
Code: [Select]
./helloworldgui
make clean will delete the helloworldgui.o and helloworldgui executable files, make install will install helloworldgui into your computer (why would you want to do that? :P), and make uninstall will uninstall helloworldgui.
« Last Edit: May 13, 2011, 05:32:47 pm by alberthrocks »
Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/


Proud member of ClrHome!

Miss my old signature? Here it is!
Spoiler For Signature:
Alternate "New" IRC post notification bot (Newy) down? Go here to reset it! http://withg.org/albert/cpuhero/

Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/

Activity remains limited due to busyness from school et al. Sorry! :( Feel free to PM, email, or if you know me well enough, FB me if you have a question/concern. :)

Don't expect me to be online 24/7 until summer. Contact me via FB if you feel it's urgent.


Proud member of ClrHome!

Spoiler For "My Projects! :D":
Projects:

Computer/Web/IRC Projects:
C______c: 0% done (Doing planning and trying to not forget it :P)
A_____m: 40% done (Need to develop a sophisticated process queue, and a pretty web GUI)
AtomBot v3.0: 0% done (Planning stage, may do a litmus test of developer wants in the future)
IdeaFrenzy: 0% done (Planning and trying to not forget it :P)
wxWabbitemu: 40% done (NEED MOAR FEATURES :P)

Calculator Projects:
M__ C_____ (an A____ _____ clone): 0% done (Need to figure out physics and Axe)
C2I: 0% done (planning, checking the demand for it, and dreaming :P)

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: C++ wxWidgets Text Editor
« Reply #2 on: May 13, 2011, 05:30:01 pm »
Hum, that sounds too complicated, here's my option:

Code: [Select]
g++ helloworldgui.cpp `wx-config --cxxflags` `wx-config --libs`
./a.out

Save it as compile.sh or whatever and build+run by doing sh compile.sh.

But I guess that has more options, but for developing it, I used this.

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: C++ wxWidgets Text Editor
« Reply #3 on: May 13, 2011, 06:26:55 pm »
If its an sh file can't it only be run in Linux. alberthrocks method would be multiplatform I believe
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: C++ wxWidgets Text Editor
« Reply #4 on: May 14, 2011, 04:21:59 am »
Actually, I don't think /usr/bin exists in Windows for software, or does it?

Offline alberthrocks

  • Moderator
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 876
  • Rating: +103/-10
    • View Profile
Re: C++ wxWidgets Text Editor
« Reply #5 on: May 14, 2011, 11:53:40 am »
Hum, that sounds too complicated, here's my option:

Code: [Select]
g++ helloworldgui.cpp `wx-config --cxxflags` `wx-config --libs`
./a.out

Save it as compile.sh or whatever and build+run by doing sh compile.sh.

But I guess that has more options, but for developing it, I used this.
bleh... remember that Linux has no extensions for shell scripts or binaries! :P
Preferably:
Code: [Select]
g++ helloworldgui.cpp `wx-config --cxxflags` `wx-config --libs` -o helloworldgui
./helloworldgui
...since you know exactly what was compiled. If you had many object files, it wouldn't be very pretty with all of them writing to ./a.out! :P

If its an sh file can't it only be run in Linux. alberthrocks method would be multiplatform I believe
Actually, I don't think /usr/bin exists in Windows for software, or does it?
Scout's right on this one - the make install rule will not work on Windows. But, the makefile works on all platforms (assuming GCC is in the PATH on Windows) due to the "make" binary being cross-platform.

For Windows, a slight modification needs to be made. Change
Code: [Select]
g++ `wx-config --libs` helloworldgui.o -o helloworldto
Code: [Select]
g++ `wx-config --libs` helloworldgui.o -o helloworld.exe
Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/


Proud member of ClrHome!

Miss my old signature? Here it is!
Spoiler For Signature:
Alternate "New" IRC post notification bot (Newy) down? Go here to reset it! http://withg.org/albert/cpuhero/

Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/

Activity remains limited due to busyness from school et al. Sorry! :( Feel free to PM, email, or if you know me well enough, FB me if you have a question/concern. :)

Don't expect me to be online 24/7 until summer. Contact me via FB if you feel it's urgent.


Proud member of ClrHome!

Spoiler For "My Projects! :D":
Projects:

Computer/Web/IRC Projects:
C______c: 0% done (Doing planning and trying to not forget it :P)
A_____m: 40% done (Need to develop a sophisticated process queue, and a pretty web GUI)
AtomBot v3.0: 0% done (Planning stage, may do a litmus test of developer wants in the future)
IdeaFrenzy: 0% done (Planning and trying to not forget it :P)
wxWabbitemu: 40% done (NEED MOAR FEATURES :P)

Calculator Projects:
M__ C_____ (an A____ _____ clone): 0% done (Need to figure out physics and Axe)
C2I: 0% done (planning, checking the demand for it, and dreaming :P)

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: C++ wxWidgets Text Editor
« Reply #6 on: May 15, 2011, 07:56:24 am »
Yeah I guess. So it has to be changed.

Also what about in the install label not only move to /usr/bin and create a desktop file in the /home/Desktop/ that directs to it?