CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2003
    Location
    Guayama, P.R.
    Posts
    41

    Tip of the day Component

    Hi guys.!

    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

  2. #2
    Join Date
    Nov 2003
    Posts
    1,902
    Put them in a resource...string table or binary resource perhaps.
    Or put the entire contents of the file in an const array.

    gg

  3. #3
    Join Date
    Jul 2003
    Location
    Guayama, P.R.
    Posts
    41
    Wouldn't using arrays limit the number of characters per tip?
    So this would make the Resources a better option?

  4. #4
    Join Date
    Nov 2003
    Posts
    1,902
    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.

    gg

  5. #5
    Join Date
    Jul 2003
    Location
    Guayama, P.R.
    Posts
    41
    OK.

    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

    http://gelocks.topcities.com/DataDEEN.ZIP

  6. #6
    Join Date
    Nov 2003
    Posts
    1,902
    Just create a string table resource. Each string can be it's own tip.
    Use
    LoadString() to access strings in your string table.

    gg

  7. #7
    Join Date
    Jul 2003
    Location
    Guayama, P.R.
    Posts
    41
    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:

    CString m_pStream;
    m_pStream.LoadString(IDS_TIP);

    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.

  8. #8
    Join Date
    Jul 2003
    Location
    Guayama, P.R.
    Posts
    41
    Duh...

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

    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured