Text Editor...

is there any way i could make a text editor in c++??
closed account (DSLq5Di1)
The answer is yes: numerous ways!

In a lot of cases, you would just use a pre-existing edit control of some kind (The Win32 GDI Edit control, Scintilla, etc). Which one depends on whether you're using Win32 directly, or a GUI toolkit of some kind (Qt, wxWidgets, FLTK, ...).

For more sophisticated apps, you might implement your own control. The tutorial that sloppy9 posted the link to looks very interesting, but it is quite detailed. And it does include the implementation of a custom edit control. Cool, if you want to learn how to do that...

But, for a very basic Win32 text editor, you could just use the stock GDI Edit control. For this, you just need to create a regular window, with a menu, which has one child which fills up the whole of the client area: an Edit control. (I'm pretty sure this is more or less what the normal Notepad.exe is! You can see it's just an Edit control in a windows with a menu if you examine it with the Spy++ tool)

Depending on where you're starting from, GUI programming-wise, it might make sense to try the stock control approach first. And then move onto the custom control version.

Do you have a preference for a particular GUI toolkit? Or anything like that??

If you know how to write a basic Win32 app, it should be pretty easy for you to clone pretty much all of Notepad's functionality. I wrote my own a few years ago, as I wanted to add extra funcionality to help me with my French homework (mine can do French accents on an English o/s). If you do go this route, make sure you read up about the Common Dialog Box library (for ChooseFont(), GetOpenFileName(), etc). And there are a couple of sticky points which you might have to search out the answer for. Or ask about here!

By the way, the Neatpad app, as opposed to the control, is pretty much what you need to use with the Edit control. With suitable adjustments to the message handling. And it's GDI based.

The starting point for an Edit control based Notepad clone can be found here:

How to Create a Multiline Edit Control

It doesn't have file handling, font selection, etc. but it should be enough to get you going. But I haven't been able to find a good, up to date tutorial which I can point you at. Googling for "notepad clone" will find quite a bit, but be a bit wary of most of these! (it's popular with new programmers who don't always get things quite right...)


PS Note that GDI is probably on the way out, slowly byt surely. e.g. GetOpenFileName() -- which display the File Open Dialog -- was superseded by the shell's IFileOpenDialog mechaism in Windows Vista.
Last edited on
That link everybody here gives to folks wanting to learn Api coding has a working example that is even an MDI interface (Multiple Document Interface), and it uses just plain old edit controls as Andy mentioned. Let me look it up quick ...


Using that you wouldn't even have to code it yourself - just understand what they did. Of course, it suffers from the various pitfalls Andy mentioned. Deconstructing it to make an SDI (Single Document Interface)Notepad would be a good exercise.
Topic archived. No new replies allowed.