Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Referencing "internal" resources in MFC

Referencing "internal" resources in MFC

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsharpc++htmlvisual-studio
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Antti Keskinen
    wrote on last edited by
    #1

    Hi ! The topic states it pretty well, but let me specify a little. I am building an application which uses a HTML template (mailbase.html) to send e-mail. Now, I currently have the CFile constructor to find & open this file from the same folder as the executable. However, I would like to reduce the number of files visible to the end user. So, the necessity would be to include the HTML file to the project's resources, and use the CFile to open this "resource file" instead. Question is, what must I write for the first parameter of the constructor (filename) in order to have it search inside the executable instead of the directory where the executable is ? Or, if the CFile isn't an appropriate solution, what should I do ? The idea is that the software opens the HTML file, copies it to CString, finds comment spots there and replaces them with appropriate information. So, a "standard" way to use a HTML template :) I am using version 2003 of MS Visual Studio, but all tips/tricks, including those for older versions, will be helpful. Greets, Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

    M PJ ArendsP 2 Replies Last reply
    0
    • A Antti Keskinen

      Hi ! The topic states it pretty well, but let me specify a little. I am building an application which uses a HTML template (mailbase.html) to send e-mail. Now, I currently have the CFile constructor to find & open this file from the same folder as the executable. However, I would like to reduce the number of files visible to the end user. So, the necessity would be to include the HTML file to the project's resources, and use the CFile to open this "resource file" instead. Question is, what must I write for the first parameter of the constructor (filename) in order to have it search inside the executable instead of the directory where the executable is ? Or, if the CFile isn't an appropriate solution, what should I do ? The idea is that the software opens the HTML file, copies it to CString, finds comment spots there and replaces them with appropriate information. So, a "standard" way to use a HTML template :) I am using version 2003 of MS Visual Studio, but all tips/tricks, including those for older versions, will be helpful. Greets, Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      Read up on the APIs for accessing resources: FindResource, LoadResource, LockResource --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Ericahist updated (again) Sep 6!

      1 Reply Last reply
      0
      • A Antti Keskinen

        Hi ! The topic states it pretty well, but let me specify a little. I am building an application which uses a HTML template (mailbase.html) to send e-mail. Now, I currently have the CFile constructor to find & open this file from the same folder as the executable. However, I would like to reduce the number of files visible to the end user. So, the necessity would be to include the HTML file to the project's resources, and use the CFile to open this "resource file" instead. Question is, what must I write for the first parameter of the constructor (filename) in order to have it search inside the executable instead of the directory where the executable is ? Or, if the CFile isn't an appropriate solution, what should I do ? The idea is that the software opens the HTML file, copies it to CString, finds comment spots there and replaces them with appropriate information. So, a "standard" way to use a HTML template :) I am using version 2003 of MS Visual Studio, but all tips/tricks, including those for older versions, will be helpful. Greets, Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

        PJ ArendsP Offline
        PJ ArendsP Offline
        PJ Arends
        wrote on last edited by
        #3

        Maybe I'm totally missing the point here, but if you want to read the file, and then copy it into a CString, why not just include it as a string resource and use CString::LoadString to load it:confused:


        [

        ](http://www.canucks.com)Sonork 100.11743 Chicken Little "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 Within you lies the power for good - Use it!

        Within you lies the power for good; Use it!

        A 1 Reply Last reply
        0
        • PJ ArendsP PJ Arends

          Maybe I'm totally missing the point here, but if you want to read the file, and then copy it into a CString, why not just include it as a string resource and use CString::LoadString to load it:confused:


          [

          ](http://www.canucks.com)Sonork 100.11743 Chicken Little "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 Within you lies the power for good - Use it!

          A Offline
          A Offline
          Antti Keskinen
          wrote on last edited by
          #4

          Thank you both for a swift response. Mike's suggestion yielded a working solution. Using a string resource might have worked as well, but pushing 3 kb of HTML code into a string resource just didn't sound nice. If nothing else, it would look ugly in the String Table :) I'll post the code snippet here in case someone wants to utilize it. I must say though, it looks like a SERIOUS hack :suss: Note that you need to check the resource integer number for FindResource() manually from 'resource.h' // Load the HTML file char* ptrChar = (char*)LockResource(LoadResource(NULL, FindResource(NULL, "#130" ,RT_HTML))); // Construct a CString from the resource CString HTMLFile(ptrChar); Greetings, Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

          M 1 Reply Last reply
          0
          • A Antti Keskinen

            Thank you both for a swift response. Mike's suggestion yielded a working solution. Using a string resource might have worked as well, but pushing 3 kb of HTML code into a string resource just didn't sound nice. If nothing else, it would look ugly in the String Table :) I'll post the code snippet here in case someone wants to utilize it. I must say though, it looks like a SERIOUS hack :suss: Note that you need to check the resource integer number for FindResource() manually from 'resource.h' // Load the HTML file char* ptrChar = (char*)LockResource(LoadResource(NULL, FindResource(NULL, "#130" ,RT_HTML))); // Construct a CString from the resource CString HTMLFile(ptrChar); Greetings, Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

            M Offline
            M Offline
            Michael Dunn
            wrote on last edited by
            #5

            Antti Keskinen wrote: Note that you need to check the resource integer number for FindResource() manually from 'resource.h' No, just use MAKEINTRESOURCE:

            FindResource ( NULL, MAKEINTRESOURCE(IDR_YOUR_HTML), RT_HTML );

            And some error-handling would be good too. ;) --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Ericahist updated (again) Sep 6!

            A 1 Reply Last reply
            0
            • M Michael Dunn

              Antti Keskinen wrote: Note that you need to check the resource integer number for FindResource() manually from 'resource.h' No, just use MAKEINTRESOURCE:

              FindResource ( NULL, MAKEINTRESOURCE(IDR_YOUR_HTML), RT_HTML );

              And some error-handling would be good too. ;) --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Ericahist updated (again) Sep 6!

              A Offline
              A Offline
              Antti Keskinen
              wrote on last edited by
              #6

              Well, now it's a complete haxor :) Greetings, Antti ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups