How do I create a certain control using Windows Forms in Visual C++? - 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.

Related

Windows MFC macros

I'm trying to learn the MFC to code for Windows and I've come across things like the ID_FILE_EDIT macros that are defined as being unicode values I think. I understand, I think, that the macros specify the item in the menu pulldowns. Question is, how do I define my own and where do I put them. I'm trying to get custom menus and custom menu buttons to stem from the MFC. Like I want under file 'new, open existing doc and stuff like that'. I've got VS2013 pro and all the headers I could ever want. Second question is where do I start with the MFC. Should I start by practicing making windows then pulldowns and then... something else? I know where the documentation is at and I understand where the class references are. Really just confused on using it to make my own stuff.
ID_FILE_EDIT (and other defines, like ID_FILE_NEW, ID_FILE_OPEN, etc.) are macros to specify a name for an unique resource identifier that is used to identify a menu command and/or toolbar item. They are typically defined in a header file named resource.h.
Microsoft has released a numbering and naming convention as a Technical Note (TN), because the names and values ​​represented by these macros must follow a certain pattern: http://msdn.microsoft.com/en-us/library/t2zechd4.aspx
Under normal circumstances you can use Visual-Studio's built-in resource editor to create dialogues, menus, buttons, and all the other UI stuff. These editors also assign automatically unique ID's for any resource and generate the macros.
Your second question can not be answered easily. MFC applications are a wide field, ranging from simple, dialogue-based programs to sophisticated Model-View-Controller-based applications. If you just want to play around with MFC to familiarize yourself with the basic concepts of this framework, I recommend to start with a dialogue-based app.
Regards,
Stephan
In VC++ 6.0, Insert menu - Resource - Menu. Is how you add/edit a menu.
Where is the formatting bar gone on answers.
To learn MFC basics, manually build up the Scribble example application (http://msdn.microsoft.com/en-us/library/92y4h944%28v=vs.90%29.aspx) with which whole generations of MFC programmers made their first contacts with MFC. Don't just read it, start with an empty application and gradually add the stuff as in the tutorials. It'll show you a lot. If you don't know the win32 api yet though, you may want to start with reading the Petzold from front to back. Good luck, remember that these are libaries and API's from a time when it wasn't considered unreasonable to spend 3 months full time to learn something.

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).

Windows ListView control (or similar) that can have multiple columns of checkboxes?

OK, so my Windows application involves a window that, among other things, has a list of objects in a pane. Each object has 8 boolean values that need to be determined — so I'd like a list of the objects, with eight columns of checkboxes after. I'm not using MFC, should that be relevant.
ListView looks the way I want it to, but apparently it doesn't accept checkboxes in SubItems (the LVS_EX_CHECKBOXES style only gives each row a checkbox on the left).
So what I need is some kind of alternative to ListView that does allow this. I've been looking, but nothing I've found seems to work.
I have seen reference to some DataGridView control, but I don't see that as an option in my Visual Studio 2010 "toolbox" — how does one access it, is it even available for non-MFC C++ projects? Most references to it seem to be for VB or C#.
Another thing I found is is this custom ListView, but it, again, seems to be for C# and not C++. I'd certainly accept suggestions on how to use this resource in my code, if there's a simple way to interface with the C# dialogue (I'm completely unfamiliar with C#).
Anyway, any thoughts, suggestions, or tips anyone has, would be most appreciated!
EDIT: This should maybe go in a new question, but it doesn't really seem deserving an entire question on its own: MFC seems to have more support for this kind of thing (insofar as most of the custom controls I can find to download are for MFC). My project does not actually require being non-MFC, it just is, at the moment. How much work am I looking at to convert it?
Well, I've taken the plunge and started using MFC; the CGridCtrl I downloaded seems to be working pretty well, though I still have a lot of work on it. I'm going to call this the answer, then, since there doesn't seem to be another forthcoming.

How do I open a Open File dialog in OS X using C++?

I'm working on an application using OpenGL and C++ that parses some structured input from a file and displays it graphically. I'd like to start an Open File dialog when the application loads to allow the user to choose the file they want to have displayed. I haven't been able to find what I need on the web. Is there a way to achieve this in C++? If so, how? Thank you in advance.
You have two choices, a quick one, and a good one:
Quick and pretty simple, use the Navigation Services framework from Carbon and NavCreateGetFileDialog(). You'll be done quick, and you'll have to learn almost nothing new, but your code won't run in 64-bit (which Apple is pushing everyone towards) and you'll have to link the Carbon framework. Navigation Services is officially removed in 64-bit, and is generally deprecated going forward (though I expect it to linger in 32-bit for quite a while).
A little more work the first time you do it (because you need to learn some Objective-C), but much more powerful and fully supported, wrap up NSOpenPanel in an Objective-C++ class and expose that to your C++. This is my Wrapping C++ pattern, just backwards. If you go this way and have trouble, drop a note and I'll try to speed up posting a blog entry on it.
To add to what Rob wrote:
Unfortunately, there's no simple equivalent to Windows's GetOpenFileName.
If you use Carbon: I don't really think NavCreatGetFileDialog is easy to use... you can use this code in the CarbonDev to see how to use it. The code there returns CFURLRef. To get the POSIX path, use CFURLGetFileSystemReprestnation.
That said, I recommend you to use Cocoa. Rob will write a blog post how to use NSOpenPanel from GLUT :)

Modifying old Windows program for Mac OS X

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.