February 19th, 2004, 06:49 PM
Tip of the day Component
Well, it's been a long time since I used VC++ and I started again in December. Now, I have made a little "encryption" program using the Julius Ceasar algorithm in VC++ and I added a Tip of the Day component when the program starts.
The thing is that this component is relying on a file called Tips.txt but what I want to know, is ...
Is there a way to get rid of the tips.txt and somehow make the component look for the tips internally (you know, so I don't have to pack the exe with a txt file)?
P.S. if you want to see the executable and test it a little, just post and I might be able to put it up for download :P
February 19th, 2004, 10:00 PM
Put them in a resource...string table or binary resource perhaps.
Or put the entire contents of the file in an const array.
February 19th, 2004, 10:11 PM
Wouldn't using arrays limit the number of characters per tip?
So this would make the Resources a better option?
February 19th, 2004, 10:23 PM
Resources are more flexible and can be changed without a recompile or stored in seperate DLL's.
I was suggesting that you put the entire contents of the file into a single array. Consider that if the file is small and you have no need to modify the data once the code is built. Upside is that it's a quick and easy way to get the text "inside" the exe.
February 19th, 2004, 10:30 PM
If I choose to go the Resource route, whatever I put there (let's say I called the ID -> IDS_TIP and put whatever text) it's going to be a structure type or something similar while the Tip of the Day function uses a String variable.
Do you have an example to pass the IDS_TIP to the string variable?
Also, can you provide an code example of the array you are suggesting? (I'm only going to use one tip so ...).
Thanks a bunch.
And by the way, if you want to test the program
February 20th, 2004, 12:47 AM
Just create a string table resource. Each string can be it's own tip.
LoadString() to access strings in your string table.
February 20th, 2004, 10:03 AM
Well.. it seems that functions requires an Instance and I'm not using API I'm using MFC.
So I tried changing a created variable (the component created it) that opens the file tips.txt to a CString so I could do:
but it gives me errors (since the rest of the component thinks I'm opening a file!). If I take out everything related to file manipulation, the program compiles but when it is time to execute it just gives me a fatal error (still can't find it!!!).
I'll keep trying though.
Any other suggestions welcomed.
February 20th, 2004, 10:40 AM
Nevermind, I was doing something stupidly wrong!
It works like a charm so thanks for the help Codeplug.
Can you download the program again and tell me if it works (the zip is not suppossed to have the file tips.txt this time around).
Click Here to Expand Forum to Full Width