Modifying old Windows program for Mac OS X - c++

This application was written for windows back in 1998,
I loved using this program, Now I want to learn how to make it
work on Mac, And maybe changing and adding functionality,
The problem is I don't know where to start, I Have studied C++ php, javascript, But don't really know how to read this code. or where to start.
Thanks for taking a look
http://github.com/klanestro/textCalc
From http://www.atomixbuttons.com/textcalc/
What is TextCalc?
TextCalc is a combination of an
expression calculator and a text
editor. Being both, it has several
advantages over conventional
calculators.
1) You can evaluate expressions like
9*4-2+95-12 just the way you write
them on paper.
2) You can put comments besides your
answer and expressions.
3) You can save, reload, edit and
print your results and expressions.
4) You do not need to write your
answer down on a paper before
computing another expression, as you
can leave the previous result in the
editor.
5) You can open an existing text data
file and perform calculations on it.
6) You can apply an expression to many
numbers at one go. For example, you
can change the list 1 2 3 4 5 to 2 4
6 8 10 by multiplying each number by
2.
7) You can sum, average, convert into
hex etc. a list of numbers easily.
The editor is capable of parsing
numbers and strings enclosed in double
quotes " ". Numbers will be colored
blue and strings will be colored red.
This makes it ideal for editing files
containing numeric data.
★✩

Based on the screenshots and info on the TextCalc site, I think this is best implemented as a Mac OS X service. You can assign a hot key to trigger your service in the System Preferences -> Keyboard -> Services.
It would actually be rather easy. You don't need to write the text editor portion, it will be available in all text areas in all apps. You will be handed the text the user has selected, and all you need to do is evaluate it. There's a built-in command line tool, bc, that you should be able to delegate this to.
There is a guide to implementing services. You will need to read through the Cocoa intro material to understand it. This is a good first project, though.
I don't think there's any reason to try to read the source of the original app in this case. You just need to know what you want the behavior to be.

Check out the Calculator example from the second chapter of Stroustrup's "The C++ Programming Language".

It looks like this application is written using MFC, which is quite Windows-centric. Translating this program to use a different API such as Cocoa would be a lot of work, and would require good familiarity with both MFC and Cocoa. Not to mention the work involved in translating the C++ to Objective-C, of course.
You may be better off running it as-is in a virtual machine such as VirtualBox, or under Wine. Unfortunately, the free version of Microsoft Visual C++ does not include MFC, so to modify this code you would have to either purchase a non-free version of MSVC, or translate the program to "bare bones" Win32, without using MFC.

The core part of this program (Expression Evaluation) has been taken from this smaller program written by Zoly Farkas.
So I would suggest the following:
Learn Objective C.
As an exercise, port Zoly Farkas' Expression Evaluation to Objective-C, to use as a library or on the command line.
Learn Cocoa.
As an exercise, create a graphical interface for your library using Cocoa. You don't need MFC.
Should be fun! :-)

I would not recommend to "port" such a old program using MFC which you cant use on a Mac anyway.
Rather i would recommend to create the skeleton of a new blank application and then to insert more or less large fragments from the old code. The skeleton may use whatever language is appropriate: C++, Objective-C, real Basic. But as the code to reuse is C++ its probably best to use C++.

If you decide to re-write it, I recommend RealBasic. It has many components that will help shorten the development cycle and you can compile the program for Windows, Mac and Linux.
Easy to learn and very productive platform.

Why not rewrite it in C# .NET and use Mono to compile it on the Mac? You can rewrite the GUI parts in Native Cocoa from c# using a wrapper. Depends on your program but this program doesn't sound like your going to sell it to the public so L+F issues are probably not an issue.

The code looks to be in C++. C++ is available on Macs.
The code relies on MFC, which if course is not available on OS X. So you'll need to pick a framework like WxWidgets, Qt, FLTK, etc. that's available on both the Mac and Windows. Then you need to translate from MFC to your new framework.
In the process you'll learn more about MFC than you intend to.

Related

I want to create a DeskBand. Do I have to use C++?

I want to create a DeskBand to display some information on my Windows task bar, but I am struggling with implementing the functionality I need in C++. It's been about 10-15 years since I touched C++. I've been working entirely in .NET for the past 7 years.
Before you say it - I know that DeskBands are deprecated. But the suggested replacement UI element - thumbnail toolbars - don't meet my needs. I need a UI element that is constantly visible to the user no matter which application they switch to, and also that provides enough room to display a line of text - I could get by with room for 30 characters or so.
I've been able to get the DeskBand from the Windows SDK sample to compile and run, but now I need to implement some real functionality - specifically...
Locating the AppData\Local folder (SHGetKnownFolderPath(FOLDERID_LocalAppData...)
Watching an XML file for modifications. I need to parse and repaint whenever the file changes.
Parsing the XML file (I found pugixml)
Displaying some data from the XML file in my DeskBand
Setting a timer to repaint the DeskBand once per minute
... and I am realizing how little I know about C++, and how much I've come to depend on .NET's Base Class Library. This task would be super easy for me if I was writing it in C#. But I've learned elsewhere that you shouldn't write shell extensions in .NET.
What are my options? Is there an easier language to accomplish this in - maybe Python? Or do I have to just bite the bullet and do this in C++? If so, any advice for a .NET developer trying to implement a WinAPI shell extension in C++?
Thank you in advance.
Shell Extensions are COM objects, and C++ is generally the best language to use when developing COM objects because COM was designed primarily for C++, but it is not the only language possible. COM has a standardized architecture, so you can use any language outside of .NET that supports COM object development (Delphi, VB, etc) to develop Shell Extensions (similar to how the Win32 API is primarily designed for C, but any C-compatible language can access it).

gtkmm for desktop application

Is it a good idea to use gtkmm gui toolkit for some desktop client application ?
Is this toolkit stable and is there enough documentation online ?
I used gtkmm to write professional applications and yes you can use it for real world software development.
But I also used C/GTK+ and C++/Qt and my opinion is that using Gtkmm you have the feeling that the original toolkit was meant to be used in C and the porting to C++ is ok but in many cases you feel that C++ features could have been used better.
For Comparison:
If you have to choose between Gtk and Gtkmm go for Gtkmm even though you might find yourself stuck in some not well documented or supported function. Eventually you always manage to find a solution (you can check the source code) and c++ is way better then c.
If you have to choose between Gtkmm and Qt, go for Qt. There is a HUGE gap between the two. Not only in the toolkit itself but in the documentation and all the other classes that you need when writing an application.
I started two month ago with gtkmm. I actually port a tcl/tk application and it feels very hard for my to get the things run. The only useful documentation I found is the https://developer.gnome.org/gtkmm-tutorial/3.4/
But many things described in the manual are not working! I actually run into trouble while overriding signal handlers which should work but didn't. Maybe you will take a look in gtkmm-list#gnome.org to find out what kind of problems yo will maybe run in :-)
The docs derived from the doxygen input seems useless for me, because the functions are mostly not described and the parameter names or often not very clear to me.
In comparison to tcl/tk the interface looks inconsistent. Sometimes a parameter must be provided by a text, sometimes by a pointer and sometimes by the native value itself. Especially the menus are very "mysterious" with the string based configuration. The need of having parameters as text is very unhandy! You have to convert the parameter with ostrstream into a text and parse the parameters sometimes yourself from text to real values.
I decided to give gtk+ a chance is the existence of the c++ interface. I thought it would be helpful to get the errors in compile time and not while running the app like with tcl/tk. But this is not the always true with gtkmm. With gtkmm you are also able to run into run time errors because all string parameters will be parsed during run time! This makes the things error prone!
Maybe I will start again and give Qt a chance. But a first view on it shows, that this seems not really better :-)
Writing a gui application still is a really annoying job!
gtkmm is a official supported binding of GTK (gtk.org/language-bindings.php).
"inkscape" and "ardour" are notable applications written in gtkmm
The bindings that are official GNOME Bindings follow the GNOME release schedule which guarantees API stability and time-based releases.
If you want to write your Application in C, go with GTK+ (and the GLib).
You can find a link to the documentation at http://www.gtkmm.org/ (https://developer.gnome.org/gtkmm-tutorial/).
With Glade (and ie. PyGTK) you could rapid prototype your application.
Building a GUI with Glade is easy and the resulting UI is a xml file, that is not bound to a programming language.

windows programming using template in c++

I am interested in writing simple windows-based programs for scientific calculations in c++. Is there a place I could find source code for a template that I could use? The window I would create would hardly ever vary -- it would be something similar to this (but simpler!):
http://www.lisisoft.com/imglisi/6/Science/73401version4xp.jpg
I am not a c++ programmer -- but I have created similar programs in visual basic (blush!). This is my way of learning c++ by working within a limited range of program design...mainly at first just changing the formulas and a few labels.
Can anyone help or point me in the right direction?
First off, there are a million things you need to know before you can just download some code from somewhere and try to work with it. My best advice would be to pick up an "Introduction to C++" book.
But, putting that aside, I will try to answer the question.
There are 2 main ways to make GUI apps in windows using C++:
Get a C++ GUI library, there is an extensive list here.
Work with the Windows API directly.
Once you have choosen either step 1 or 2, try to search for samples by searching the library name you have chosen followed by the word "samples" or "examples" (i.e, "WxWidgets Samples", "Qt examples" or "Windows API examples")
However, either way you choose, in order to make something like the example in your picture, I would estimate that it would take you at least 6 months (and thats if you program everyday).
For a windows C++ GUI library try reliable software library at www.relisoft.com. If you want to use native windows GUI programming you can also try using QT libraries.

making a gui editor

For my school project, I would like to build a gui that someone else can use to create a gui. Upon some research I saw lot of gui builders but didn't see anything along the lines of what I am looking for.
But then I did find a tutorial using C# on here
I rather create this gui editor for linux environment.
Any suggestions to where I should start? what tools I can use? Any links to any tutorials?
Any help/direction would be greatly appreciated.
P.S. I would like to add that it only needs to be very simple. like few text input fields and some button type fields that user can arrange in the order desired.
I would recommend that you not try to build your own GUI builder. It is a daunting task that you will not be able to accomplish as a school project. C++ is fully-compiled, which means that it lacks almost every feature that enables people to build meta-tools (like GUI editors) for it. This mainly has to do with the fact that C++ does not have runtime reflection (natively, anyway). Beyond that, there is no "one GUI toolkit and/or paradigm to rule them all." This makes your problem incredibly difficult to deal with.
So: I would recommend Qt, because it works on a ton of platforms, is easy to use and is just plain awesome. You could also look at the billions of other GUI toolkits like Gtk+, Tk, FLTK, YAAF, GLUI, dlib, CLX...
I'm aware that this does not actually answer the question. However, I do not think that the author is aware of how incredibly difficult the task he has set in front of himself is.
I would recommend starting by implementing it like an interpreter. Start with a very simple command line tool that takes commands like window(300, 400, "window1") and button(50,100, "button1") etc and output the code (native or whatever other GUI code you want), to a file. The goal should be to output a file that can be run and show the GUI that was designed. Once you have that, build a GUI that uses the command line functions as a back-end.
I don't have any exact links to this, but here's an example of what you could do. Gtk has the option of loading a GUI by using a class called GtkBuilder. Glade (the usual Gtk gui editor) has support for outputting it's result as an XML file that the GtkBuilder class then reads.
It would be possible for your program to output an equivalently formed XML file that GtkBuilder could read.
I have no clue as to how difficult it would be to target that XML though.
You should use GTK+ or Qt if you are targeting the linux environment. I think the first step is to learn how to program gui, which takes some time considering you are writing c/c++ code wich is different from higher level languages. Don't you think learning to code gui programs and writing a gui builder at the same time is a little bit too much.? First you should master the basics about gui and then go on to harder projects.
Here's a link to an excellent book on gtk. (Foundations of gtk+ development - Andrew Krause)
http://books.google.com/books?id=L1BZZYRrqSgC&printsec=frontcover&dq=foundations+krause&hl=es&cd=1#v=onepage&q=&f=false
And here's a great tutorial/cookbook for gtk+.
http://zetcode.com/tutorials/gtktutorial/
The official documentation is on library.gnome.org
My final advice is learn one thing at a time.

How do I create a certain control using Windows Forms in Visual C++?

I am new to using Windows Forms in C++ (and just in general), and I am not exactly sure of the name or if it's even possible to do.
Currently I am currently working on a school project in which we must make a program for an imaginary bookstore. I am trying right now to make a sort of list that shows what the "customer" is buying. I have to make it sort by price and ISBN and any other variable that the book has.
In essence I am trying to make something like the following:
I just need to know how to get started. I can't figure out what the name of the control is or how to even get it to sort every time the user clicks on the header.
You need to write a managed C++
Please look at
http://www.codeproject.com/KB/miscctrl/mfcandwindowsforms.aspx?fid=3422&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=2509859
Try to do your control same way.
The WindowsForms control you are looking for is called a DataGrid
It's not entirely clear by your question, but if you are trying to access Windows Forms from standard c++ you are out of luck. Windows Forms lives in the Managed world while c++ is unmanaged. To use windows forms you'd have to switch to C++/CLI or C#. Which if you are doing something for a school project may not be an option.
If it is an option to switch languages like that. I'd start looking at C++/CLI documentation to get a feel for how things might work for you.
If you want to know Windows UI inner workings, I recommend you to stay away from .NET for now, and learn some basic things in C++ and WinAPI. Sometimes programming .NET (or C++ / COM) requires you to invoke unmanaged components/functions and you'll be glad you understand how the low-level things work.
If your project requires .NET, go on, but don't forget to make yourself some time to learn good-old Win32 / C++ programming.
Please give some more details about the question Dalze->
is there any requirement about using managed controls? or not using them?
What's your prof want you to learn from this exercise (and is how to use stack overflow to do your homework one of them)?
There's several ways to skin this cat.
If you are supposed to or want to used managed code:
DataGrid mentioned is a good simple database tool link text
An sql database could also hold all the information and allows sorting on the various sub elements.
If you choose not to use managed code you can build a few simple objects to carry the information you need, then add some sort functions for each of the variables of interest.