I was just looking at a Windows programming example in VC++. Then I saw a "resource file". I looked in it and found some "visual" components that the program used. I thought you programmed in the visual part of a Windows program? Am I wrong? I thought that menu (for example) was programmed by hand. How are these visual components made? Thanks.
You can hard code some things or use a resource editor IE Menus....
Resource editors create a .rc script as a text file. The file doesn't actually contain the visual components, its just a compiler script that describes how to load them.
I don't understand. So, you do create the controls (dialogs, menus, etc.) with pure code (text) in a text-editor? You don't create them visually (what I mean is by a click-and-drag method), but you create them with raw code? Thanks.
You can create them with a text editor and save them as a .rc file like;
This details a menu that you can call LoadMenu() on. If you use the resource editor with say VC++6, you can build this component graphically but it will still save it as the script you see above.
IDR_MENU1 MENU DISCARDABLE
MENUITEM "Connect", ID_CONN
MENUITEM "Disconnect", ID_DIS
MENUITEM "Exit", ID_EXIT
You can also create a menu directly in your code with the CreateMenu() function.
What do you prefer? I think I'm going to create the visual parts with the text-editor. The reason that I keep bringing this up and asking all these questions is because I consider myself a very experienced Visual Basic programmer. I started C programming because Visual Basic is a higher-level programming lanuage. So, I did a little research and I found out that C\C++ can create the same applications as Visual Basic but with a faster speed, but a slower programming time. So, I want to get down to the core programming with C. The reason that I don't want to work with the visual editor is because I want to stray away from that. That is how it is like in Visual Basic. That click-and-drag method. No, I want to create components with code. Oh, and that code that you supplied me with to create a menu, is that a specific language? What language is it? Thanks.
>>What do you prefer?
Mostly I use VC++6, and so it is easy to create components with the built in resource editor. I am drifting towards using .rc files less though.....
>>Oh, and that code that you supplied me with to create a menu, is that a specific language? What language is it?
Nah, its no languge - just a script for the compiler.
>>The reason that I don't want to work with the visual editor is because I want to stray away from that. That is how it is like in Visual Basic. That click-and-drag method. No, I want to create components with code.
Dont dismiss the ease of use with resource editors so early on. There's far more important lessons to learn first :p :p
If your coming from VB, you should really look at console programming first as it will teach you how this language properly before you try to focus on windows coding. C/C++ is not like VB - its a very "warts and all" language
It is the same, unregistered guy from before except I registered now. Okay, I have been doing console programming for a little while now and I am quite enjoying it. It is not that I'm going to get into Windows programming for another couple of months, just that curiousity has sparked that question of how to make the visual components. I'm going to continue to keep learning console programming and then when I'm confortable with that, I'll move on to Windows. (I'll probably get Charles Petzold's "Programming Windows". Many recommend it.) I'm actually currently working on File I\O. For example:
how does the program know the directory of the file to read? After all, to run the program, you have to be in the directory of the executable file. So, how does the program find "newfile.txt"? Thanks.
in_file = fopen("newfile.txt", "r")
Well I suppose the easiest way is to state it explicitly.
If its in My documents on Win 98 you might use;
Whatever you do dont forget the extra \ as it is an escape charector.
in_file = fopen("C:\\My Documents\\newfile.txt", "r")
If you want to find the file you could look up the findfirst() and findnext() fuctions.
To look them up online try Gookin's Tutorials
> The reason that I don't want to work with the visual editor is because I want to stray away from that.
There is no virtue in spurning visual resource editors for raw .RC files - or, indeed, for code. There is no loss in efficiency, no lack of flexibility - it's not a code generator. Resources are space-efficient, easily editable and provide a useful separation between UI design and code.
I would very much doubt that any large commercial application produced in the last year was produced without the aid of a visual resource editor. Would you draw a picture in a hex editor or a bitmap editor?
I design comercial UI.
Unless I want a control on a window, I use the resource editor. I can still modify the controls 'on the fly' but have to spend less time in initial coding.
As for fopen I believe it searches the folder the exe is running in first, the working directory.
For folder off the root folder, a subdirectory try
can also be useful
So, you don't think there is anything wrong with designing the controls in the editor. I don't know. I'm just going to learn the scripting "language" (if you may) to learn how to program in the controls and then include them in the program. By the way, where do you learn that scripting "language" for the resource files? Thanks.
Imagine you want to design a dialog that displays / edits a contact list. ie names and adresses. Say 20 to 30 controls.
Do you want to, 'on the fly', adjust all the controls to fit evenly on the dialog? Try printing in WIN32 and you will see what I mean.
I would rather design the dialog in the editor and then display in the program. Even menus I create in the editor and then turn off and on, hide and show items.
Best to leave the script.rc and resource.h alone.
The only time I edit them is if I want the controls to have sequential identifiers for loops. If the editboxes have sequential ID's I can increment a counter to move thru the controls.
When you can use all the controls including Listviews and Treeviews, then start playing with the files produced by the editor.
Petzoid describes how to make controls within the code.