| TChapman500 (9) | |||
|
I'm trying to make a windows application that get's the window width and height from a config file. So far, everything I've seen that has to deal with files is based on console applications. I'm quite new at C++ and I do not know how to translate the console application tutorials so that they can be used in windows applications. Here's some of the code (derived from book "Beginning Visual C++ 2008").
| |||
|
|
|||
| andywestken (1966) | |
|
The code to read from a file should be the same for a console program as for a GUI; file operations aren't UI related. You just need to read the values from the file into variable and then pass these to CreateWindow(). But if you want to use an ini-file, you could use the calls GetPrivateProfileInt() and GetPrivateProfileString(). But note that these are seen as old fashioned these days: they are to support old, 16-bit apps (from the mid-90s and earlier...). Nowadays it's common practice to store config information in the registry rather than a config/ini-file. See RegOpenKeyEx(), RegQueryValueEx(), RegCloseKey(), etc. Andy | |
|
Last edited on
|
|
| TChapman500 (9) | |||
I think I get it. Would this code work?
| |||
|
|
|||
| andywestken (1966) | ||
|
As it stands, the answer is nope. Have you tried to compile this line??? string wndwidth = config.getline("resolution_x = " &wndwidthval)See: http://www.cplusplus.com/reference/string/getline/ http://www.cplusplus.com/reference/iostream/istream/getline/ If you use GetPrivateProfileInt()/GetPrivateProfileString() it's pretty straightforward. But to read an ini-file with ifstream, you'll have to deal with
Which means you have to: - find the relevant section - find the line with the key-value pair you want and read it - split the value from the key (split at '=') - trim and return the value Andy | ||
|
Last edited on
|
||
| freddie1 (847) | |
|
Is the config file something you already have, or can you create your own? As Andy said, if its pre-existing, then you likely need to parse it. Don't know if this will help, but if you are trying to get the dimensions of the display, the GetSystemMatrics function (I believe that's the right name) will give this. I believe there are others too. Also, the are C Runtime functions that read text files pretty easily. | |
|
|
|
| TChapman500 (9) | |||
|
Thanks for the references. I'll be looking over them for a little while. ---------------------------------------------------------------- I made a "concept" config file so that I will know exactly what is going to be in it. Concept File:
I know it's a lot for a newbie like me, so I'm just creating a simple application and expanding on it after each test to make it what I want. The config file is not pre-existing. The only thing that's in place in the application is the "ifstream config("Config.ini");" part. I am trying to get the dimensions of the display, but I'm also wanting to make those dimensions configurable. Thanks for the advice. | |||
|
|
|||
| TChapman500 (9) | |
|
What is the difference between this http://www.cplusplus.com/reference/string/getline/ and this? http://www.cplusplus.com/reference/iostream/istream/getline/ | |
|
|
|
| modoran (1245) | ||
If you read carefully:
| ||
|
|
||
| TChapman500 (9) | |
| I don't understand what that means? Are they different means to getting the same results? Do they require different methods to retrieve the variables that they store? | |
|
|
|
| TChapman500 (9) | |||
I need some help identifying the problem with this code:
| |||
|
|
|||
| andywestken (1966) | |
| What do you think is supposed to happen on line 7 ??? | |
|
|
|
| TChapman500 (9) | |
It's supposed to retrieve the value in the config file that says:resolution_x=800or resolution_x = 800
| |
|
|
|
| TChapman500 (9) | |
|
I think I found something that I'm looking for. As it turns out, I have to know how to handle strings before I can know how to handle files, which are VERY LONG strings! I believe I found my answer and I'm sorry that I couldn't convey what I was trying to do. Here's the page I found which I believe has answered my questions. http://www.mochima.com/tutorials/strings.html | |
|
|
|